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)
	}
}

Python: from collections import deque
L = int(input())
d = deque()
d_set = set()
clist = list(map(int, input().split()))
for i in range(L):
    c = clist[i]
    if c > 0:
        if c in d_set:
            print(i+1)
            break
        d.append(c)
        d_set.add(c)
    else:
        c *= -1
        if not d or d.pop() != c:
            print(i+1)
            break
        d_set.remove(c)
else:
    print("OK")

Python: if __name__ == '__main__':

	n = int(input())
	A = list(map(int,input().split()))
	B = []

	for i,j in enumerate(A):
		if j > 0:
			if j not in B:
				B.append(j)
			else:
				print(i+1)
				break

		else:
			if len(B) != 0:
				p = B[-1]
				if p != abs(j):
					print(i+1)
					break
				else:
					B.pop(-1)
			else:
				print(i+1)
				break

	else:
		print("OK")

Python: n = int(input())
a = [int(s) for s in input().split()]
memory = []
flag = False
for i in range(n):
    if a[i] > 0:
        if a[i] in memory:
            print(i+1)
            flag = True
            break
        else:
            memory.append(a[i])
    else:
        if len(memory) > 0 and memory[-1] == abs(a[i]):
            memory.pop()
        else:
            print(i+1)
            flag = True
            break

if flag == False:
    print("OK")

Python: l = int(input())
c = list(map(int, input().split()))

from collections import deque

def sign(n):
    if n<0: return -1
    if n>0: return 1
    return 0

ans = -1
neko = set()
q = deque()
j = 0
for i in c:
    if sign(i) == 1:
        if i in neko:
            ans = j
            break
        q.append(i)
        neko.add(i)
    else:
        if len(q) > 0:
            if -q.pop() != i or -i not in neko:
                ans = j
                break
            neko.remove(-i)
        else:
            ans = j
            break

    j += 1

if ans == -1:
    print("OK")
else:
    print(ans + 1)

Python: n = int(input())
cats = list(map(int, input().split()))

hole = []
p = "OK"

for i in range(n):
    if cats[i] < 0:
        if len(hole)==0 or cats[i] != -1*hole[-1]:
            p = str(i+1)
            break
        else:
            hole.pop()
    else:
        if cats[i] in hole:
            p = str(i+1)
            break
        else:
            hole.append(cats[i])

print(p)

Python: input()#入力１
l_m = [int(i) for i in input().split()]#入力２[]コピペで数列化(整数i)
l_t = []#空のリストを作る[]
ret = 0#返された情報を表示する形式を作る
for index,i in enumerate(l_m):#forでifの計算式をループ処理させるenuでインデックス番号（要素数）を取得
    if i > 0:#プラスの時
        if not i in l_t:#l_tの中にiがないとき
            l_t.append(i)#l_tに送る
        else:#おかしいの
            ret = index + 1#おかしい瞬間を現在の要素数+1してretで送る
            break
    elif i < 0:#マイナスの時
        
        if len(l_t) > 0 and l_t[-1] == - i:#lenでリスト内要素数を取得l_tにiが最後尾[-1]にあるとき
            l_t.pop(-1)#l_tの最後尾を消す
        else:#おかしいの
            ret = index + 1#おかしい瞬間を現在の要素数+1してretで送る
            break
if ret == 0:#retが０の時はＯＫを出力
    print("OK")
else:#それ以外は弾かれた瞬間+1の要素数=retで出力
    print(ret)

Python: n = int(input())
lst = list(map(int, input().split()))

stack = []
ans = 'OK'
for i in range(n) :
    x = lst[i]
    if x > 0 :
        if x not in stack :
            stack.append(x) 
        else :
            print(i+1)
            ans = 'NG'
            break
    else :
        if len(stack) == 0 or stack[-1] != -x :
            print(i+1)
            ans = 'NG'
            break
        else :
            del stack[-1]
if ans == 'OK' :
    print(ans)

Python: # coding: utf-8
# Your code here!

cats = [0 for i in range(101)]
stack = []

L = int(input())
c = [int(i) for i in input().split()]

ans = -1
for i in range(L):
    if c[i] > 0:
        if cats[c[i]] == 1:
            ans = i + 1
            break
        else:
            cats[c[i]] = 1
            stack.append(c[i])
    else:
        if cats[-c[i]] == 0:
            ans = i + 1
            break
        else:
            cats[-c[i]] = 0
            if(stack.pop() != -c[i]):
                ans = i + 1
                break
if ans < 0:
    print("OK")
else:
    print(ans)

Python: L = int(input())
a = list(map(int, input().split()))
b = []
flag = 0
for i in range(L):
    if a[i] > 0:
        if a[i] in b:
            print(i+1)
            flag = 1
            break
        else:
            b.append(a[i])
    else:
        if len(b) > 0 and b[-1] == -a[i]:
            b.pop()
        else:
            print(i+1)
            flag = 1
            break
if flag == 0:
    print('OK')

Python: n, *a = map(int, open(0).read().split())
stack = []
isOK = 0
for i in range(n):
    if a[i]>0:
        if a[i] in stack: break
        stack.append(a[i])
    else:
        if not stack: break
        if -a[i] != stack.pop(): break
else: isOK = 1
print("OK" if isOK else i+1)

Python: n = int(input())
lis = list(map(int,input().split()))
now = []
key = 0
cat = [0 for i in range(101)]
for i in range(n):
  if lis[i] > 0:
    now.append(lis[i])
    cat[lis[i]] += 1
    if cat[lis[i]] > 1:
      print(i+1)
      key = 1
      break
  else:
    try:
      num = now.pop(-1)
      cat[num] -= 1
      if lis[i]*(-1) != num:
        print(i+1)
        key = 1
        break
    except:
      print(i+1)
      key = 1
      break
if key == 0:print("OK")

Python: L = int(input())
C = list(map(int, input().split()))

cats = set()
cave = []

for i, c in enumerate(C, 1):
    if c > 0:
        if c not in cats:
            cats.add(c)
            cave.append(c)
        else:
            print(i)
            exit()
    else:
        c = abs(c)
        if len(cave) > 0 and cave[-1] == c:
            cats.remove(c)
            cave.pop(-1)
        else:
            print(i)
            exit()

print('OK')

Python: a = int(input())
b = list(map(int,input().split()))
cave = []
for i in range(a):
    cat = b[i]
    if cat > 0:
        if cat in cave:
            print(i+1)
            break
        else:
            cave.append(cat)
    else:
        if -(cat) in cave:
            if -(cat) == cave[-1]:
                cave.remove(-(cat))
            else:
                print(i+1)
                break
        else:
            print(i+1)
            break
    if i + 1 == a:
        print("OK")

Python: l=int(input())
c=list(map(int,input().split()))
ans='OK'
cat=[]
for i in range(l):
    if c[i]>0:
        if c[i] in cat:
            ans=i+1
            break
        else:
            cat.append(c[i])
    else:
        if len(cat)==0:
            ans=i+1
            break
        elif abs(c[i])!=cat[-1]:
            ans=i+1
            break
        else:
            cat.pop(-1)
print(ans)