program cow;
{$o-}
{$APPTYPE CONSOLE}
uses
Math, StrUtils, SysUtils;
type
ex=extended;
int=longint;
bool=boolean;
var
a,b,c: array [1..10] of int;
f: bool;
i,j,n,y,z: int;
s: string;
function check(s,t: string; a,b: int): bool;
var
i,c,d: int;
begin
c:= 0;
d:= 0;
for i:= 1 to 4 do
if pos(s[i],t)=i
then
inc(c)
else
if pos(s[i],t)>0
then
inc(d);
result:= (a=c)and(b=d);
end;
function conv(n: int): string;
begin
result:= inttostr(n);
if n<1000
then
result:= '0'+result;
end;
function ok(n: int): bool;
var
a,b,c,d: int;
begin
a:= n mod 10;
n:= n div 10;
b:= n mod 10;
n:= n div 10;
c:= n mod 10;
d:= n div 10;
result:= not((a=b)or(a=c)or(a=d)or(b=c)or(b=d)or(c=d));
end;
begin
readln(n);
y:= 0;
z:= 0;
for i:= 1 to n do
readln(a[i],b[i],c[i]);
for i:= 123 to 9876 do
begin
if not ok(i)
then
continue;
s:= conv(i);
f:= true;
for j:= 1 to n do
f:= f and check(s,conv(a[j]),b[j],c[j]);
if f
then
begin
inc(z);
y:= i;
end;
end;
if z=1
then
writeln(y)
else
if z=0
then
writeln('Incorrect data')
else
writeln('Need more data');
//readln;
end.
Free Pascal Compiler version 2.2.0 [2009/11/16] for i386
Copyright (c) 1993-2007 by Florian Klaempfl
Target OS: Linux for i386
Compiling prog.pas
prog.pas(3,2) Warning: APPTYPE is not supported by the target OS
prog.pas(30,7) Error: Identifier not found "result"
prog.pas(35,7) Error: Identifier not found "result"
prog.pas(38,9) Error: Identifier not found "result"
prog.pas(38,22) Error: Identifier not found "result"
prog.pas(51,7) Error: Identifier not found "result"
prog.pas(59,2) Warning: Variable "a" does not seem to be initialized
prog.pas(59,2) Warning: Variable "b" does not seem to be initialized
prog.pas(59,2) Warning: Variable "c" does not seem to be initialized
prog.pas(86,4) Fatal: There were 5 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)