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

vector<int> input(int N){
    int i;
    vector<int> output(N);
    for(i=0;i<N;i++)cin>>output[i];
    return output;
}

void disp(vector<int> cave,int tail){
    int i;
    for(i=0;i<=tail;i++)cout<<cave[i]<<" ";
    cout<<endl;
}

int main(){
    int L,i;
    int tail=0;
    int result=-1;
    vector<int> list,cat_in(100),cave(100);

    cin>>L;
    list=input(L);

    for(i=0;i<L;i++){
        if(list[i]<0){
            list[i]=abs(list[i]);
            if(cave[tail-1]!=list[i] || cat_in[list[i]-1]==0){
                result=i+1;
                break;
            }else{
                cat_in[list[i]-1]=0;
                tail-=1;
            }
        }else{
            if(cat_in[list[i]-1]==1){
                result=i+1;
                break;
            }else{
                cave[tail]=list[i];
                cat_in[list[i]-1]=1;
                tail+=1;
            }
        }
    }

    if(result==-1){
        cout<<"OK"<<endl;
    }else{
        cout<<result<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < int(n); i++)

int main(){
    int L;
    cin >> L;
    vector<int> cat;
    vector<bool> is_there(1000, false);
    rep(i, L){
        int c;
        cin >> c;
        if(c >= 1){
            if(is_there[c]){
                cout << i + 1 << endl;
                return 0;
            }
            cat.push_back(c);
            is_there[c] = true;
        }else{
            if(cat.empty() || cat.back() != -c){
                cout << i + 1 << endl;
                return 0;
            }
            cat.pop_back();
            is_there[-c] = false;
        }
    }
    cout << "OK" << endl;
}

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

int l, k = -1;
vector<int> v;

int main()
{
	cin >> l;

	for (int i = 0; i < l; i++) {
		int c;
		cin >> c;

		if (v.empty()) {
			if (c > 0)
				v.push_back(c);
			else {
				if (k < 0)
					k = i + 1;
			}
		}
		else if (c > 0 && find(v.begin(), v.end(), c) == v.end())
			v.push_back(c);
		else if (c < 0 && v.back() == -c)
			v.pop_back();
		else {
			if (k < 0)
				k = i + 1;
		}
	}

	if (k < 0)
		cout << "OK" << endl;
	else
		cout << k << endl;

	return 0;
}

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


int main(void){
    
    int L, c;
    int C[101] = {}, tunnel[1000] = {0}, put = 0;
    
    cin >> L;
    
    for(int i = 1; i <= L; i++){
        cin >> c;
        
        if(c > 0){
            
            // 判定：トンネルにネコが居ないか確認
            if(C[c] == 0){
                C[c] = 1;
                tunnel[ put ] = c;      // トンネルの先頭順番を決める（今回はスタックをイメージ）
                put++;                  // 次の先頭位置が変化するので １ プラスする
            } 
            
            else{
                cout << i << endl;
                return 0;
            }
        }
        
        if(c < 0){
            c *= -1;
            
            // 判定：トンネルにネコが居る　＋　トンネルの先頭は出口を出るネコか確認
            if(C[c] == 1 && tunnel[ put - 1] == c){
                C[c] = 0;
                put--;   
            }
            
            else{
                cout << i << endl;
                return 0;
            }
        }
    }
    
    cout << "OK" << endl;
    
}

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

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

    int ans;
    bool check(true);
    stack<int> s;
    map<int,int> mp;

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

    if(check){
        cout << "OK" << endl;
    }else
        cout << ans << endl;

    return 0;

}

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

using namespace std;

int L;
stack<int> CatInfo;
bool Exist[101];

int main() {
	int c;

	memset(Exist, false, sizeof(Exist));
	cin >> L;
	for (int i = 0; i < L; ++i) {
		cin >> c;
		if (c > 0) {
			if (Exist[c]) {
				cout << i + 1 << endl;
				return 0;
			}
			Exist[c] = true;
			CatInfo.push(c);
			continue;
		}
		if (CatInfo.empty() || CatInfo.top() != -c) {
			cout << i + 1 << endl;
			return 0;
		}
		Exist[CatInfo.top()] = false;
		CatInfo.pop();
	}
	cout << "OK" << endl;

	return 0;
}

C++: //ねこのあな(stackとvectorを使わない)
#include<bits/stdc++.h>
using namespace std;

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

  int stk[101]; //穴の中を再現 初期値はすべて0
  for(int i=0; i<100; i++) stk[i] = 0;
  //stk(穴の座標) = 猫番号
  int top = 0; //穴の先頭にいる猫の座標
  
  int flag[101]; //その猫が穴の中なら1 初期値はすべて0
  for(int i=0; i<100; i++) flag[i] = 0;
  //flag(猫番号) = 1か0
  
  for(int i=0; i<L; i++) {
    int c;
    cin >> c;

    if(c > 0) {
      ////////////////
      //猫が入るとき//
      ////////////////
      if(flag[c] == 1) {
        //その猫はすでに穴の中のとき
        cout << i + 1 << endl;
        return 0;//プログラム終了
      }

      //猫を穴に入れる
      top++;
      stk[top] = c;
      flag[c] = 1;
    } else {
      ////////////////
      //猫が出るとき//
      ////////////////
      c = c * -1;//番号を正に
      if (flag[c] != 1 or stk[top] != c) {
        //その猫は穴の中にいない or その猫は穴の先頭にいない とき
        cout << i + 1 << endl;
        return 0;//プログラム終了
      }

      //猫を穴から出す
      stk[top] = 0;
      top--;
      flag[c] = 0;
    }
  }
  cout << "OK" << endl;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, b = 0; cin >> n;
	int test[101] = { 0 }, uiop[1001] = { 0 };
	for (int h = 1; h <= n; h++) {
		cin >> a;
		if (a > 0) {
			test[a]++;
			if (test[a] == 2) {
				cout << h << endl;
				cin >> n; return 0;
			}
			uiop[b] = a; b++;
		}
		else {
			test[abs(a)]--;
			if (uiop[b - 1] != abs(a)) {
				cout << h << endl;
				cin >> n; return 0;
			}
			else {
				uiop[b - 1] == 0; b--;
			}
		}
	}
	cout << "OK" << endl;
	cin >> n;
}