import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author cteam084 */ class Self { public static enum Dir { NORTH,WEST,SOUTH,EAST; } public static void main(String [] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int numberOfInstruction = 0; int field[]; do { String line = br.readLine(); numberOfInstruction = Integer.parseInt(line); field = new int[numberOfInstruction]; String [] ins = br.readLine().split(" "); for (int i = 0; i < ins.length; i++) { field[i] = Integer.parseInt(ins[i]); } List list = new ArrayList(); Dir dir = Dir.NORTH; Position p = new Position(0,0); list.add(p); for (int i = 0; i < field.length; i++) { int moves = field[i]; for (int j = 0; j < moves; j++) { Position pos = move(dir, p); list.add(pos); p = pos; } if(contain(list)) { bw.write((i) +"\n"); break; } else { if(i == field.length-1) { bw.write("OK\n"); } } dir = changeDir(dir); } }while(br.ready()); bw.flush(); } public static Dir changeDir(Dir d) { switch(d) { case NORTH: return Dir.EAST; case EAST: return Dir.SOUTH; case SOUTH: return Dir.WEST; case WEST: return Dir.NORTH; } return null; } public static Position move(Dir d,Position p) { switch(d) { case NORTH: return new Position(p.x,p.y+1); case EAST: return new Position(p.x+1, p.y); case SOUTH: return new Position(p.x, p.y-1); case WEST: return new Position(p.x-1, p.y); } return null; } public static boolean contain(List list) { for (int i = 0; i < list.size(); i++) { for (int j = 0; j < list.size(); j++) { if(i == j) continue; else { if(list.get(i).equals(list.get(j))) return true; } } } return false; } } class Position { public int x,y; public Position(int x, int y) { this.x = x; this.y = y; } @Override public boolean equals(Object obj) { Position p = (Position) obj; return this.x == p.x && this.y == p.y; } }