Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func parseToArray2d(lines []string) [][]int64 {
	var result [][]int64
	for _, line := range lines {
		var parsedLine []int64
		for _, element := range strings.Split(line, " ") {
			n, err := strconv.ParseInt(element, 10, 64)
			if err != nil {
				fmt.Printf("Error: element = %v\n", element)
			}
			parsedLine = append(parsedLine, n)
		}
		result = append(result, parsedLine)
	}
	return result
}

func pop(stack []int64) ([]int64, int64) {
	lenStack := len(stack)
	return stack[0:(lenStack - 1)], stack[lenStack-1]
}

func contains(s []int64, e int64) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	content := []string{}
	for scanner.Scan() {
		line := scanner.Text()
		content = append(content, line)
	}
	arr := parseToArray2d(content)
	input := arr[1]

	stack := []int64{}
	result := -1

	for i, x := range input {
		if x > 0 {
			if contains(stack, x) {
				result = i + 1
				break
			} else {
				stack = append(stack, x)
			}
		} else {
			var top int64
			if len(stack) == 0 {
				result = i + 1
				break
			}
			stack, top = pop(stack)
			if top != -x {
				result = i + 1
			}
		}
	}

	if result < 0 {
		fmt.Println("OK")
	} else {
		fmt.Println(result)
	}
}

C++: #include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 l;
  cin >> l;
  vector<i64> c(l);
  for (i64 i = 0; i < l; i++)
    cin >> c[i];
  vector<i64> h;
  vector<bool> in(l);
  for (i64 i = 0; i < l; i++)
  {
    if (0 < c[i])
    {
      h.push_back(c[i]);
      if (in[c[i] - 1])
      {
        cout << i + 1 << endl;
        return 0;
      }
      in[c[i] - 1] = true;
    }
    else
    {
      if (0 < h.size() && h[h.size() - 1] == -c[i])
      {
        h.pop_back();
        in[-c[i] - 1] = false;
      }
      else
      {
        cout << i + 1 << endl;
        return 0;
      }
    }
  }
  cout << "OK" << endl;
  return 0;
}

C++: #include <iostream>
#include <stack>
#include <unordered_set>

using namespace std;

int main() {
    int L;
    cin >> L;

    unordered_set<int> cats;
    stack<int> cave;
    cave.push(0);

    int c, ans = 0;
    for (int i = 1; i <= L; i++) {
        cin >> c;
        if (c < 0) {
            if (cave.top() == -c) {
                cave.pop();
                cats.erase(-c);
            } else {
                ans = i;
                break;
            }
        } else {
            if (cave.top() != c && cats.find(c) == cats.end()) {
                cave.push(c);
                cats.insert(c);
            } else {
                ans = i;
                break;
            }
        }
    }

    cout << (ans ? to_string(ans) : "OK") << endl;
}

C++: #include "bits/stdc++.h"

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int l;
    cin >> l;
    stack<int> st;
    vector<int> exist(107);
    for (int i = 0; i < l; i++) {
        int c;
        cin >> c;
        if (st.size() >= 1) {
            if (c < 0) {
                if (st.top() != abs(c)) {
                    cout << i + 1 << '\n';
                    return 0;
                }
                st.pop();
                exist[abs(c)]--;
            } else {
                if (exist[c] >= 1) {
                    cout << i + 1 << '\n';
                    return 0;
                }
                st.push(c);
                exist[c]++;
            }
        } else {
            if (c < 0) {
                cout << i + 1 << '\n';
                return 0;
            }
            st.push(c);
            exist[c]++;
        }
    }
    cout << "OK" << '\n';
    return 0;
}

C++: #include <iostream>
#include <stack>

using namespace std;

int main()
{
  stack<int> cats_stack;
  bool cave_in_cat[100] = { false };
  int n;
  int cat_number;
  
  cin >> n;

  cin >> cat_number;
  if (cat_number < 0) {
    cout << "1" << endl;
    return 0;
  } else {
    cats_stack.push(cat_number);
    cave_in_cat[cat_number] = true;
  }

  for (int i = 2; i <= n; i++) {
    cin >> cat_number;
    if (cat_number > 0) {
      if (cave_in_cat[cat_number] == false) {
        cats_stack.push(cat_number);
        cave_in_cat[cat_number] = true;
      } else {
        cout << i << endl;
        return 0;
      }   
    } else if (cat_number < 0) {
      if (!cats_stack.empty()) {
        if (cats_stack.top() == -cat_number) {
          cats_stack.pop();
          cave_in_cat[-cat_number] = false;
        } else {
          cout << i << endl;
          return 0;
        }
      } else {
        cout << i << endl;
        return 0;
      }
    }
  }

  cout << "OK" << endl;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
  int l; cin >> l;
  vector<int> c(l);
  for(auto& a:c) cin >> a;
  vector<int> io(l);
  int now=0,ans=0;
  for(int i=0;i<l;++i) {
    if(c[i]>0) {
      if(find(io.begin(),io.end(),c[i])!=io.end()) {
	ans=i+1;
	break;
      }
      io[now++]=c[i];
    } else {
      if(now==0) {
	ans=i+1;
	break;
      }
      if(io[now-1]!=-c[i]) {
	ans=i+1;
	break;
      }
      io[--now]=0;
    }
  }
  if(ans) cout << ans << endl;
  else cout << "OK" << endl;
  
  return 0;
}

C++: #include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
#include <stack>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	stack<ll> s ;
	vb cat(100,false) ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		if(a<0){
			a *= -1 ;
			if(s.empty()||s.top()!=a){
				cout << i+1 << endl ;
				return 0 ;
			}else{
				s.pop() ;
				cat.at(a-1) = false ;
			}
		}else{
			if(cat.at(a-1)){
				cout << i+1 << endl ;
				return 0 ;
			}else{
				s.push(a) ;
				cat.at(a-1) = true ;
			}
		}
	}
	cout << "OK" << endl ;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;

bool memo[101]={};
stack<int> s;
int main(){
	int l;
	cin>>l;
	int c;
	s.push(0);
	for(int i=0;i<l;i++){
		cin>>c;
		if(c>0){
			if(memo[c]){
				cout<<++i<<endl;
				return 0;
			}else{
				s.push(c);
				memo[c]=true;
			}
		}else{
			c=c*-1;
			if(s.top()==c){
				s.pop();
				memo[c]=false;
			}else{
				cout<<++i<<endl;
				return 0;
			}
		}
	}
	cout<<"OK"<<endl;
	
}

C++: #include <bits/stdc++.h>

#define ALL(a) (a).begin(), (a).end()

using namespace std;

int solve() {
	int n; cin >> n;
	vector<int> inp(n);
	for(auto& e: inp) cin >> e;
	stack<int> st;
	vector<bool> inner(1000,false);
	for(size_t i = 0; i < n; i++) {
		auto e = inp[i];
		if( e > 0 ) {
			if( inner[e] ) {
				return  i+1;
			}
			else {
				inner[e] = true;
				st.push(e);
			}
		}
		else {
			e *= -1;
			if(st.size() == 0) {
				return i+1;
			}
			if(st.top() != e ) {
				return i+1;
			} else {
				st.pop();
				inner[e] = false;
			}
		}
	}
	return -1;
}

signed main(){
	auto ans = solve();
	if(ans == -1){
		cout << "OK" << endl;
	} else {
		cout << ans << endl;
	}

	return 0;
}