Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

H, W, M = map(int, input().split())
cntH = {}
cntW = {}
bomb = set()
for i in range(M):
    h, w = map(int, input().split())
    bomb.add((h-1,w-1))
    cntH[h-1] = cntH.get(h-1, 0) + 1
    cntW[w-1] = cntW.get(w-1, 0) + 1

max_H_list = [kv[0] for kv in cntH.items() if kv[1] == max(cntH.values())]
max_W_list = [kv[0] for kv in cntW.items() if kv[1] == max(cntW.values())]
ans = max(cntH.values()) + max(cntW.values())

flag = False
for i in max_H_list:
    for j in max_W_list:
        if (i, j) not in bomb:
            flag = True
            break
    else:
        continue
    break
if not flag:
    ans -= 1
print(ans)

### FIXED CODE ###

H, W, M = map(int, input().split())
cntH = {}
cntW = {}
bomb = set()
for i in range(M):
    h, w = map(int, input().split())
    bomb.add((h-1, w-1))
    cntH[h-1] = cntH.get(h-1, 0) + 1
    cntW[w-1] = cntW.get(w-1, 0) + 1

maxH, maxW = max(cntH.values()), max(cntW.values())
max_H_list = [kv[0] for kv in cntH.items() if kv[1] == maxH]
max_W_list = [kv[0] for kv in cntW.items() if kv[1] == maxW]

ans = maxH + maxW - 1
flag = False
for i in max_H_list:
    for j in max_W_list:
        if (i, j) not in bomb:
            flag = True
            break
    else:
        continue
    break
if flag:
    ans += 1

print(ans)
### BUGGY CODE ###

#未提出
n, x, y = map(int, input().split())
lis = []
for i in range(1, n):
    for j in range(i+1, n+1):
        lis.append(min([j-i, abs(x-i)+1+abs(y-j), abs(y-i)+1+abs(x-j)]))
import collections
dic = collections.Counter(lis)
for i in range(1, n):
    print(dic[i])

### FIXED CODE ###

n, x, y = map(int, input().split())
lis = [0]*(n-1)
for i in range(1, n):
    for j in range(i+1, n+1):
        lis[min([j-i, abs(x-i)+1+abs(y-j), abs(y-i)+1+abs(x-j)])-1] += 1
for i in range(n-1):
    print(lis[i])
### BUGGY CODE ###

s = input()
q = int(input())
rev = 0
revcnt = 0
for _ in range(q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        revcnt += 1
        if rev == 0:
            rev = 1
        elif rev == 1:
            rev = 0

    elif query[0] == "2":
        if rev == 0:
            if query[1] == "1":
                s = query[2] + s
            elif query[1] == "2":
                s = s + query[2]
        else:
            if query[1] == "1":
                s = s + query[2]
            elif query[1] == "2":
                s = query[2] + s

if revcnt%2 == 0:
    print(s)
else:
    print(s[::-1])

### FIXED CODE ###

from collections import deque
s = list(input())
q = int(input())
rev = 0
revcnt = 0
s_q = deque(s)
for _ in range(q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        revcnt += 1
        if rev == 0:
            rev = 1
        elif rev == 1:
            rev = 0

    elif query[0] == "2":
        if rev == 0:
            if query[1] == "1":
                s_q.appendleft(query[2])
            elif query[1] == "2":
                s_q.append(query[2])
        else:
            if query[1] == "1":
                s_q.append(query[2])
            elif query[1] == "2":
                s_q.appendleft(query[2])
s = list(s_q)
if revcnt%2 == 0:
    print("".join(s))
else:
    print("".join(s[::-1]))
### BUGGY CODE ###

import sys
H, W = map(int, input().split())
S = [line.strip("\n") for line in sys.stdin]

# i行j列に置いたとき上下左右の方向それぞれに光の軌跡が何マス伸びるか(自マスを含む)
trailLeft = [[0] * W for _ in range(H)]
trailRight = [[0] * W for _ in range(H)]
trailUp = [[0] * W for _ in range(H)]
trailDown = [[0] * W for _ in range(H)]

for i in range(H):  # 各行について下に見ていく
    for j in range(W):  # その行の各列について右に見ていく
        if S[i][j] == '#':
            pass  # そのマスに置いたとき照らすのは0マス(置けないので)
        else:
            if i == 0 and j == 0:  # 左上
                trailLeft[i][j] = 1
                trailUp[i][j] = 1
            elif i == 0:  # 最上行
                trailLeft[i][j] = trailLeft[i][j - 1] + 1
                trailUp[i][j] = 1
            elif j == 0:  # 最左列
                trailLeft[i][j] = 1
                trailUp[i][j] = trailUp[i - 1][j] + 1
            else:
                trailLeft[i][j] = trailLeft[i][j - 1] + 1
                trailUp[i][j] = trailUp[i - 1][j] + 1

        k = H - i - 1  # H-1 to 0
        l = W - j - 1  # W-1 to 0
        # 左上に見ていく
        if S[k][l] == "#":
            pass
        else:
            if k == H - 1 and l == W - 1:  # 右下
                trailRight[k][l] = 1
                trailDown[k][l] = 1
            elif k == H - 1:  # 最下行
                trailRight[k][l] = trailRight[k][l + 1] + 1
                trailDown[k][l] = 1
            elif l == W - 1:  # 最右列
                trailRight[k][l] = 1
                trailDown[k][l] = trailDown[k + 1][l] + 1
            else:
                trailRight[k][l] = trailRight[k][l + 1] + 1
                trailDown[k][l] = trailDown[k + 1][l] + 1

ans = 0
for i in range(H):  # 各行について下に見ていく
    for j in range(W):  # その行の各列について右に見ていく
        ans = max(ans, trailLeft[i][j] + trailRight[i][j] + trailUp[i][j] + trailDown[i][j] - 3)

print(ans)


### FIXED CODE ###

# can't AC without numpy, Python array handling with for is SLOW
import numpy as np
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))
S = (np.array(S) == ".") * 1

# i行j列に置いたとき上下左右の方向それぞれに光の軌跡が何マス伸びるか(自マスを含む)
trailLeft = np.zeros((H, W), dtype=int)
trailRight = np.zeros((H, W), dtype=int)
trailUp = np.zeros((H, W), dtype=int)
trailDown = np.zeros((H, W), dtype=int)

for i in range(H):
    if i == 0:
        trailUp[i] = S[i]
        trailDown[H - i - 1] = S[H - i - 1] * 1
    else:
        trailUp[i] = (trailUp[i - 1] + 1) * S[i]
        trailDown[H - i - 1] = (trailDown[H - i] + 1) * S[H - i - 1]

for j in range(W):
    if j == 0:
        trailLeft[:, j] = S[:, j]
        trailRight[:, W - j - 1] = S[:, W - j - 1] * 1
    else:
        trailLeft[:, j] = (trailLeft[:, j - 1] + 1) * S[:, j]
        trailRight[:, W - j - 1] = (trailRight[:, W - j] + 1) * S[:, W - j - 1]

print(np.max(trailLeft + trailRight + trailUp + trailDown - 3))
### BUGGY CODE ###

def make_divisors(n):
    cnt = 0
    i = 1
    while i*i <= n:
        if n % i == 0:
            cnt += 1
            if i != n // i:
                cnt += 1
        i += 1
    return cnt
numbers = [1,10, 100, 1000, 10000, 100000, 200000, 250000,300000,350000, 400000,450000, 500000,550000,600000,630000,675000,750000,800000,825000,850000,875000,900000,925000,950000,975000,1000000]
datas = [0,23,473,7053,93643,1166714, 2472071, 3145923, 3829761, 4522005,5221424,5927120,6638407,7354651,8075420,8509899,9164377,10261678,10997400,11366472,11736253,12106789,12478098,12850013,13222660,13595947,13969985]

N = int(input())
ttl = 0
numPin = 0

for i in range(len(numbers)):
    if N == 1000000:
        numPin = len(numbers) - 1
        break
    if numbers[i] <= N < numbers[i+1]:
        numPin = i
        break

if numPin != len(numbers)-1:
    if N - numbers[numPin] < numbers[numPin + 1] - N:
        for i in range(numbers[numPin], N):
            ttl += make_divisors(i)
        print(ttl + datas[numPin])
    else:
        for i in range(N,numbers[numPin+1]):
            ttl -= make_divisors(i)
        print(ttl + datas[numPin + 1])
else:
    print(datas[numPin])


### FIXED CODE ###

def make_divisors(n):
    cnt = 0
    i = 1
    while i*i <= n:
        if n % i == 0:
            cnt += 1
            if i != n // i:
                cnt += 1
        i += 1
    return cnt
numbers = [1,10, 100, 1000, 10000, 100000, 150000,200000, 250000,300000,350000, 400000,450000, 500000,550000,600000,630000,675000,700000,720000,750000,800000,825000,850000,875000,900000,912500,925000,950000,975000,987500,1000000]
datas = [0,23,473,7053,93643,1166714, 1810893, 2472071, 3145923, 3829761, 4522005,5221424,5927120,6638407,7354651,8075420,8509899,9164377,9529244,9821778,10261678,10997400,11366472,11736253,12106789,12478098,12664043,12850013,13222660,13595947,13782871,13969985]

N = int(input())
ttl = 0
numPin = 0

for i in range(len(numbers)):
    if N == 1000000:
        numPin = len(numbers) - 1
        break
    if numbers[i] <= N < numbers[i+1]:
        numPin = i
        break

if numPin != len(numbers)-1:
    if N - numbers[numPin] < numbers[numPin + 1] - N:
        for i in range(numbers[numPin], N):
            ttl += make_divisors(i)
        print(ttl + datas[numPin])
    else:
        for i in range(N,numbers[numPin+1]):
            ttl -= make_divisors(i)
        print(ttl + datas[numPin + 1])
else:
    print(datas[numPin])
### BUGGY CODE ###

N = int(input())
import numpy as np
#max=int(np.sqrt(N))

for n in range(1,N+1):
    j=0
    min = 1
    max = int(np.sqrt(abs(n-2)))
    #print(max)
    for x in range(min,max):
        #print(f'max:{max}')
        for y in range(min, max):
            for z in range(min, max):
                if x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x > n:
                    break
                if x**2+y**2+z**2+x*y+y*z+z*x==n:
                    if x == y == z:
                        j += 1
                        break
        #     else:
        #         continue
        #     break
        # else:
        #     continue
        # break
                    if j==0:
                        max = z+1
                        min += 1
                        #min = x
                        #print(x, y, z)
                        #print(f'n:{n}')
                        j += 3
                    # else:
                    #     j += 3

    print(j)

### FIXED CODE ###

n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
	for j in range(1,105):
		for k in range(1,105):
			v = i*i+j*j+k*k+i*j+j*k+k*i;
			if v<10050:
				ans[v]+=1

for i in range(n):
  	print(ans[i+1])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = list(zip(b, a))
 
a.sort()
b.sort()
for i in range(n):
  if a[i] > b[i]:
    print('No')
    exit()

ptr, pos = {}, {}
for i in range(n):
  if i > 0 and a[i] <= b[i - 1]:
    print('Yes')
    exit()
  ptr[l[i][1]] = l[i][0]
  pos[b[i]] = i

sta, now, cnt = a[0], a[0], 1
while ptr[now] != sta:
  now = a[pos[ptr[now]]]
  cnt += 1
if cnt == n:
  print('No')
else:
  print('Yes')


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = list(zip(b, a))
 
a.sort()
b.sort()
for i in range(n):
  if a[i] > b[i]:
    print('No')
    exit()

ptr, pos = {}, {}
for i in range(n):
  if i > 0 and a[i] <= b[i - 1]:
    print('Yes')
    exit()
  ptr[l[i][1]] = l[i][0]
  pos[b[i]] = i

sta, now, cnt = a[0], a[0], 1
while True:
  now = a[pos[ptr[now]]]
  if now == sta:
    break
  cnt += 1
if cnt == n:
  print('No')
else:
  print('Yes')
### BUGGY CODE ###

n = int(input())
 
a = {i+1: list(map(int, input().split())) for i in range(n)}
 
ret = 1
while True:
    pair = []
    for k, v in a.items():
        if a[v[0]][0] == k:
            pair.append(k)
    for p in pair:
        if len(a[p]) > 1:
            a[p] = a[p][1:]
        else:
            a.pop(p)
    if len(a) == 0:
        break
    if len(pair) == 0:
        ret = -1
        break
    ret = ret + 1
 
print(ret)

### FIXED CODE ###

n = int(input())
 
a = {i+1: list(map(int, input().split())) for i in range(n)}
ret = 1
pair = []
keys = a.keys()
while True:
    for k in keys:
        v = a[k][0]
        if a[v][0] == k:
            pair.append(k)
            if v not in keys:
                pair.append(v)
    for p in pair:
        if len(a[p]) > 1:
            a[p] = a[p][1:]
        else:
            a.pop(p)
    if len(a) == 0:
        break
    if len(pair) == 0:
        ret = -1
        break
    ret = ret + 1
    keys = [k for k in pair if k in a]
    pair = []
 
print(ret)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np 

def main():
    H, W = map(int , readline().split())
    A = np.zeros((H+1, W+1), np.int64)
    A[:H, :] = (np.frombuffer(read(H*(W+1)), 'B') == ord('.')).reshape((H, W+1))
    for j in range(H):
        prev = 0
        start = 0
        for i in range(W+1):
            if A[j, i] > 0:
                if prev == 0:
                    start = i 
                    prev = 1
            else:
                if prev == 1:
                    n = i - start
                    for k in range(start, i):
                        A[j, k] = n
                    prev = 0 
    

    for i in range(W):
        prev = 0
        start = 0
        for j in range(H+1):
            if A[j, i] > 0:
                if prev == 0:
                    start = j
                    prev = 1
            else:
                if prev == 1:
                    n = j - start - 1
                    for k in range(start, j):
                        A[k, i] += n
                    prev = 0

    print(A.max())
if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np 
import itertools as it
def main():
    H, W = map(int, readline().split())
    G = np.zeros((H+2, W+2), np.int16)
    G[1:-1, 1:] = (np.frombuffer(read(H*(W+1)), dtype='B') == ord('.')).reshape((H, W+1))
    def solve(G):
        left = np.zeros(G.shape, np.int16)
        for i in range(G.shape[0]):
            left[i, ] = np.arange(G.shape[1])
        left[G>0] = 0
        np.maximum.accumulate(left, out=left, axis=1)

        rG = G[..., ::-1]
        right = np.zeros(G.shape, np.int16)
        for i in range(G.shape[0]): 
            right[i, ] = np.arange(G.shape[1])
        right[rG>0] = 0
        np.maximum.accumulate(right, out=right, axis=1)

        right = G.shape[1] - right[..., ::-1]-1
        scoreres = (right-left-1) 
        scoreres[G==0] = 0
        return scoreres

    print((solve(G)+solve(G.T).T-1).max())
if __name__ == '__main__':
    main()
### BUGGY CODE ###


n,m=map(int, input().split())  
a=list(map(int, input().split()))

for i in range(n):
    a[i]=a[i]%m

count=0
cnt=0

for i in range(n):
    for j in range(i,n):
        cnt=cnt+a[j]
        if cnt%m==0:
            count+=1
    cnt=0
    

print(count)






### FIXED CODE ###

import itertools
import collections

n, m = map(int, input().split())
a=list(map(int,input().split()))
b =[0]+ list(itertools.accumulate(a))
count=0
for i in range(n+1):
    b[i]=b[i]%m

b=collections.Counter(b)
b=b.most_common()

for i in range(len(b)):
    if b[i][1]>=2:
        count+=b[i][1]*(b[i][1]-1)//2
    else:
        break
print(count)
### BUGGY CODE ###

N = int(input())
T =[0]*N
A =[0]*N
Cnt=[1]*N
Cnt_pre =1
for i in range(N):
	T[i],A[i] = map(int,input().split())

for i in range(1,N):
	Cnt_pre = Cnt[i-1]
	while T[i]*Cnt[i]<T[i-1]*Cnt_pre:
		Cnt[i] += 1
	while A[i]*Cnt[i]<A[i-1]*Cnt_pre:
		Cnt[i] += 1
print(Cnt[N-1]*(T[N-1]+A[N-1])) 

### FIXED CODE ###

N = int(input())
T =[0]*N
A =[0]*N
Cnt=[1]*N
Cnt_pre =1
for i in range(N):
	T[i],A[i] = map(int,input().split())

for i in range(1,N):
	Cnt_pre = Cnt[i-1]
	if T[i]<T[i-1]*Cnt_pre:
		if (T[i-1]*Cnt_pre)%T[i]==0:
			Cnt[i] = (T[i-1]*Cnt_pre)//T[i]
		else:Cnt[i]= (T[i-1]*Cnt_pre)//T[i] + 1
	if A[i]*Cnt[i]<A[i-1]*Cnt_pre:
		if (A[i-1]*Cnt_pre)%A[i]==0:
			Cnt[i]=(A[i-1]*Cnt_pre)//A[i]
		else:Cnt[i]=(A[i-1]*Cnt_pre)//A[i]+1
print(Cnt[N-1]*(T[N-1]+A[N-1]))
### BUGGY CODE ###

from numba import njit


@njit(cache=True)
def div(n, d):
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


n = int(input())
arr = [int(float(input()) * 10**9) for _ in range(n)]
arr = [(div(x, 2), div(x, 5)) for x in arr]

ans = 0
for i in range(len(arr)):
    for j in range(i + 1, len(arr)):
        (a, b), (c, d) = arr[i], arr[j]
        if a + c >= 18 and b + d >= 18:
            ans += 1

print(ans)

### FIXED CODE ###

def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())
dp = [[0]*19 for _ in range(19)]

ans = 0
for _ in range(n):
    x = round(float(input()) * pow(10, 9))
    two = div(x, 2)
    five = div(x, 5)
    ans += dp[18 - two][18 - five]
    for i in range(two + 1):
        for j in range(five + 1):
            dp[i][j] += 1

print(ans)
### BUGGY CODE ###

n = int(input())
boss = [0] + list(map(int, input().split()))
#print(boss)
for i in range(n):
    print(boss.count(i+1))
    del boss[0]

### FIXED CODE ###

n = int(input())
dicti = {}
boss = list(map(int, input().split()))
for i in boss:
    if i in dicti:
        dicti[i] += 1
    else:
        dicti[i] = 1
#print(dicti)
for j in range(1,n+1):
    try:
        print(dicti[j])
    except:
        print(0)
### BUGGY CODE ###

n = int(input())
S = input()
cnt = [0] * 1000
for i in range(1000):
    pin = str(i).zfill(3)
    for j in range(n):
        if S[j] == pin[0]:
            p1 = j
            break
    else:
        continue
    for k in range(p1+1, n):
        if S[k] == pin[1]:
            p2 = k
            break
    else:
        continue
    for l in range(p2+1, n):
        if S[l] == pin[2]:
            break
    else:
        continue
    cnt[i] += 1
print(sum(c > 0 for c in cnt))

### FIXED CODE ###

n = int(input())
S = input()
ans = 0
def ok(i):
    pin = '{:0=3}'.format(i)
    j = 0
    for s in S:
        if s == pin[j]:
            j += 1
            if j == 3:
                return True
    else:
        return False

for i in range(1000):
    ans += ok(i)
print(ans)
### BUGGY CODE ###

import bisect,collections,copy,itertools,math,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
N = I()
A = LI()
_123 = [0]*N
_123count = [0]*N
for x in A:
    _123[x-1] += 1
_123copy = copy.copy(_123)
_123copy.sort(reverse=True)
_count = {}
for i,x in enumerate(_123copy):
    if x==0:
        break
    if x==1:
        _123count[i] = 0
    elif i!=0 and _123copy[i]==_123copy[i-1]:
        _123count[i] = _123count[i-1]
    else:
        _123count[i] = math.factorial(x)//((math.factorial(x-2))*(math.factorial(2)))
        _count[x] = _123count[i]
_sum = sum(_123count)
for x in A:
    temp = _123[x-1]-1
    if temp<=0:
        print(_sum)
    elif temp==1:
        print(_sum-1)
    else:
        if (temp+1) in _count:
            tempminus = _count[temp+1]
        else:
            tempminus = math.factorial(temp+1)//((math.factorial(temp-1))*(math.factorial(2)))
            _count[temp+1] = tempminus
        if (temp) in _count:
            tempplus = _count[temp]
        else:
            tempplus = math.factorial(temp)//((math.factorial(temp-2))*(math.factorial(2)))
            _count[temp] = tempplus
        print(_sum-tempminus+tempplus)


### FIXED CODE ###

import bisect,collections,copy,itertools,math,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
N = I()
A = LI()
_123 = [0]*N
_123count = [0]*N
for x in A:
    _123[x-1] += 1
_123copy = copy.copy(_123)
_123copy.sort(reverse=True)
_count = {}
for i,x in enumerate(_123copy):
    if x==0:
        break
    if x==1:
        _123count[i] = 0
    elif i!=0 and _123copy[i]==_123copy[i-1]:
        _123count[i] = _123count[i-1]
    else:
        _123count[i] = math.factorial(x)//((math.factorial(x-2))*(math.factorial(2)))
        _count[x] = _123count[i]
_sum = sum(_123count)
for x in A:
    temp = _123[x-1]-1
    if temp<=0:
        print(_sum)
    elif temp==1:
        print(_sum-1)
    else:
        if (temp+1) in _count:
            tempminus = _count[temp+1]
        else:
            tempminus = math.factorial(temp+1)//((math.factorial(temp-1))*(math.factorial(2)))
            _count[temp+1] = tempminus
        if (temp) in _count:
            tempplus = _count[temp]
        else:
            tempplus = math.factorial(temp)//((math.factorial(temp-2))*(math.factorial(2)))
            _count[temp] = tempplus
        print(_sum-tempminus+tempplus)
### BUGGY CODE ###

s = input()
k = int(input())
strings = []
for start in range(len(s)):
    for end in range(start+1, len(s)+1):
        moji = s[start:end]
        strings.append(moji)

ans = sorted(list(set(strings)))[k-1]
print(ans)

### FIXED CODE ###

s = input()
k = int(input())
strings = set()
for start in range(len(s)):
    for end in range(start+1, start+1+k):
        moji = s[start:end]
        strings.add(moji)

ans = sorted(list(strings))[k-1]
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
h=list(map(int,input().split()))
l=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  l[a-1].append(b)
  l[b-1].append(a)
ans=0
for i in l:
  p=True
  for j in i:
    if h[l.index(i)]<=h[j-1]:
      p=False
      break
  if p:
    ans+=1
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
h=list(map(int,input().split()))
l=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  if h[a-1]<h[b-1] and l[a-1]==0:
    l[a-1]=-1
  elif h[a-1]>h[b-1] and l[b-1]==0:
    l[b-1]=-1
  elif h[a-1]==h[b-1]:
    l[a-1]=-1
    l[b-1]=-1
print(l.count(0))
### BUGGY CODE ###

import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)
N = int(input())
A = list(map(int, input().split()))
RedWine = prod(A)
if RedWine > 1000000000000000000:
    print(-1)
else:
    print(RedWine)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
RedWine = 1
for i in range(N):
    RedWine *= A[i]
    if RedWine > 1000000000000000000:
        break
if RedWine > 1000000000000000000:
    if A.count(0) == 0:
        print(-1)
    else:
        print(0)
else:
    print(RedWine)
### BUGGY CODE ###


def check1(a):
  sum = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        return (i, -abs(sum)-1)
    else:
      sum += a[i]
      if(sum <= 0):
        return (i, abs(sum)+1)
  return True

def check2(a):
  sum = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        return (i, abs(sum)+1)
    else:
      sum += a[i]
      if(sum >= 0):
        return (i, -abs(sum)-1)
  return True



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = 0
ans2 = 0

while(True):
  c = check1(a)
  if(c == True):
    break

  a[c[0]] += c[1]
  ans1 += abs(c[1])


while(True):
  c = check2(a2)
  if(check2(a2) == True):
    break
  a2[c[0]] += c[1]
  ans2 += abs(c[1])


print(ans1) if(ans1<ans2) else print(ans2)

### FIXED CODE ###


def check1(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
    else:
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
  return ans

def check2(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
    else:
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
  return ans



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = check1(a)
ans2 = check2(a2)


print(ans1) if(ans1<ans2) else print(ans2)