var
  Problem,id:string;
  i:byte;
  yours,std:text;
  key,ans:longint;
procedure printhelp;
  begin
    writeln;
    writeln('  This program is used to check whether your program reaches a correct');
    writeln('answer or not for the problems of CEOI''98.');
    writeln;
    writeln('Command Format:');
    writeln('CHECK <Problem Name> <TestID> ');
    writeln('<Problem Name> = Squares | Cards | Subtract | Soldiers | Roads | Ball');
    writeln('<TestID> = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | A (stand for 10) ');
    writeln;
    writeln('Your output file (*.OUT), standard file (*,OU?), input file (*.IN) ');
    writeln('must be in the current directory.');
    writeln('Any error may caused by your program.');
    writeln('                                               ---Programmed by Guo 1/3/1999');
  end;
procedure checkcards;
  var i,n,a,b:integer;
  begin
    read(n);
    close(input);
    for i:=1 to n do begin
      readln(std,a);
      if seekeof(yours) then begin
         writeln('Wrong!');
         exit;
      end;
      readln(yours,b);
      if a<>b then begin
         writeln('Wrong!');
         exit;
      end;
    end;
    writeln('OK!');
  end;
procedure checksub;
  var p,n,t,i,j,max:integer;
      list:array[1..100]of integer;
  begin
    readln(n,t);
    for i:=1 to n do readln(list[i]);
    close(input);
    max:=n;
    for i:=1 to n-1 do begin
      if seekeof(yours) then begin
         writeln('Wrong!');
         exit;
      end;
      readln(yours,p);
      if (p>=max) or (p<1) then begin
         writeln('Wrong!');
         exit;
      end;
      list[p]:=list[p]-list[p+1];
      for j:=p+1 to max-1 do list[j]:=list[j+1];
      dec(max);
    end;
    if list[1]=t then writeln('OK!') else writeln('Wrong!');
  end;
procedure checkball;
  const
    edge:array[1..12,1..5]of byte
        =((2,3,4,5,6),(6,7,11,3,1),(2,11,10,4,1),(3,10,9,5,1),(4,9,8,6,1),(5,8,7,2,1),
          (6,8,12,11,2),(7,6,5,9,12),(8,5,4,10,12),(9,4,3,11,12),(10,3,2,7,12),(7,8,9,10,11));
  var i,j,p,n,t:integer;
      used:array[1..12]of boolean;
      num:array[1..12,1..12]of shortint;
      tile:array[1..12,1..5]of byte;
  begin
    for i:=1 to 12 do
      for j:=1 to 5 do read(tile[i,j]);
    close(input);
    fillchar(used,sizeof(used),0);
    for i:=1 to 12 do
      for j:=1 to 12 do num[i,j]:=-1;
    for i:=1 to 12 do begin
      readln(yours,n,t);
      if (n<1) or (n>12) or (t<1) or (t>12) or used[n] then begin
         writeln('Wrong!');
         exit;
      end;
      used[n]:=true;
      p:=0;
      for j:=1 to 5 do
        if edge[i,j]=t then p:=j;
      if p=0 then begin
         writeln('Wrong!');
         exit;
      end;
      for j:=1 to 5 do begin
        if (num[edge[i,p],i]>=0) and (num[edge[i,p],i]<>tile[n,j]) then begin
           writeln('Wrong!');
           exit;
        end;
        num[i,edge[i,p]]:=tile[n,j];
        inc(p);
        if p>5 then p:=p-5;
      end;
    end;
    writeln('OK!');
  end;
begin
  if paramcount<2 then begin
     printhelp;
     exit;
  end;
  problem:=paramstr(1);
  for i:=1 to length(problem) do problem[i]:=upcase(problem[i]);
  id:=paramstr(2);
  for i:=1 to length(id) do id[i]:=upcase(id[i]);
  if (id='10') or (length(id)=1) and (id[1] in ['A','1'..'9']) then begin
     if id='10' then id:='A';
     if (problem<>'SQUARES') and (problem<>'SOLDIERS') and (problem<>'ROADS')
        and (problem<>'CARDS') and (problem<>'SUBTRACT') and (problem<>'BALL')
     then printhelp
     else begin
            {$I-}
            assign(yours,problem+'.OUT');
            reset(yours);
            if IOResult<>0 then begin
               writeln('Wrong! (Your Output File Not Found)');
               exit;
            end;
            assign(std,problem+'.OU'+id);
            if (problem<>'SUBTRACT') and (problem<>'BALL') then begin
               reset(std);
               if ioresult<>0 then begin
                  writeln('Standard Output Not Found!');
                  exit;
               end;
            end;
            if (problem='SQUARES') or (problem='SOLDIERS') or (problem='ROADS')
            then begin
                   readln(std,key);
                   readln(yours,ans);
                   if key=ans then writeln('OK!')
                              else writeln('Wrong!');
                 end else begin
                            assign(input,problem+'.in');
                            {$I-}
                            reset(input);
                            if ioresult<>0 then begin
                               writeln('Input File Not Found');
                               exit;
                            end;
                          end;
            if problem='CARDS' then checkcards;
            if problem='SUBTRACT' then checksub;
            if problem='BALL' then checkball;
            close(std);
            close(yours);
          end;
  end
  else printhelp;
end.


