[an error occurred while processing this directive]
Listing: FLIP.PAS 
 const ni='input.txt'; 
      no='output.txt'; 
      q:array['0'..'1'] of Byte=(0,1); 
 var a:array[1..1000,1..9] of Byte; 
     fc:array[1..9] of Byte; 
     i,j,k,l,m,s,min:Word; 
 
  procedure citeste; 
 var c,d:Char; 
 begin 
   Assign(input,ni); Reset(input); 
   Readln(m); 
   for i:=1 to m 
do 
   begin 
     for j:=1 to 9 do  
     begin 
       Read(c,d); 
       a[i,j]:=q[c]; 
     end; 
     Read(d) 
   end 
 end; 
  
 procedure rezolva; 
 begin 
   min:=9*m+1; 
   for k:=0 to 511 do  
   begin 
     for j:=1 to 9 do  
       fc[j]:=k shr (j-1) and 1; 
     s:=0; 
     for i:=1 to m do  
     begin 
       l:=0; 
       for j:=1 to 9 do  
         l:=l+(a[i,j] xor fc[j]); 
       if l<5 then s:=s+l  
              else s:=s+9-l 
     end; 
     if s<min then  
     begin Writeln(k); min:=s end 
   end 
 end; 
  
 procedure scrie; 
 begin 
   Assign(output,no); Rewrite(output); 
   Writeln(min); 
   Close(output) 
 end; 
 
 
 Begin
   citeste; 
   rezolva; 
   scrie 
 End.

[cuprins]