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<iostream>
#include<vector>
using namespace std;
int main() {
int L;
cin >> L;
int i,c;
int f = -1;
vector<int> s;
vector<bool> v(110,false);
for(i=0;i<L&&f<0;i++) {
cin >> c;
if(c>0) {
if(!v[c]) {
s.push_back(c);
v[c] = true;
}
else f = i+1;
}
else if(s.size()==0?false:s[s.size()-1]==-c) {
s.erase(s.end()-1);
v[-c] = false;
}
else f = i+1;
}
if(f>0)cout << f << endl;
else cout << "OK" << endl;
}

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

bool in[101];

void solve() {
    int L;
    cin >> L;
    stack<int> st;
    for (int i=1; i<=L; ++i) {
        int c;
        cin >> c;
        if (c > 0) {
            if (in[c]) {
                cout << i << endl;
                return;
            }
            st.push(c);
            in[c] = true;
        } else {
            if (st.empty() || st.top() != -c) {
                cout << i << endl;
                return;
            }
            st.pop();
            in[-c] = false;
        }
    }
    cout << "OK" << endl;
}

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

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int n; scanf("%d",&n);
    vector<int> a; set<int> used;
    rep(i,0,n){
        int p;scanf("%d",&p);
        bool f=p>0; p=abs(p);
        if((f&&used.count(p))||(!f&&(a.empty()||a.back()!=p))){
            printf("%d\n",i+1); return 0;
        }
        if(f){
            a.push_back(p); used.insert(p);
        }
        else{
            a.pop_back(); used.erase(p);
        }
    }
    printf("OK\n");
    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <stack>
#include <algorithm>
using namespace std;
bool cats[102];

int main(){
    int L, id, res = -1;
    stack<int> c;
    memset(cats, 0, sizeof (cats));
    scanf("%d", &L);
    for (int i = 1; i <= L; i++) {
        scanf("%d", &id);
        if (res < 0) {
            if (id < 0) {
                if (cats[abs(id)] && c.top() == abs(id)) { cats[abs(id)] = false; c.pop(); }
                else res = i;
            }
            else if (id > 0) {
                if (!cats[id]) { cats[id] = true; c.push(id); }
                else res = i;
            }
        }
    }
    (res == -1) ? printf("OK\n") : printf("%d\n", res);
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    stack<int> s;
    vector<int> df(100);
    int R = 0;
    int b;
    for (int i = 0;i < N;i++){
        int a;
        cin >> a;
        if(0 < a){
            df[a] += 1;
            for(int k = 0;k < 100;k++){
                if(df[k] >= 2){
                    R = i+1;
                    goto loop;
                  
                }
            }
            s.push(a);
        }else{
            if (s.size() == 0){
              R = i+1;
              break;
            }
            int top = s.top();
            if(top == a * -1){
                df[a*-1] = 0;  
                s.pop();
            }else{
              //cout << 1;
                R = i+1;
                break;
            }
        }
    }
    loop:
    if(R == 0){
        cout << "OK" << endl;
    }else{
        cout << R << endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
    int L; cin >> L;
    int c[1100];
    for(int i=0;i<L;i++){
        cin >> c[i];
    }
    int a[110];
    for(int i=0;i<100;i++){
        a[i] = -1;
    }
    int sp = 0;

    for(int i=0;i<L;i++){
        if(c[i]>0){
            if(a[c[i]-1]==-1){
                a[c[i]-1] = sp;
                sp++;
            }else{
                cout << i+1 <<endl;
                return 0;
            }
        }else{
            if(sp>0 && a[-c[i]-1]==sp-1){
                a[-c[i]-1] = -1;
                sp--;
            }else{
                cout << i+1 << endl;
                return 0;
            }
        }
    }
    cout << "OK" << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int l;
    cin >> l;
    int ok[100];
    memset(ok, -1, sizeof(ok));

    stack<int> sta;
    sta.push(0);
    rep(i, l) {
        int c;
        cin >> c;

        if (c > 0) sta.push(c);
        else {
            if (sta.top() != abs(c)) {
                cout << i+1 << endl;
                return 0;
            } else {
                sta.pop();
            }
        }

        if (c*ok[abs(c)] > 0) {
            cout << i+1 << endl;
            return 0;
        }

        ok[abs(c)] *= -1;
    }

    cout << "OK" << endl;

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<set>

using namespace std;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int l;
    cin >> l;

    vector<int> v;
    set<int> st;

    int ans = -1;
    for(int i = 1 ; i <= l ; ++i){
        int c;
        cin >> c;

        if(c > 0){
            if(st.count(c)){
                ans = i;
                break;
            }
            v.emplace_back(c);
            st.insert(c);
        }else{
            if(v.empty() || v.back() != -c){
                ans = i;
                break;
            }
            v.pop_back();
            st.erase(-c);
        }
    }

    if(ans > 0){
        cout << ans << endl;
    }else{
        cout << "OK" << endl;
    }

    return 0;
}