program Order; {Internet_Olimp informat VIPPO 2011-2012 tur2 zavd1} {Kod ychasnuka B3292} {mova program Pascal} {seredovushe Delphi7} {$APPTYPE CONSOLE} uses SysUtils; const nMax = 1048576; mMax = 100; mMaxStr=25; type TMas = array [1..nMax] of integer; TBin = array [1..mMax] of integer; TBinStr = array [1..mMaxStr] of string; var f:text; m,n:integer; i,j,k,p,s,D,pOst:integer; a:TMas; b:TBin; bStr:TBinStr; procedure inStr(i,k:integer; var mas:TBinStr); begin case i of 0: mas[k]:='0'; 1: mas[k]:='1'; 2: mas[k]:='2'; 3: mas[k]:='3'; 4: mas[k]:='4'; 5: mas[k]:='5'; 6: mas[k]:='6'; 7: mas[k]:='7'; 8: mas[k]:='8'; 9: mas[k]:='9'; 10: mas[k]:='A'; 11: mas[k]:='B'; 12: mas[k]:='C'; 13: mas[k]:='D'; 14: mas[k]:='E'; 15: mas[k]:='F'; end; end; begin assign(f,'order.dat'); reset(f); readln(f,m); for i := 1 to m do begin read(f,n); s:=0; for j := 1 to n do begin read(f,a[j]); k:=0; for p := 1 to j do if a[p]>a[j] then k:=k+1; s:=s+k; end; b[i]:= s mod 2; readln(f); end; close(f); p:=m div 4; pOst:=m mod 4; i:=m; k:=1; while i>1+pOst do begin D:=1; s:=0; for j := 0 to 3 do begin s:=s+b[i-j]*D; D:=D*2; end; inStr(s,k,bStr); k:=k+1; i:=i-4; end; if pOst>0 then begin D:=1; s:=0; for j := pOst to 1 do begin s:=s+b[i+j]*D; D:=D*2; end; inStr(s,k,bStr); end; assign(f,'orderd.sol'); rewrite(f); s:=0; for i := k downto 1 do if bStr[i]<>'0' then begin s:=i; break; end; if (s=0)then write(f,'0') else for i := s downto 1 do write(f,bStr[i]); close(f); end.