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 <stack>
#include <set>
using namespace std;
int main(){
    int n;cin>>n;
    stack<int> A;
    set<int> B;
    for(int i = 0; n > i; i++){
        int z;cin>>z;
        if(z<0){
            if(A.size() && A.top()==abs(z)){
                A.pop();
                B.erase(abs(z));
            }else{
                cout << i+1 << endl;
                return 0;
            }
        }else{
            if(B.find(z)==B.end()){
                A.push(z);
								B.insert(z);
            }else{
                cout << i+1 << endl;
                return 0;
            }
        }
    }
    cout << "OK" << endl;
}

C++: #include<bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int L, C[1010];
int flag[101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> L;

    stack<int> stk;
    rep(i, 0, L) {
        int c; cin >> c;
        if (0 < c) {
            // 入る
            if (flag[c]) {
                cout << i + 1 << endl;
                return;
            }

            flag[c] = true;
            stk.push(c);
        } else {
            // 出る
            c *= -1;
            if (!flag[c] or stk.top() != c)
            {
                cout << i + 1 << endl;
                return;
            }
            stk.pop();
            flag[c] = false;
        }
    }
    cout << "OK" << endl;
}

C++: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

int main(){
    INT(n);
    stack<int> s;
    vector<int> cat(101,0);
    int x;
    rep(i,n){
        in(x);
        if(x>0){
            if(cat[x]>=1){
                out(i+1);
                return 0;
            }
            s.push(x);
            cat[x]++;
        }else{
            x=-x;
            if(!s.empty()&&x==s.top()){
                s.pop();
                cat[x]--;
            }else{
                out(i+1);
                return 0;
            }
        }
    }
    out("OK");
}

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

using namespace std;

int main(){
	ll n, i;
	
	cin>>n;
	
	vector <ll> a(n+1);
	bool b[101]={0};
	stack <ll> house;
	
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	
	ll k=0, g;
	for(i=1;i<=n;i++){
		if(a[i]>0){
			if(!b[a[i]]){
				b[a[i]]=1;
				house.push(a[i]);	
			}
				else{
					k=i;
					break;
				}
		}
			else {
				if(b[a[i]*(-1)]){
					g=house.top();
					house.pop();
					if(a[i]*(-1)==g) b[a[i]*(-1)]=0;
						else k=i;
				}
					else{
						k=i;
						break;
					}
			}
	}
	
	if(k==0) cout<<"OK\n";
		else cout<<k<<endl;
	
}

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

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

    int a[1000];
    for(int i=1;i<=L;i++){
        cin >> a[i];
    }

    int b[101]; // 猫のスタック位置
    for(int i=1; i<=100; i++){ 
        b[i] = -1;
    }
    int sp = 0;

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