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>
typedef long long lint;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int sgn(int n) {
    if (n>0) return 1;
    else if (n<0) return -1;
    else return 0;
}

int main() {
    int l; cin >> l;
    stack<int> s;
    set<int> li;
    int out = -1;
    rep(i,l) {
        int t; cin >> t;
        if (sgn(t) == 1) {
            if (li.find(t) != li.end()) {
                out = i;
                break;
            }
            else s.push(t);
            li.insert(t);
        }
        else {
            t = -t;
            if (li.find(t) == li.end() or s.top() != t) {
                out = i;
                break;
            }
            else s.pop();
            li.erase(t);
        }
    }
    if (out == -1) cout << "OK" << endl;
    else cout << out+1 << endl;
}

C++: #include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 1; i < (n); i++)
using namespace std;
using ll = long long;

int f[101];

int main() {
	
	int L;
	cin >> L;
	vector<int> c(L);
	vector<int> F(101);
	int cnt = 1;
	cin >> c[0];
	if (c[0] < 0) {
		cout << cnt << endl;
		return 0;
	}
	F[c[0]] = 1;
	int i = 1;
	while(i<L) {
		cin >> c[i];
		cnt++;
		if (c[i] > 0) {
			if (F[c[i]] == 0) {
				F[c[i]] = 1;
			}
			else {
				std::cout << cnt << endl;
				return 0;
			}
		}

		if (c[i] < 0) {

			if (c[i] ==-1* c[i - 1]) {
				F[c[i-1]]= 0;
				c.pop_back();
				c.pop_back();
				i -= 2; L -= 2;
			}
			else {
				std::cout << cnt << endl;
				return 0;
			}

		}
		i++;
	}

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

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

using namespace std;

void solve()
{
    int n;
    cin >> n;
    deque<int> cs;
    set<int> s;
    for (int i = 0; i < n; i++)
    {
        int c;
        cin >> c;
        if (c > 0)
        {
            if (s.find(c) != s.end())
            {
                cout << i + 1 << endl;
                return;
            }
            s.insert(c);
            cs.push_back(c);
        }
        else
        {
            if (cs.empty() || cs.back() != -c)
            {
                cout << i + 1 << endl;
                return;
            }
            cs.pop_back();
            s.erase(s.find(-c));
        }
    }
    cout << "OK" << endl;
}

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

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

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

    stack<int> st;
    vector<bool> check;
    for(int i=0;i<=100;i++){
        check.push_back(false);
    }

    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        //stackから取り出して判定
        if(x<0){
            //空じゃなかったら
            if(!st.empty()){
                int top = st.top();
                //topと値が一緒かどうかの判定
                if(top!=abs(x)){
                    cout << i+1 << endl;
                    return 0;
                }else{
                    st.pop();
                    check[abs(x)] = false;
                }
            }else{
                cout << i+1 << endl;
                return 0;
            }
        }else{
            //穴にはいる
            st.push(x);
            if(check[x]){
                cout << i+1 << endl;
                return 0;
            }
            check[x] = true;
        }
    }

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

C++: // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

bool in[110];
int main() {
    int L; cin >> L;
    stack<int> st;
    
    int ng = -1;
    for(int i=0; i<L; i++) {
        int v; cin >> v;
        if(v < 0) {
            v = -v;
            if(!in[v]) ng = i+1;
            if(st.empty() or st.top() != v) ng = i+1;
            in[v] = false;
            st.pop();
        }
        else {
            if(in[v]) ng = i+1;
            in[v] = true;
            st.push(v);
        }
        
        if(ng != -1) break;
    }

    if(ng < 0) cout << "OK" << endl;
    else cout << ng << endl;
    return 0;
}

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

int main(){
	int L;
	cin >> L;
	
	bool has[101];
	for(int i=1; i<=100; ++i){has[i] = false;}
	
	int hole[2000];
	int n=0;
	
	for(int i=1; i<=L; ++i){
		int cat; cin>>cat;
		if(cat < 0){
			cat = -cat;
			if( n == 0 || !has[cat]){
				cout<<i<<endl;
				return 0;
			}else if( hole[n-1] == cat ){
				has[cat] = false;
				n--;
			}else{
				cout<<i<<endl;
				return 0;
			}
		}else{
			if( has[cat] ){
				cout<<i<<endl;
				return 0;
			}
			has[cat] = true;
			hole[n] = cat;
			n++;
		}
	}
	cout << "OK\n";
}

C++: #include "bits/stdc++.h"
using namespace std;
int main() {
	stack<int>A;
	int N; cin >> N;
	vector<int>B(N);
	vector<bool>C(10000, false);
	for (int i = 0; i < N; i++) {
		cin >> B.at(i);
		if (B.at(i) > 0) {
			if (C.at(B.at(i) - 1)) {
				cout << i + 1 << endl;
				return 0;
			}
			else {
				A.push(B.at(i));
				C.at(B.at(i) - 1) = true;
			}
		}
		else {
			if (A.empty()) {
				cout << i + 1 << endl;
				return 0;
			}
			else if (abs(B.at(i)) != A.top()) {
			    cout << i + 1 << endl;
			    return 0;
			}
			else {
				A.pop();
				C.at(abs(B.at(i)) - 1) = false;
			}
		}
	}
	cout << "OK" << endl;
}