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>
using namespace std;

int main(){
    int l, ans;
    bool a = true;
    cin >> l;
    vector<int> c(l);
    vector<int> ana(0);
    for (int i = 0; i < l; ++i){
        cin >> c[i];
    }
    for (int i = 0; i < l; ++i){
        int last;
        if (c[i] > 0){
            for (int j = 0; j < ana.size(); ++j){
                if (ana[j] == c[i]){
                    ans = i + 1;
                    a = false;
                    break;
                }
            }
            ana.push_back(c[i]);
            last = ana.back();
        }
        else {
            if (last + c[i] != 0){
                a = false;
                ans = i + 1;
                break;
            } else {
                ana.pop_back();
                last = ana.back();
            }
        }
        if(!a) break;
    }
    if(!a) cout << ans << endl;
    else cout << "OK" << endl;
    return 0;
}

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

#define N 1000
int main() {

  int n;
  cin>>n;
  int cats[N];

  int cat, tail = 0;
  for(int i = 0; i < n; i++) {
    cin>>cat;
    if (cat > 0) {
      for (int j = 0; j < tail; j++) {
        if (cats[j] == cat) {
	  cout<<i+1<<endl;
          return 0;
        }
      }
      cats[tail] = cat;
      tail++;
    } else {
      if (cats[tail-1] != -cat) {
	cout<<i+1<<endl;
	return 0;
      }
      tail--;
    }
  }

  cout<<"OK"<<endl;
  
  return 0;
}

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

typedef long long ll;
#define ALL(a) a, a+sizeof(a)/sizeof(a[0])
#define all(a) a.begin(),a.end()
#define MOD 1000000007
using namespace std;
ll gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n % m);
}
ll lcm(ll n, ll m) {return m / gcd(n, m) * n;}

int main(void) {
	ll l,tmp;
	cin >> l;
	deque<int> c;
	for (int i = 0; i < l; i++) {
		cin >> tmp;
		for (int j = 0; j < c.size(); j++) {
			if (c[j] == tmp) {
				cout << i + 1 << "\n";
				return 0;
			}
		}
		if (tmp > 0) {
			c.push_back(tmp);
		}else{
			if (i == 0) {
				cout << "1" << "\n";
				return 0;
			}
			else if (c.back() == -1 * tmp) c.pop_back();
			else {
				cout << i + 1 << "\n";
				return 0;
			}
		}
	}
	cout << "OK" << "\n";
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int memo[101];

int main() {
  int n, c;
  bool f = true;
  cin >> n;
  stack<int> stk;
  for (int i = 0; i < n; i++) {
    cin >> c;
    if (c > 0) {
      if (memo[c]) {
        cout << i + 1 << "\n";
        f = false;
        break;
      } else {
        stk.push(c);
        memo[c] = 1;
      }
    } else {
      if (stk.empty() || stk.top() != -c) {
        cout << i + 1 << "\n";
        f = false;
        break;
      } else {
        stk.pop();
        memo[-c] = 0;
      }
    }
  }
  if (f) cout << "OK\n";
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int c[n],in[101]={};
    stack<int>cat;
    for(int i=0;i<n;i++)cin>>c[i];
    for(int i=0;i<n;i++){
        if(c[i]>0){
            if(in[c[i]]){
                cout<<i+1<<endl;
                return 0;
            }
            in[c[i]]=1;
            cat.push(c[i]);
        }
        if(c[i]<0){
            c[i]*=-1;
            if(cat.size()==0 || cat.top()!=c[i]){
                cout<<i+1<<endl;
                return 0;
            }
            in[c[i]]=0;
            cat.pop();
        }
    }
    cout<<"OK"<<endl;
    return 0;
}

C++: #include<bits/stdc++.h>
#include <array>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;

struct Problem {

	void Solve() {
		UL n; cin >> n;
		bool ins[100] = {};
		stack<UL> spot; spot.push(101);
		int mem[1000]; rep(i, n) cin >> mem[i];
		rep(i, n) {
			if (mem[i] > 0) {
				UL c = mem[i] - 1;
				if (ins[c]) { cout << i + 1 << endl; return; }
				ins[c] = true;
				spot.push(c);
			}
			else {
				UL c = (-mem[i]) - 1;
				if (!ins[c]) { cout << i + 1 << endl; return; }
				if (spot.top() != c) { cout << i + 1 << endl; return; }
				ins[c] = false;
				spot.pop();
			}
		}
		cout << "OK" << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    int n; cin >> n;
    int a[n]; rep(i,0,n) cin >> a[i];

    bool f = false;
    bool neko[101] = {};
    stack<int> st;
    rep(i,0,n){
        if(a[i] > 0 && neko[a[i]] == 0){
            st.push(a[i]);
            neko[a[i]] = 1;
        }else{
            int b = 0;
            if(!st.empty()) b = st.top();

            if(b == -1*a[i]){
                st.pop();
                neko[b] = 0;
            }else{
                cout << i+1 << "\n";
                f = true;
                break;
            }
        }
    }
    if(!f) cout << "OK\n";
}

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

int main(){
	int n;	cin>>n;
	vector<bool> cat(100,false);
	stack<int> hole;

	int ans=0;

	for(int i=1;i<=n;i++){
		int x;	cin>>x;
		if(x>0){
			if(cat[x]==false){
				cat[x]=true;
				hole.push(x);
			}
			else{
				ans=i;
				break;
			}
		}else if(x<0){
			x*=(-1);
			if(cat[x]==true && hole.top()==x){
				hole.pop();
				cat[x]=false;
			}
			else{
				ans=i;
				break;
			}
		}
	}
	if(ans!=0)cout<<ans<<endl;
	else cout<<"OK"<<endl;

	return 0;
}