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 <stdio.h>
#include <stack>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, l, c, t;
  stack<ll> s;
  scanf("%lld", &l);
  bool b[200];
  for(i = 0; i < 200; ++i) b[i] = false;
  for(i = 0; i < l; i++) {
    scanf("%lld", &c);
    if(c > 0) {
      if(b[c]) {
        printf("%lld\n", i + 1);
        return 0;
      }
      s.push(c);
      b[c] = true;
    } else {
      if(s.empty()) {
        printf("%lld\n", i + 1);
        return 0;
      }
      t = s.top(), s.pop();
      if(t != -c) {
        printf("%lld\n", i + 1);
        return 0;
      }
      b[-c] = false;
    }
  }
  printf("OK\n");
  return 0;
}

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

int L;
int main(){
	cin >> L;
	stack<int> st;
	bool isIn[101] ={};
	for(int i=0; i<L; i++){
		int c;
		cin >> c;
		if(c < 0){
			if(st.size() == 0 || st.top() != -c){
				cout << i+1 << endl;
				return 0;
			}
			st.pop();
			isIn[-c] = false;
		}
		else{
			if(isIn[c]){
				cout << i+1 << endl;
				return 0;
			}
			st.push(c);
			isIn[c] = true;
		}
	}
	cout << "OK" << endl;
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int L,flag=0;;
  cin>>L;
  vector<int> c;

  for(int i=1;i<=L;i++){
    int x;
    int size=c.size();
    cin>>x;
    if(x<0&&size==0){
      cout<<i<<endl;
      flag=1;
      break;
    }
    else if(x>0){
      int num;
      for(int j=0;j<size;j++){
        if(x==c[j]){
          num=i;
          flag=1;
        }
      }
      if(flag==1){
        cout<<num<<endl;
        break;
      }
      else c.push_back(x);
    }
    else if(x<0){
      if(c[size-1]!=-1*x){
        cout<<i<<endl;
        flag=1;
        break;
      }
      else c.pop_back();
    }
  }
  if(flag==0) cout<<"OK"<<endl;
  return 0;
}