#include #include #include #include #include #include #include #include #include using namespace std; typedef long long int lint; typedef long long ll; long long dx[] = {1,0,-1,0}; long long dy[] = {0,1,0,-1}; struct usecka{ pair a; pair b; }; bool p(usecka& a, usecka& b){ ll x1 = min(a.a.first, a.b.first); ll x2 = max(a.a.first, a.b.first); ll y1 = min(a.a.second, a.b.second); ll y2 = max(a.a.second, a.b.second); ll X1 = min(b.a.first, b.b.first); ll X2 = max(b.a.first, b.b.first); ll Y1 = min(b.a.second, b.b.second); ll Y2 = max(b.a.second, b.b.second); //printf("%lld %lld %lld %lld %lld %lld %lld %lld\n", x1,x2,y1,y2,X1,X2,Y1,Y2); if(x1 <= X1 && x2 >= X2 && y1 >= Y1 && y2 <= Y2){ return true; } if(x1 == x2 && X1 == X2 && x1 == X1){ if(y1<=Y1 && Y1 <= y2) return true; } if(y1 == y2 && Y1 == Y2 && y1 == Y1){ if(x1<=X1 && X1 <= x2) return true; } return false; } bool pretina(usecka& a, usecka& b){ if(p(a,b) || p(b,a)) return true; return false; } bool skontroluj(deque > posledne){ if(posledne.size() <= 3) return true; usecka akt, akt2; akt.a = posledne.back(); posledne.pop_back(); akt.b = posledne.back(); posledne.pop_back(); akt2.b = posledne.back(); posledne.pop_back(); while(posledne.size()){ akt2.a = akt2.b; akt2.b = posledne.back(); if(pretina(akt, akt2)) return false; posledne.pop_back(); } return true; } int main() { lint n; while(scanf("%lld",&n) == 1){ bool da = true; deque > posledne; long long cx = 0, cy = 0; posledne.push_back(make_pair(cx, cy)); for(int i = 0; i < n; i++){ long long dlzka; scanf("%lld", &dlzka); if(da){ cx += dlzka * dx[i%4]; cy += dlzka * dy[i%4]; posledne.push_back(make_pair(cx,cy)); if(posledne.size() > 7) posledne.pop_front(); if(!skontroluj(posledne)){ printf("%lld\n", i); da = false; } } } if(da) printf("OK\n"); } }