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>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;

//ねこのあな
int main() {
    int l;
    cin >> l;
    stack<int> c;
    bool can = true;
    int error = 0;
    vector<int> data(l,0);
    rep(i,l){
        cin >> data[i];
    }
    vector<bool> now(l+1,false);
    rep(i,l){
        if(data[i] > 0){//はいる時
            if(now[data[i]] == false){
                now[data[i]] = true;
                c.push(data[i]);
            }
            else{
                cout << i+1 << endl;
                return 0;
            }
        }else{//出る時
            if(i == 0 && data[i] < 0){
                cout << 1 << endl;
                return 0;
            }
            if(c.top() == 0-data[i] && now[0-data[i]] == true){
                now[0-data[i]] = false;
                c.pop();
            }else{
                cout << i+1 << endl;
                return 0;
            }
        }
    }
    cout << "OK\n";
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

C++: #include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>

using namespace std;

int main(void) {
	int L, tmp;
	bool c[100];//猫が穴に入っているかのフラグ
	for (int i = 0; i < 100; i++) c[i] = false;
	stack<int> stack;

	cin >> L;
	for (int i = 0; i < L; i++) {
		cin >> tmp;
		if (tmp > 0) {
			if (!c[abs(tmp)]) {
				c[abs(tmp)] = true;//反転
				stack.push(abs(tmp));
			}
			else {
				std::cout << (i + 1) << endl;
				return 0;
			}
		}
		else {
			if ((stack.size()==0) || (stack.top() != abs(tmp))){
				std::cout << i + 1 << endl;
				return 0;
			}
			else { stack.pop(); c[abs(tmp)] = false; }
		}
	}
	std::cout << "OK" << endl;

	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    int n;
    cin >> n;
    V<int> cat(101);
    stack<int> st;
    Rep(i,n) {
        int a;
        cin >> a;
        bool ok = true;
        if(cat[abs(a)] && a > 0) ok = false;
        if(!cat[abs(a)]&& a < 0) ok = false;
        if(a > 0) st.push(a);
        else {
            if(!sz(st))
                ok = false;
            else {
                int b = st.top(); st.pop();
                if(abs(a) != b) ok = false;
            }
        }
        cat[abs(a)] = ~cat[abs(a)];
        if(!ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << "OK" << endl;
}

C++: #include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=998244353 ;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//17:00~

int main(void){
	cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
	int i,n;cin>>n;
	stack<int>s;
	s.push(0);
	int in[101]={};
	for(i=1;i<=n;i++){
		int x;cin>>x;
		if(x>0){
			if(in[x]){cout<<i<<endl;return 0;}
			in[x]=1;
			s.push(x);
		}else{
			x*=-1;
			if(s.top()!=x){cout<<i<<endl;return 0;}
			s.pop();
			in[x]=0;
		}
	}
	cout<<"OK"<<endl;
	return 0;
}

C++: #include <iostream>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//using graph = vector<vector<ll>>;


int main() {
	ll l,mem,ans=-1;
	stack<int> c;
	vector<bool> kanri(100, false);
	cin >> l;
	for (ll i = 0; i < l; i++) {
		cin >> mem;
		if (mem > 0&&kanri[mem]==false) {
			c.push(mem);
			kanri[mem] = true;
		}
		else if (mem>0&&kanri[mem]==true) {
			ans = i + 1;
			break;
		}
		else if(mem<0 && c.empty()==true){
			ans = i + 1;
			break;
		}
		else if (mem < 0 && c.top() == -mem) {
			c.pop();
			kanri[-mem] = false;
		}
		else if (mem < 0 && c.top() != -mem) {
			ans = i + 1;
			break;
		}
		else if (mem < 0 && kanri[-mem] == false) {
			ans = i + 1;
			break;
		}
	}
	if (ans == -1) {
		cout << "OK" << endl;
	}
	else {
		cout << ans << endl;
	}

	return 0;
}