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 <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int L;
    cin >> L;
    vector<bool> C(101);
    stack<int> que;
    rep(i, L) {
        int c;
        cin >> c;
        if(c > 0) {
            if(C[c] == 1) {
                cout << i + 1 << endl;
                return 0;
            } else {
                C[c] = 1;
                que.push(c);
            }
        } else {
            c = -c;
            if(C[c] == 0 || que.top() != c) {
                cout << i + 1 << endl;
                return 0;
            } else {
                que.pop();
                C[c] = 0;
            }
        }
    }
    cout << "OK" << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int ans = -1;
  stack<int> st;
  vector<bool> used(100, false);
  for (int i = 0; i < N; i++){
    int c;
    cin >> c;
    if (c > 0){
      if (used[c]){
        ans = i + 1;
        break;
      } else {
        st.push(c);
        used[c] = true;
      }
    } else {
      if (st.empty()){
        ans = i + 1;
        break;
      } else if (st.top() + c != 0){
        ans = i + 1;
        break;
      } else {
        st.pop();
        used[-c] = false;
      }
    }
  }
  if (ans == -1){
    cout << "OK" << endl;
  } else {
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>
#include <cstdio>
#include <stack>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
//priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
int x[101];

void solve(){
  cin >> n;
  int c;
  stack<int>q;
  for(int i=0;i<n;i++){
    cin >> c;
    if(c<0){
      if(q.size()==0 || q.top()!=abs(c)){
        cout << i+1 << endl;
        return;
      }
      else{
        x[q.top()]=0;
        q.pop();
      }
    }
    if(c>0){
      if(x[c]==1){
        cout << i+1 << endl;
        return;
      }
      else{
        q.push(c);
        x[c]=1;
      }
    }
  }
  cout << "OK" << endl;
}

int main() {
  solve();
  return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    int n;
    cin >> n;
    deque<int> que;
    set<int> st;
    for(int i = 0; i < n; i++) {
        int a; cin >> a;
        if(a < 0) {
            if(!que.size() || que.back() != -a) {
                cout << i + 1 << endl;
                return 0;
            } else {
                st.erase(que.back());
                que.pop_back();
            }
        } else {
            if(st.count(a)) {
                cout << i + 1 << endl;
                return 0;
            }
            que.push_back(a);
            st.insert(a);
        }
    }
    cout << "OK" << endl;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
	int l;
    int ans = 0;
    bool flag = false;
    cin >> l;
    vector<int> c(l);
    map<int, int> m;
    stack<int> s;
    rep(i,0,l){
        cin >> c[i];
        if(l == 1){
            if(c[i] > 0){
                cout << "OK" << endl;
                return 0;
            }else{
                cout << 1 << endl;
                return 0;
            }
        }
        if(flag) continue;
        if(c[i] > 0){
            if(m[c[i]] == 1){
                flag = true;
                ans = i+1;
            }else{
                m[c[i]] = 1;
                s.push(c[i]);
            }
        }else{
            int num = s.top();
            if(m[abs(c[i])] == 0){
                flag = true;
                ans = i+1;
            }else{
                if(num == abs(c[i])){
                    s.pop();
                    m[abs(c[i])] = 0;
                }else{
                    flag = true;
                    ans = i+1;
                }
            }
        }
    }
    if(ans == 0){
        cout << "OK" << endl;
        return 0;
    }else{
        cout << ans << endl;
        return 0;
    }
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define rrep(i,n) for(int i = n-1;i >=0;i--)
#define ALL(a) a.begin(),a.end()
#define PI  acos(-1)
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, sum = 0,h,w;
int main() {
    int n, a, cnt; cin >> n; vector<int> v, p(n);
    rep(i, n) cin >> p[i];
    rep(i, n) {
        a = p[i];
        if (v.empty() && a > 0) {
            v.push_back(a);
        }
        else if (v.empty() && a < 0) {
            cout << i + 1 << endl;
            return 0;
        }
        else if (a < 0) {
            auto it = v.end(); it--;
            if (*it != abs(a)) {
                cout << i + 1 << endl;
                return 0; 
            }
            else v.erase(it);
        }
        else {
            if (find(ALL(v), a) != v.end()) {
                cout << i + 1 << endl;
                return 0;
            }
            else v.push_back(a);
        }
    }cout << "OK" << endl;
}