#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++) #define FORD(prom, a, b) for(int prom = (a); prom > (b); prom--) #define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--) #define DRI(a) int a; scanf("%d ", &a); #define DRII(a, b) int a, b; scanf("%d %d ", &a, &b); #define RI(a) scanf("%d ", &a); #define RII(a, b) scanf("%d %d ", &a, &b); #define PB push_back #define MP make_pair #define ll long long #define ull unsigned long long #define MM(co, cim) memset((co), (cim), sizeof((co))) #define DEB(x) cerr << ">>> " << #x << " : " << x << endl; /* int a[1000014], n = 1000007; struct line { int y1, y2, x1, x2; bool begin; bool operator<(const line& a) const { if(hor() && a.hor()) { if(begin && a.begin) { return x1 < a.x1; } else if(begin) { return x1 < a.x2; } else if(a.begin) { return x2 < a.x1; } else { return x2 < a.x2; } } else if(hor() && !a.hor()) { if(begin) { return x1 < a.x1; } else { return x2 <= a.x1; } } else if(!hor() && a.hor()) { if(a.begin) { return x1 <= a.x1; } else { return x1 < a.x2; } } else { if(x1 != a.x1) return x1 < a.x1; } } bool hor() const { if(y1 == y2) return true; return false; } }; struct cord { int real; int idx; bool operator<(const cord& a) const { return real < a.real; } }; int read(int idx) { int sum = 0; while(idx >= 0) { sum += a[idx]; idx = (idx & (idx+1)) - 1; } return sum; } void update(int idx, int val) { while(idx < n) { a[idx] += val; idx |= (idx+1); } } int X[1000007]; int Y[1000007]; set lns; set mpx; set mpy; */ // OMG ty kokot int A[1000007]; int main () { int N; while(cin >> N) { FOR(i,0,N) RI(A[i]); bool poss; int W, W2, H, H2, d; // ven int mx = 0; W = H = 0; W2 = H2 = 0; d = 0; poss = true; FOR(i,0,N) { switch(d) { case 0: if(A[i] <= H) { poss = false; mx = max(mx,i); H = A[i]; W = W - W2; break; } H2 = H; H = A[i]; break; case 1: if(A[i] <= W) { poss = false; mx = max(mx,i); break; } W2 = W; W = A[i]; break; } d++; d %= 2; if(!poss) break; } if(poss) { cout << "OK" << endl; continue; } poss = true; FOR(i,mx+1,N) { switch(d) { case 0: if(A[i] >= H) { poss = false; mx = i; break; } H = A[i]; break; case 1: if(A[i] >= W) { poss = false; mx = i; break; } W = A[i]; break; } d++; d %= 2; if(!poss) break; } if(poss) { cout << "OK" << endl; continue; } cout << mx << endl; } return 0; } /* bool poss = true; int mx = 0; int W = 1000000007, H = 1000000007; int d = 0; FOR(i,0,N) { } //cout << mx << endl; if(poss) { cout << "OK" << endl; continue; } cout << mx << endl; } /* n = N+5; int d = 0, x = 0, y = 0; X[0] = x; Y[0] = y; FOR(i,0,N) { DRI(l); A[i] = l; switch(d) { case 0: y += l; break; case 1: x += l; break; case 2: y -= l; break; case 3: x -= l; break; } d++; d %= 4; X[i+1] = x; Y[i+1] = y; } lns.clear(); mpx.clear(); mpy.clear(); sort(X,X+N+1); sort(Y,Y+N+1); cord c; FOR(i,0,N+1) { c.real = X[i]; c.idx = i; mpx.insert(c); } FOR(i,0,N+1) { c.real = Y[i]; c.idx = i; mpy.insert(c); } x = y = d = 0; line ln; FOR(i,0,N) { int l = A[i]; switch(d) { case 0: ln.x1 = x; ln.x2 = x; ln.y1 = y+l; ln.y2 = y; break; case 1: ln.x1 = x; ln.x2 = x+l; ln.y1 = y; ln.y2 = y; ln.begin = true; lns.insert(ln); ln.begin = false; break; case 2: ln.x1 = x; ln.x2 = x; ln.y1 = y; ln.y2 = y-l; break; case 3: ln.x1 = x-l; ln.x2 = x; ln.y1 = y; ln.y2 = y; ln.begin = true; lns.insert(ln); ln.begin = false; break; } lns.insert(ln); switch(d) { case 0: y += l; break; case 1: x += l; break; case 2: y -= l; break; case 3: x -= l; break; } d++; } for(set::iterator it = lns.begin(); it != lns.end(); ++it) { cout << "line" << endl; line ln = *it; if(ln.hor()) { // check diff od abs? if(ln.begin) { update(ln.y1,-1); // higher update(ln.y2,1); } else { update(ln.y1,1); update(ln.y2,-1); } } else { // vertical // test if(read(ln.y1) > read(ln.y2)) { // TODO intersect cout << "intersect" << endl; } } } */ //}