#include #include typedef struct _vektor { int x; int y; int len; int index; } vektor; int inter(vektor a, vektor b) { if (a.index == 2) { if (b.index == 3) { return a.y - a.len <= b.y && b.y <= a.y && b.x - b.len <= a.x && a.x <= b.x; } else { return a.y - a.len <= b.y && b.y <= a.y && b.x <= a.x && a.x <= b.x + b.len; } } else { if (b.index == 3) { return a.y <= b.y && b.y <= a.y + a.len && b.x-b.len <= a.x && a.x <= b.x; } else { return a.y <= b.y && b.y <= a.y + a.len && b.x <= a.x && a.x <= b.x + b.len; } } } int main() { int i, a; while(scanf("%d", &a) != 0) { int inte = 0; int x = 0, y = 0; vektor pole[a]; for(i = 0; i < a; i++) { int len; scanf("%d", &len); if (inte) continue; pole[i].x = x; pole[i].y = y; pole[i].len = len; pole[i].index = i; if (i % 2 == 0) { int j; for (j = 1; j < i-1 ;j+=2) { if (inter(pole[i], pole[j])) { inte = i; printf("konec %d\n", i); break; } } } else { int j; for (j = 0; j < i-1 ;j+=2) { if (inter(pole[j], pole[i])) { inte = i; break; } } } switch (i % 4) { case 0: y += len; break; case 1: x += len; break; case 2: y -= len; break; case 3: x -= len; break; } } if (inte) printf("%d\n", inte); else printf("OK\n"); } return 0; }