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>
using namespace std;

int main(){
    int l;
    cin >> l;
    stack<int> s;
    bool b[101] = {};
    for(int i = 1; i <= l; i++){
        int x;  cin >> x;
        bool ok = true;
        if(x > 0){
            if(b[x])    ok = false;
            b[x] = true;
            s.push(x);
        }else{
            x = -x;
            if(s.empty() || s.top() != x)  ok = false;
            if(!s.empty())  s.pop();
            b[x] = false;
        }
        if(!ok){
            cout << i << endl;
            return 0;
        }
    }
    cout << "OK" << endl;
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
using namespace std;

int main() {
  int l;
  cin >> l;
  vector<int> in_list(1000);
  stack<int> st;
  int c;
  int i;
  for (i = 0; i < l; i++) {
    cin >> c;
    if (0 < c) {
      if (in_list[c] == 0) {
        st.push(c);
        in_list[c] = 1;
      } else {
        cout << i + 1 << endl;
        return 0;
      }
    } else {
      if (st.empty()) {
        cout << i + 1 << endl;
        return 0;
      }
      if (st.top() != -c) {
        cout << i + 1 << endl;
        return 0;
      } else {
        st.pop();
        in_list[-c] = 0;
      }
    }
  }
  cout << "OK" << endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	stack<int> s;
	bool b[110] = {};

	rep(i, n) {
		int p; cin >> p;
		if (p > 0) {
			if (b[p]) {
				cout << i + 1 << endl;
				return 0;
			}
			s.push(p);
			b[p] = 1;
		}
		else if (s.size() == 0 || s.top() != -p || !b[-p]) {
			cout << i + 1 << endl;
			return 0;
		}
		else {
			b[-p] = 0;
			s.pop();
		}
	}
	puts("OK");
	return 0;
}

C++: #include<algorithm>
#include<stack>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

stack<long long> catstack;
int main(void)
{
	int L,i,c[1024];
	int catin[128]={0};
	cin>>L;
	for(i=0;i<L;i++)
	{
		cin>>c[i];
	}
	for(i=0;i<L;i++){
		if(c[i]>0){
			if(catin[c[i]]==1){
				cout<<i+1<<endl;
				return 0;
			}
			catin[c[i]]=1;
			catstack.push(c[i]);
		}else{
			if(catstack.empty()||catstack.top()!=-c[i]){
				cout<<i+1<<endl;
				return 0;
			}
			catstack.pop();
			catin[-c[i]]=0;
		}
	}
	cout<<"OK"<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int l;
    cin >> l;
    vector<int> ana;
    int check;
    int ind = 1001;
    if (l == 1) {
        cin >> check;
        if (check < 0) {
            cout << 1 << endl;
            return 0;
        }
        else {
            cout << "OK" << endl;
            return 0;
        }
    }
    for (int i = 0; i < l; i++) {
        cin >> check;
        if (check < 0) {
            if (ana.back() == abs(check)) {
                ana.pop_back();
            }
            else {
                ind = i;
                break;
            }
        }
        else {
            auto itr = std::find(ana.begin(), ana.end(), check);    //  最初の要素5へのイテレータを返す
            if( itr != ana.end() ) {     // 発見した場合
                ind = i;
                break;
            }
            else {
                ana.push_back(check);
            }
        }
    }
    if (ind == 1001) {
        cout << "OK" << endl;
    }
    else {
        cout << ind+1 << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
#include<iomanip>

#define	rep(i, n) for(int i=0; i<n; i++)

#define P pair<int, int>

typedef long long ll;

using namespace std;

#include <string>
#include <cctype>
typedef string::const_iterator State;
class ParseError {};


int main() {
	int L;
	stack<int> rec; rec.push(0);
	bool in[1005] = {};
	cin >> L;
	rep(i, L) {
		int c;
		cin >> c;
		if (c > 0) {
			if (in[c]) {
				cout << i+1 << endl;
				return 0;
			}
			in[c] = true;
			rec.push(c);
		}
		else {
			c = -c;
			int f = rec.top();
			if (f != c) {
				cout << i + 1 << endl;
				return 0;
			}
			rec.pop();
			in[c] = false;
		}
	}
	cout << "OK" << endl;

	return 0;
}

C++: #include <iostream>
using namespace std;

int main(){
  int kind[101];
  int n;
  cin >> n;
  for(int i = 0; i < 102; i++){
    kind[i] = 0;
  }
  int order = 0;
  for(int i = 0; i < n; i++){
    int temp;
    cin >> temp;
    if(temp > 0){
      order++;
      if(kind[temp] == 0){
      kind[temp] = order;
      }else{
        cout << i+1 << endl;
        return 0;
      }
    }
    if(temp < 0){
      if(kind[temp*-1] == order&&order != 0){
        kind[temp*-1] = 0;
      }else{
        cout << i+1 << endl;
        return 0;
      }
      order--;
    }
  }
  cout << "OK" << endl;
}

C++: #include<iostream>
#include<stack>
using namespace std;
bool b[1234];
stack<int>s;
signed main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int p; cin >> p;
		if (p > 0) {
			if (b[p]) {
				cout << i + 1 << endl;
				return 0;
			}
			s.push(p); b[p] = 1;
		}
		else if (s.size() == 0 || s.top() != -p || !b[-p]) {
			cout << i + 1 << endl;
			return 0;
		}
		else {
			b[-p] = 0; s.pop();
		}
	}
	cout << "OK\n";
}