{ Student name: Ena Oster School name: V. gimnazija Zagreb, Croatia Division: Senior Contest: #3 } var n, k, i, b1, b2, j, px, py, i1, u:integer; niz:array [1..10, 1..10] of integer; uc:array [1..50] of integer; begin read (n); for i:=1 to n do begin read (uc[i]); b1 := uc[i] div 5; b2 := uc[i] mod 5; if (not (b2 = 0)) then niz[b1 + 1][b2] := 1 else niz[b1][5] := 1; end; readln (uc[1], uc[2], uc[3], uc[4], uc[5]); for k:=1 to 5 do begin if (uc[k] = 1) then begin px := -1; py := -1; for i:=7 downto 1 do begin for j:=5 downto 1 do begin if (niz[i][j] = 0) then begin u := 0; for i1:=i+1 to 7 do begin if (niz[i1][j] = 1) then u := 1; end; if (u = 0) then begin px := i; py := j; end; end; end; end; if ((px = -1) and (py = -1)) then begin writeln ('NONE'); end else begin b1 := ((px - 1) * 5) + py; niz[px][py] := 1; writeln (b1); end; end; if (uc[k] = 2) then begin px := -1; py := -1; for i:=6 downto 1 do begin for j:=5 downto 1 do begin if ((niz[i][j] = 0) and (niz[i+1][j] = 0)) then begin u := 0; for i1:=i+1 to 7 do begin if (niz[i1][j] = 1) then u := 1; end; if (u = 0) then begin px := i; py := j; end; end; end; end; if ((px = -1) and (py = -1)) then begin writeln ('NONE'); end else begin b1 := ((px - 1) * 5) + py; niz[px][py] := 1; niz[px+1][py] := 1; writeln (b1); end; end; if (uc[k] = 3) then begin px := -1; py := -1; for i:=7 downto 1 do begin for j:=4 downto 1 do begin if ((niz[i][j] = 0) and (niz[i][j+1] = 0)) then begin u := 0; for i1:=i+1 to 7 do begin if (niz[i1][j] = 1) then u := 1; if (niz[i1][j+1] = 1) then u :=1; end; if (u = 0) then begin px := i; py := j; end; end; end; end; if ((px = -1) and (py = -1)) then begin writeln ('NONE'); end else begin b1 := ((px - 1) * 5) + py; niz[px][py] := 1; niz[px][py+1] := 1; writeln (b1); end; end; if (uc[k] = 4) then begin px := -1; py := -1; for i:=6 downto 1 do begin for j:=4 downto 1 do begin if ((niz[i][j] = 0) and (niz[i+1][j+1] = 0) and (niz[i+1][j] = 0)) then begin u := 0; for i1:=i+1 to 7 do begin if (niz[i1][j] = 1) then u := 1; if (niz[i1][j+1] = 1) then u := 1; end; if (u = 0) then begin px := i; py := j; end; end; end; end; if ((px = -1) and (py = -1)) then begin writeln ('NONE'); end else begin b1 := ((px - 1) * 5) + py; niz[px][py] := 1; niz[px+1][py+1] := 1; niz[px+1][py] := 1; writeln (b1); end; end; if (uc[k] = 5) then begin px := -1; py := -1; for i:=6 downto 1 do begin for j:=4 downto 1 do begin if ((niz[i][j] = 0) and (niz[i][j+1] = 0) and (niz[i+1][j] = 0)) then begin u := 0; for i1:=i+1 to 7 do begin if (niz[i1][j] = 1) then u := 1; if (niz[i1][j+1] = 1) then u := 1; end; if (u = 0) then begin px := i; py := j; end; end; end; end; if ((px = -1) and (py = -1)) then begin writeln ('NONE'); end else begin b1 := ((px - 1) * 5) + py; niz[px][py] := 1; niz[px][py+1] := 1; niz[px+1][py] := 1; writeln (b1); end; end; end; readln (n); end.