import java.util.Scanner; public class Self { static int delka = 8000; static int pozice = 4000; static char pole[][] = new char[delka][delka]; static int x = pozice; static int y = pozice; static int pocet = -1; public static boolean nahoru (int n) { y--; pocet++; //System.out.println("start: " + x + " = x : y = " + y); for (int i = y; i > y - n; i--) { if (pole[i][x] != '.') { pole[i][x] = '.'; } else { System.out.println(pocet); return true; } } y -= n-1; return false; } public static boolean dolu (int n) { y++; pocet++; //System.out.println("start: " + x + " = x : y = " + y); for (int i = y; i < y + n; i++) { if(pole[i][x] != '.') { pole[i][x] = '.'; }else { System.out.println(pocet); return true; } } y += n; return false; } public static boolean vpravo (int n) { x++; pocet++; //System.out.println("start: " + x + " = x : y = " + y); for (int i = x; i < x + n; i++) { if(pole[y][i] != '.') { pole[y][i] = '.'; } else{ System.out.println(pocet); return true; } } x += n -1; return false; } public static boolean vlevo (int n) { y--; pocet++; //System.out.println("start: " + x + " = x : y = " + y); for (int i = x-1; i >= x - n; i--) { if(pole[y][i] != '.') { pole[y][i] = '.'; } else { System.out.println(pocet); return true; } } x -= n; return false; } /* public static void vypis() { for (int i = 0; i < pole.length; i++) { for (int j = 0; j < pole.length; j++) { System.out.print(pole[i][j]); } System.out.println(); } }*/ public static void main(String[] args) { Scanner sc = new Scanner(System.in); boolean bre = false; while(sc.hasNextLine()) { int p = 0; int po = sc.nextInt(); //System.out.println("nacetl: " + po); for (int i = 0; i < po; i++) { if (p == 0) { if (nahoru(sc.nextInt())) { bre = true; //System.out.println("skacu1"); break; } } else if (p == 1) { if(vpravo(sc.nextInt())) { //System.out.println("skacu2"); bre = true; break; } } else if (p == 2) { if(dolu(sc.nextInt())) { //System.out.println("skacu3"); bre = true; break; } } else if (p == 3) { if(vlevo(sc.nextInt())) { //System.out.println("skacu4"); bre = true; break; } p = -1; } p++; } //System.out.println(); //System.out.println("pocet: " + po); if (bre == false) { System.out.println("OK"); } pole = new char[delka][delka]; x = pozice; y = pozice; pocet = -1; bre = false; //vypis(); sc.nextLine(); } /* nahoru(3); vpravo(1); dolu(1); vlevo(3); nahoru(2); vpravo(2); dolu(6); */ /* nahoru(2); vpravo(1); dolu(4); vlevo(4); nahoru(4); vpravo(3); */ //vypis(); } }