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

n = int(input())
a = [int(item) for item in input().split()]

nCk = [0] * (n+2)
for i in range(1,n+2):
    if i == 1:
        nCk[1] = n+1
    else:
        nCk[i] = (nCk[i-1] * (n+1-i+1) // i) # % (10**9 + 7)

index = [-1] * (n+1)
l, r = 0, 0
for i, c in enumerate(a):
    if index[c] == -1:
        index[c] = i
    else:
        l = index[c]
        r = i

nb1Ck = [0] * (n + 2)
nb1Ck[0] = 1
for i in range(1,(n-r+l)+2):
    if i == 1:
        nb1Ck[1] = n-r+l
    else:
        nb1Ck[i] = (nb1Ck[i-1] * ((n-r+l+1)-i) // i) # % (10**9 + 7)

for i in range(1, n+2):
    print((nCk[i] - nb1Ck[i-1])%(10**9 + 7))

### FIXED CODE ###

n = int(input()) + 1
a = [int(item) for item in input().split()]
MOD = 10**9 + 7

def mod_pow(x, n):
    ans = 1
    while(n != 0):
        if n & 1:
            ans = ans * x % MOD
        x = x * x % MOD
        n = n >> 1
    return ans

fac = [1] + [0] * n
inv_fac = [1] + [0] * n
for i in range(1, n+1):
    fac[i] = fac[i-1] * (i) % MOD
    inv_fac[i] = inv_fac[i-1] * mod_pow(i, MOD-2) % MOD

def mod_nCr(n, r):
    if n == 0 and r == 0:
        return 1
    if n < r or n < 0:
        return 0
    tmp = inv_fac[n-r] * inv_fac[r] % MOD
    return tmp * fac[n] % MOD 

index = [-1] * (n+1)
l, r = 0, 0
for i, c in enumerate(a):
    if index[c] == -1:
        index[c] = i
    else:
        l = index[c]
        r = i

for i in range(1, n+1):
    total = mod_nCr(n, i)
    doubled = mod_nCr(n -(r-l) - 1, i-1)
    ans = total - doubled
    if ans < 0:
        ans += MOD
    print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
def main():
    # DFSでやる?
    def rec(now: int, score: int, cnt: int):
        nonlocal ans
        if cnt >= k:
            ans = max(ans, score)
            return
        seen[now] = True
        rec(P[now], score + C[P[now]], cnt + 1)

    N, K = map(int, input().split())
    P = [int(x) - 1 for x in input().split()]
    C = [int(x) for x in input().split()]

    seen = [False] * N
    ans = -(10 ** 9)
    for k in range(1, K + 1):
        for i in range(N):
            rec(i, 0, 0)
    print(ans)
    

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    P = [int(x) - 1 for x in input().split()]
    C = [int(x) for x in input().split()]

    ans = -10 ** 9
    for start in range(N):
        # ループを探す
        now = start
        loop = []
        total = 0
        while now != start or not loop:
            loop.append(C[now])
            now = P[now]
            total += C[now]
        # ループごとの最大スコアを探す
        length = len(loop)
        # sum_loop = sum(loop)
        # # ループ長よりも操作回数が多いか？，ループを周回すると得か？で場合分け
        # res = 0 if sum_loop <= 0 else sum_loop * (K // length)
        # limit = K if K <= length else K % length
        # for k in range(limit):
        #     res += loop[k]
        #     ans = max(ans, res)
        t = 0
        for i in range(length):
            t += loop[i]
            if i + 1 > K:
                break
            now = t
            if total > 0:
                e = (K - (i + 1)) // length
                now += total * e
            ans = max(ans, now)
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import numpy as np
import math
n, m = map(int, input().split())
a = np.array(list(map(int, input().split())))
for i in range(m):
    a[a.argmax()] /= 2
b = np.array([abc // 1 for abc in a])
print(b.sum())

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(a)
for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))
print(-sum(a))
### BUGGY CODE ###

import numpy as np
def ACGT(x):
    if x == "A":
        return 0
    if x == "C":
        return 1
    else:
        return 2

N, Q = map(int, input().split(" "))
S = np.array([ACGT(x) for x in input()])
lr = [[int(j) for j in input().split(" ")] for i in range(Q)]

ind = np.linspace(1,N,N)
posA = np.hstack((np.array([False]), (S == 0)[:-1]))
ind_cand = ind[posA]
posC = (S[posA] == 1)
indAC = ind_cand[posC]

for l, r in lr:
    print(np.sum(((indAC >= l+1) & (indAC <= r))))

### FIXED CODE ###

N, Q = map(int, input().split(" "))
S = input()
t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
    l, r = map(int, input().split(" "))
    print(t[r-1]-t[l-1])
### BUGGY CODE ###

a = int(input())
b = list(map(int,input().split()))
c = []
for val in range(a):
    c.append(5)
for val in range(a):
    c[b[val]-1] = val+1
    d = str()
for val in c:
    d = d + str(val) + " "
d = d.rstrip()
print(d)

### FIXED CODE ###

a = int(input())
b = list(map(int,input().split()))
c = []
for val in range(a):
    c.append(5)
for val in range(a):
    c[b[val]-1] = val+1
d = str()
for val in range(len(c)-1):
    print(c[val], end = ' ')
print(c[-1])
### BUGGY CODE ###

a,b,n=map(int,input().split())
'''
lst=[]
for i in range(n+1):
    now=int(a*i/b)-a*int(i/b)
    lst.append(now)
print(max(lst))
'''
now=0
if n>=b:
    ans=int(a*(n-1)/b)-a*int((n-1)/b)
    ans2=int(a*n/b)-a*int(n/b)
    for i in range(n//b+1):
        ans3=int(a*(i*b-1)/b)-a*int((i*b-1)/b)
        now=max(now,ans3)
    print(max(ans,ans2,now))

else:
    ans=int(a*(n)/b)-a*int((n)/b)
    print(max(ans,0))

### FIXED CODE ###

a,b,n=map(int,input().split())
def ans(x):
    return int(a*x/b)
print(ans(min(n,b-1)))
### BUGGY CODE ###

a,b,k=map(int,input().split())
for i in range(k):
    if a>0:
        a-=1
    else:
        if b>0:
            b-=1
        else:
            break
print(a,b)

### FIXED CODE ###

a,b,k=map(int,input().split())
if k>a and k<a+b:
    k=k-a
    a=0
    b=b-k
elif k<=a:
    a=a-k
else:
    a=0
    b=0
print(a,b)
### BUGGY CODE ###

MAX_NUM = 10**9+1
MOD = 10**9+7

fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]

fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def combinations(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD


def power_func(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

n, a, b = map(int, input().split())

X = combinations(n,a)
Y = combinations(n,b)
Z = power_func(2,n,MOD) - 1
print(Z - X - Y)


### FIXED CODE ###

def binary(n):
    return bin(n)[2:]

def pow_by_binary_exponentiation(a, x, n):  # a^x mod n
    x = [int(b) for b in binary(x)]
    y = a
    for i in range(1, len(x)):
        y = (y**2) % n
        if x[i] == 1:
            y = (y * a) % n
    return y

 # mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


# nCr mod m
# modinvが必要
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9 + 7):
    r = min(r, n - r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i + 1, mod) % mod
    return res
n, a, b = map(int, input().split())


mod = 10**9 + 7
X = combination(n,a)
Y = combination(n,b)
Z = pow_by_binary_exponentiation(2,n,mod) - 1
W = (Z - X - Y) % mod
if W < 0:
    W += mod
print(W % mod)
### BUGGY CODE ###

from itertools import product

N=int(input())
S=input()
t=["0","1","2","3","4","5","6","7","8","9"]

u=product(t,repeat=3)
ans=0
for com in u:
  x_search=True
  y_search=True
  flag=False
  x=com[0]
  y=com[1]
  z=com[2]
    
  for i in range(N):
    if x_search and S[i]==x:
      x_search=False
      for j in range(i+1,N):
        if y_search and S[j]==y:
          y_search=False
          for k in range(j+1,N):
            if S[k]==z:
              flag=True
              break
  if flag:
    ans+=1
print(ans)


### FIXED CODE ###

from itertools import product

N=int(input())
S=list(input())
t=["0","1","2","3","4","5","6","7","8","9"]

u=product(t,repeat=3)
ans=0
for com in u:
  x=com[0]
  y=com[1]
  z=com[2]
  
  if x in set(S):
    idx_x = S.index(x)
    tmp1 = S[idx_x+1:]
    if y in set(tmp1):
      idx_y = tmp1.index(y)
      tmp2 = tmp1[idx_y+1:]
      if z in set(tmp2):
        ans+=1
        continue
        
print(ans)
### BUGGY CODE ###

k,s=map(int,input().split())

count=0
for i in range(k+1):
  for j in range(k+1):
    for k in range(k+1):
      if i+j+k==s:
        count+=1
print(count)

### FIXED CODE ###

k,s=map(int,input().split())

count=0
for i in range(k+1):
  for j in range(k+1):
    if 0<=s-i-j<=k:
      count+=1
      
print(count)
### BUGGY CODE ###

N,M = map(int,input().split())

allhiyatoi = []
for i in range(N):
    temp = list(map(int,input().split()))
    allhiyatoi.append(temp)

allhiyatoi.sort(key=lambda x: x[1], reverse = True)

reward = [0] * (M+1)
remain = list(range(M+1))
for hiya in allhiyatoi:
    if hiya[0]>M:
        continue
    for i in remain:
        if i<hiya[0]:
            continue
        if reward[i] == 0:
            reward[i] = hiya[1]
            remain[i] = -1
            break

print(sum(reward))

### FIXED CODE ###

from heapq import heappush, heappop
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])
 
reward = 0
Q = []
for i in allhiyatoi:
    for j in i:
        heappush(Q,j*-1)
    if len(Q) == 0:
        continue
    reward -= (heappop(Q))

print(reward)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

reached = []
pos = 0#indexで指定
while 1:
    if pos not in reached:
        reached.append(pos)
    else:
        break
    pos = A[pos]-1
#print(reached)

if 1 in reached:
    print(reached.index(1))
else:
    print(-1)

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
INF = 10**6

reached = []
pos = 0#indexで指定
c = 0
while c <= INF:
    reached.append(pos)
    if pos == 1:
        break
    pos = A[pos]-1
    c += 1

if 1 in reached:
    print(reached.index(1))
else:
    print(-1)
### BUGGY CODE ###

import numpy as np
n,k,q=map(int,input().split())
a=[]
ones=np.ones((1,n,))
point=k*ones
de_point=ones
for i in range(q):
    num=int(input())
    de_point[0,num-1]=0
    point=point-de_point
    de_point[0,num-1]=1
for i in range(n):
    if point[0,i]>0:
        print("Yes")
    elif point[0,i]<=0:
        print("No")


### FIXED CODE ###

import numpy as np
n,k,q=map(int,input().split())
a=[]
ones=np.ones((1,n,))
point=k*ones
de_point=-q*ones
for i in range(q):
    num=int(input())
    de_point[0,num-1]=de_point[0,num-1]+1
point=point+de_point
for i in range(n):
    if point[0,i]>0:
        print("Yes")
    elif point[0,i]<=0:
        print("No")
### BUGGY CODE ###

n = int(input())
abc = [tuple(map(int, input().split(" "))) for i in range(3)]

a, b, c = [sorted(abc_i) for abc_i in abc]

sum_num = 0
for b_i in b:
	can_a_count = n
	for i, a_i in enumerate(a):
		if a_i >= b_i:
			can_a_count = i
			break

	can_c_count = n
	for i, c_i in enumerate(c[::-1]):
		if c_i <= b_i:
			can_c_count = i
			break
	
	sum_num += can_a_count * can_c_count

print(sum_num)

### FIXED CODE ###

import bisect

n = int(input())
abc = [tuple(map(int, input().split(" "))) for i in range(3)]
# n = 100000
# abc = [tuple(range(n)) for i in range(3)]

a, b, c = [sorted(abc_i) for abc_i in abc]

print(sum(bisect.bisect_left(a, b_i) * (n-bisect.bisect(c, b_i)) for b_i in b))
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
ans = 0
for v in range(min(A), max(A) + 1):
    count = 0
    for a in A:
        if v - 1 <= a <= v + 1:
            count += 1
    ans = max(count, ans)
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 0
start, end = min(A), max(A) + 1
for v in range(start, end):
    ans = max(C[v - 1] + C[v] + C[v + 1], ans)
print(ans)
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))

L.sort()

def bsearch(array, value):
  left = 0
  right = len(array)
  while left + 1 < right:
    idx = int(left + (right - left) / 2)
    if array[idx] < value:
      left = idx
    else:
      right = idx
  return left

sum = 0
ai = 0
while ai < len(L) - 2:
  bi = ai + 1
  while bi < len(L) - 1:
    a = L[ai]
    b = L[bi]
    i = bsearch(L, a + b)
    sum += (i - bi)

    bi += 1
  ai += 1

print(sum)

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))

L.sort()

def bsearch(array, value):
  left = 0
  right = len(array)
  while left + 1 < right:
    idx = int(left + (right - left) / 2)
    if array[idx] < value:
      left = idx
    else:
      right = idx
  return left

sum = 0
ai = 0
while ai < len(L) - 2:
  bi = ai + 1
  while bi < len(L) - 1:
    a = L[ai]
    b = L[bi]
    i = bsearch(L, a + b)
    sum += (i - bi)

    bi += 1
  ai += 1

print(sum)
### BUGGY CODE ###

import itertools

N = int(input())
s = [list(input()) for i in range(N)]

for ss in s:
  ss.sort()

count = 0

for ss in itertools.combinations(s, 2):
  if ss[0] == ss[1]:
    count += 1

print(count)

### FIXED CODE ###

N = int(input())
s = [list(input()) for i in range(N)]

count = 0
appeared = {}

for ss in s:
  sss = "".join(sorted(ss))
  if sss in appeared.keys():
    count += appeared[sss]
    appeared[sss] += 1
  else:
    appeared[sss] = 1

print(count)
### BUGGY CODE ###

N, W = map(int, input().split())
weight = []
value = []
for i in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(N):
    for j in range(W+1):
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if j - weight[i] >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j-weight[i]]+value[i])
print(dp[N][W])



### FIXED CODE ###

N, W = map(int, input().split())

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
weight = [0]
value = [0]
for i in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)

for i in range(N):
    i += 1
    for sum_w in range(W+1):
        # i 番目の品物を選ぶ場合
        if sum_w >= weight[i]:
            dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w - weight[i]] + value[i])
        # i 番目の品物を選ばない場合
        dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w])

print(dp[N][W])
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N):
    Ai = A[i]
    if Ai >= 2*10**5:
        pass
    else:
        for j in range(i+A[i],N):
            if j-i == Ai+A[j]:
                ans += 1
print(ans)

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = Counter(list(i+1+A[i] for i in range(N)))
#print(B,B[3])
C = Counter((i+1-A[i] for i in range(N)))
ans = 0
#print(C)
for j in range(N):
    ans += B[j]*C[j]
print(ans)
### BUGGY CODE ###

import numpy as np

N = int(input())
S = input()

s = list(S)
s.reverse()
s_bit = np.array([1 if i == 'E' else 0 for i in s])
bit_mask = np.array([pow(2,i) for i in range(N)])
bit = np.dot(s_bit, bit_mask)

global cost_N,min
cost_N = np.zeros(N)
def cost(i):
    global cost_N, min
    if i == 0:
        a = bit & (1 << i)
        b = (pow(2, N) - 1) - (pow(2, i + 1) - 1)
        c = b | a
        bit_cost = bit ^ c
        cost_N[0] = bin(bit_cost).count("1")
        return cost_N[0]
    else:
        cur = s_bit[i]
        bef = s_bit[i-1]
        cost_N[i] = cost(i-1) - (1^cur) + bef
        return cost_N[i]

cost(N-1)
print(int(min(cost_N)))


### FIXED CODE ###

import numpy as np

N = int(input())
S = input()


s = list(S)


s.reverse()
s = np.array([1 if i == 'E' else 0 for i in s])
#str = S.replace('E','1')
#bit_str = str.replace('W','0')
#bit = int(bit_str, base=2)

cost = [0]*N
cost[0] = (N-1) - sum(s[1:N])
for i in range(1,N):
    now = s[i]
    bef = s[i-1]
    cost[i] = cost[i-1] + bef - (1^now)

print(min(cost))
### BUGGY CODE ###

n = int(input())
a = input().split()
b = []
for i in range(n):
  b.append(a[i])
  b = b[::-1]
print(" ".join(b))

### FIXED CODE ###

n = int(input())
a = input().split()
b = []
for i in range(n - 1, -1, -2):
  b.extend([a[i]])
for j in range(n % 2, n, 2):
  b.extend([a[j]])
print(" ".join(b))
### BUGGY CODE ###

inp = input()
cnt = 0

inf = 10 ** 5
for i in range(inf):
  cnt_10 = inp.count('10')
  if cnt_10 > 0:
    cnt += cnt_10 * 2
    inp = inp.replace('10','')

  cnt_01 = inp.count('01')
  if cnt_01 > 0:
    cnt += cnt_01 * 2
    inp = inp.replace('01','')  
  
  if (cnt_01 == 0) & (cnt_10 == 0):
    break

print(cnt)

### FIXED CODE ###

inp = input()

cnt_0 = inp.count('0')
cnt_1 = inp.count('1')

if (cnt_0 == 0) or (cnt_1 == 0):
  print(0)
else:
  print(min(cnt_0,cnt_1) * 2)
### BUGGY CODE ###

N=int(input())
L=list(map(int,input().split()))
LL=list(set([i for i in L if i<N]))

LL=list(set([x+y for x in LL for y in LL]))


cnt=0
for i in range(N):
    X=[(L[i]+L[i+j]==j) for j in LL if j<(N-i)]
    cnt=cnt+sum(X)
print(cnt)

### FIXED CODE ###

def main():
    N=int(input())
    L=list(map(int,input().split()))
    L_i,L_j=[],[]
    L_memo = [0]*N
    cnt=0
    for i, j in enumerate(L):
        if i+j<N:
            L_memo[i+j]+=1
        if i-j>0:
            cnt+=L_memo[i-j]        
    print(cnt)
main()
### BUGGY CODE ###

def main():
  from collections import deque
  s,*c=open(0)
  h,w=map(int,s.split())
  f=[-1]*h*w
  q=deque()
  for i,c in enumerate(''.join(t[:w]for t in c)):
    if c=='#':
      q.append(i)
      f[i]=0
  while q:
    i=q.popleft()
    v=f[i]+1
    j,k,l,m=i+w,i-w,i+1,i-1
    if h*w>j and f[j]<0:
      q.append(j)
      f[j]=v
    if k>=0 and f[k]<0:
      q.append(k)
      f[k]=v
    if w>i%w+1and f[l]<0:
      q.append(l)
      f[l]=v
    if i%w and f[m]<0:
      q.append(m)
      f[m]=v
  print(v-1)
if __name__=='__main__':
  main()

### FIXED CODE ###

from collections import*
h,w=map(int,input().split())
c=eval('list(input()),'*h)
q=deque()
for i in range(h):
    for j in range(w):
        if c[i][j]=='#':
            q.append((i,j,0))
ans=0
while q:
    y,x,v=q.popleft()
    ans=max(ans,v)
    for i,j in((y,x-1),(y,x+1),(y-1,x),(y+1,x)):
        if h>i>=0 and w>j>=0 and c[i][j]=='.':
            c[i][j]='#'
            q.append((i,j,v+1))
print(ans)
### BUGGY CODE ###

s = str(input())
N = len(s)
array = [0]*2019
array[0] += 1
count = 0
for i in reversed(range(0, N)):
    x = s[i:N]
    y = int(x)
    array[y%2019] += 1
for i in array:
    count += i*(i-1)/2
print(int(count))



### FIXED CODE ###

s = str(input())
N = len(s)
array = [0]*2019
array[0] += 1
count = 0
d = 1
r = 0
for i in reversed(range(0, N)):
    #x = s[i:N]
    #y = int(x)
    r = ( r + int( s[i] ) * d ) % 2019
    d = d * 10 % 2019
    array[r] += 1
for i in array:
    count += i*(i-1)/2
print(int(count))
### BUGGY CODE ###

n = int(input())
def factorize(n):
    b = 2
    fct = []
    end = int(n ** (0.5)) + 2
    for b in range(2, end):
      while n % b == 0:
        n //= b
        fct.append(b)
      if n == 1:
        break
    if n > 1:
      fct.append(n)
    return fct
 
fact = factorize(n)
dif = []
from itertools import combinations as com
for i in range((len(fact) + 1) // 2 + 1):
  for cands in com(fact, i):
    ans = 1
    for cand in cands:
      ans *= cand
    dif.append(n//ans + ans - 2)
print(min(dif))

### FIXED CODE ###

n = int(input())

end = int(n**0.5) + 2
dif = []
for i in range(1, end):
  if n % i == 0:
    dif.append(abs(n//i + i) - 2)
print(min(dif))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
q = int(input())
bc = []
for i in range(q):
    bc.append(list(map(int,input().split())))
   
for i in range(q):

    while bc[i][0] in a:
        a[a.index(bc[i][0])] = bc[i][1]
    print(sum(a))

### FIXED CODE ###

from collections import Counter

n = int(input())
a = list(map(int,input().split()))
q = int(input())
freq = Counter(a)
sm = sum(a)
for i in range(q):
    b,c = map(int,input().split())
    bn = freq[b]
    freq[b] = 0
    if c in freq:
        freq[c] += bn
    else:
        freq[c] = bn
    sm = sm + (c-b)*bn
    print(sm)
### BUGGY CODE ###

N = int(raw_input())
A = [int(i) for i in raw_input().split()]

A0 = [A[i] for i in xrange(0, N, 2)]
A1 = [A[i] for i in xrange(1, N, 2)]

Count = 0
S0 = set(A0)
S1 = set(A1)
N0 = []
N1 = []

for s in S0:
    N0.append((s, sum(map(lambda x: x==s, A0))))

for s in S1:
    N1.append((s, sum(map(lambda x: x==s, A1))))

N0.sort(key=lambda x: x[1], reverse=True)
N1.sort(key=lambda x: x[1], reverse=True)

if N0[0][0] == N1[0][0]:
    if N0[0][0] < N1[0][0]:
        if len(N0) == 1:
            print N - N1[0][1]
        else:
            print N - N0[1][1] - N1[0][1]
    else:
        if len(N1) == 1:
            print N - N0[0][1]
        else:
            print N - N0[0][1] - N1[1][1]
else:
    print N - N0[0][1] - N1[0][1]


### FIXED CODE ###


from collections import Counter

n    = int(raw_input())
nums = list(map(int, raw_input().split()))

nums_odd  =   nums[0:n:2]
nums_even =   nums[1:n:2]

N_odd     =   sorted(Counter(nums_odd ).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]
N_even    =   sorted(Counter(nums_even).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]

if N_odd[0][0] == N_even[0][0]:
    if N_odd[0][1] + N_even[1][1] > N_odd[1][1] + N_even[0][1]:
        print n - N_odd[0][1] - N_even[1][1]
    else:
        print n - N_odd[1][1] - N_even[0][1]
else:
    print n - N_odd[0][1] - N_even[0][1]
### BUGGY CODE ###

k = int(input())
x = 7
ans = 1
if k%2 == 0 or k%5 ==0:
  ans = -1
elif 7%k == 0:
  ans = 1
else:
  for i in range (1,k):
    x = x*10+7
    if x%k == 0:
      ans = i+1
      break

print(ans)



### FIXED CODE ###

k = int(input())
x = 7
ans = 1
if k%2 == 0 or k%5 ==0:
  print(-1)
  exit()
elif 7%k == 0:
  ans = 1

else:
  for i in range (1,k):
    x = (x*10+7)%k

    if x%k == 0:
      ans = i+1
      break

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

def main(n,ab,px):
  import sys
  sys.setrecursionlimit(10**7)

  g=[[]for _ in range(n)]
  for a,b in ab:
    g[a-1].append(b-1)
    g[b-1].append(a-1)
  ans=[0]*n
  for p,x in px:
    ans[p-1]+=x
  
  def dfs(seen,i):
    seen[i]=1
    l=g[i]
    for li in [li for li in l if seen[li]==0]:
      ans[li]+=ans[i]
      dfs(seen,li)
  seen=[0]*n
  dfs(seen,0)
  print(' '.join(list(map(str,ans))))

if __name__=='__main__':
  import sys
  input = sys.stdin.readline
  n,q=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in range(n-1)]
  px=[list(map(int,input().split())) for _ in range(q)]
  main(n,ab,px)
  

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
def main():
    n,q=map(int,input().split())
    graph=[[] for _ in range(n+1)]
    ab=[list(map(int,input().split())) for _ in range(n-1)]
    for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
    px=[list(map(int,input().split())) for _ in range(q)]
    seen=[0]*(n+1)
    ans=[0]*(n+1)
    for p,x in px:
        ans[p]+=x
    def dfs(i):
        seen[i]=1
        for li in graph[i]:
            if seen[li]==0:
                ans[li]+=ans[i]
                dfs(li)
    dfs(1)
    print(' '.join(map(str,ans[1:])))
if __name__ == '__main__':
    main()
### BUGGY CODE ###

"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

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

num = 1
for x in a[:]:
    num *= x
    if num == 0:
        break
if 10**18 < num:
    num = -1

print(num)


### FIXED CODE ###

"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

n = int(input())
a = list(map(int,input().split()))
if 0 in a:
    print("0")
else:
    num = 1
    for x in range(n):
        num *= a[x]
        if 10**18 < num:
            num = -1
            break

    print(num)