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>
#include<stack>
using namespace std;
int main() {
	int a,i;
	bool f = true;
	stack<int> c;
	cin >> a;
	vector<int>b(a);
	vector<bool>d(1001,true);
	for (i = 0;i < a;i++) {
		cin >> b[i];
		if (b[i] > 0) {
			c.push(b[i]);
			if (d[b[i]]) d[b[i]] = false;
			else {
				f = false;
				break;
			}
		}
		else {
			if (d[b[i]*-1]) {
				f = false;
				break;
			}
			else if (c.top() != b[i] * -1) {
				f = false;
				break;
			}
			else {	
				c.pop();
				d[b[i] * -1] = true;
			}
		}
	}
	if (f)cout << "OK" << endl;
	else cout << i + 1 << endl;
}

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

#define int long long
#define rep(i,n) for(int i=0; i<(n); i++)
#define lep(j,n) for(int j=0; j<(n); j++)
#define reps(i,n) for(int i=1; i<=(n); i++)
#define leps(j,n) for(int j=1; j<=(n); j++)

using namespace std;
bool a[1000];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    stack<int> st;

    int l;
    cin>>l;

    for(int i=1; i<=l; i++){

        int n;
        cin>>n;

        if(n>0){
            if(a[n]==0){
                st.push(n);
                a[n]++;
            }else{
                cout<<i<<'\n';
                return(0);
            }
        }else{
            if(st.empty()){
                cout<<i<<'\n';
                return(0);
            }else{
                if(st.top()==-n){
                    st.pop();
                    a[-n]=false;
                }else{
                    cout<<i<<'\n';
                    return(0);
                }
            }
        }
    }
    cout<<"OK\n";
}

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

int main(){
    int L; cin >> L; int A[L];
    stack<int> s; 
    bool fg = true; int ans(0);
    map<int,int> mp;

    for(int i=0;i<L;i++){
        int x; cin >> x;
        if(x<0){
            if(s.empty()){
                ans = i;
                fg = false;
                break;
            }
            else if((-1)*x != s.top()){
                ans = i;
                fg = false;
                break;
            }
            else{
                s.pop();
                mp[(-1)*x] = 0;
            }
        }else{
            if(mp[x] == 1){
                ans = i;
                fg = false;
                break;
            }
            else{
                mp[x]++;
                s.push(x);
            }
        }
    }

    if(fg){
        cout << "OK" << endl;
    }
    else{
        cout << ans+1 << endl;
    }

    return 0;

}

C++: #define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n;
  cin>>n;
  
  vector<int> A(n),B(n+1);
  rep(i,n) cin>>A[i];
  
  stack<int> s;
  int ans=0;
  rep(i,n){
    if(A[i]>0){
      if(B[A[i]]==1){
        ans=i+1;
        break;
      }
      s.push(A[i]);
      B[A[i]]=1;
    }
    else{
      if(s.size()==0 || s.top()!=-A[i]){
        ans=i+1;
        break;
      }
      else{
        s.pop();
        B[-A[i]]=0;
      }
    }
  }
  
  if(ans) cout<<ans<<endl;
  else cout<<"OK"<<endl;
  
  return 0;
}

C++: /*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int l;
	scanf("%d", &l);
	stack<int> st;
	set<int> a;
	rep(i, l) {
		int c;
		scanf("%d", &c);
		if (c < 0) {
			if(st.empty()) {
				printf("%d\n", i + 1);
				return 0;
			}
			if (st.top() != -c) {
				printf("%d\n", i + 1);
				return 0;
			}
			else {
				st.pop();
				a.erase(-c);
			}
		}
		else {
			if (a.find(c) != a.end()) {
				printf("%d\n", i + 1);
				return 0;
			}
			else {
				st.push(c);
				a.insert(c);
			}
		}
	}
	puts("OK");

	Please AC;
}