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

H,W = map(int, input().split())
field = []
bque = []
for i in range(H):
    st = str(input())
    ls = []
    for j,ss in enumerate(st):
        ls.append(ss)
        if ss=='#':
            bque.append([i,j])

    field.append(ls)

from collections import deque

que = deque([])
que.append(bque)
count = 0
while len(que)>0:
    ll = que.popleft()
    nls = []
    for item in ll:
        x = item[0]
        y = item[1]
        for dx in [-1,1]:
            for dy in [-1,1]:
                if 0<=x+dx<=H-1:
                    if field[x+dx][y]=='.':
                        field[x+dx][y]='#'
                        nls.append([x+dx,y])
                if 0<=y+dy<=W-1:
                    if field[x][y+dy]=='.':
                        field[x][y+dy]='#'
                        nls.append([x,y+dy])
    if len(nls) != 0:
        que.append(nls)
        count += 1
print(count)


### FIXED CODE ###

H,W = map(int, input().split())
from sys import stdin
field = []
bque = []
for i in range(H):
    st = stdin.readline()[:-1]
    ls = []
    for j,ss in enumerate(st):
        ls.append(ss)
        if ss=='#':
            bque.append([i,j])

    field.append(ls)

from collections import deque

que = deque([])
que.append(bque)
count = 0
while len(que)>0:
    ll = que.popleft()
    nls = []
    for item in ll:
        x = item[0]
        y = item[1]
        for dx in [-1,1]:
            for dy in [-1,1]:
                if 0<=x+dx<=H-1:
                    if field[x+dx][y]=='.':
                        field[x+dx][y]='#'
                        nls.append([x+dx,y])
                if 0<=y+dy<=W-1:
                    if field[x][y+dy]=='.':
                        field[x][y+dy]='#'
                        nls.append([x,y+dy])
    if len(nls) != 0:
        que.append(nls)
        count += 1
print(count)
"""微妙に遅かった60msぐらい　"""
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    ans = [0] * 63
    
    
    for i in range(63):
        # x0 = len([j for j in range(N) if not (A[j]>>i)&1])
        # x1 = len([j for j in range(N) if (A[j]>>i)&1])
        x0 = 0
        x1 = 0
        for j in range(N):
            if (A[j]>>i)&1:
                x1 += 1
            else:
                x0 += 1

        ans[i] = x0*x1

    x = 0
    for i in range(len(ans)):
        # print(i, 2**i)
        x += pow(2, i) * ans[i] % MOD

    print(x%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    ans = [0] * 60
    
    
    for i in range(60):
        # x0 = len([j for j in range(N) if not (A[j]>>i)&1])
        # x1 = len([j for j in range(N) if (A[j]>>i)&1])
        x0 = 0
        x1 = 0
        for j in range(N):
            if (A[j]>>i)&1:
                x1 += 1
            else:
                x0 += 1

        ans[i] = x0*x1

    x = 0
    for i in range(len(ans)):
        # print(i, 2**i)
        x += pow(2, i) * ans[i] % MOD

    print(x%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

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

S = int(input())
count = 0
l = [0]*2019
l[0] = 1

for i in range(1,len(str(S))+1):
    l[(S%10**i)%2019] += 1

for j in range(2019):
    if l[j] >= 2:
        count += l[j]*(l[j]-1)//2

print(count)


### FIXED CODE ###

S = input()
count = 0
l = [0]*2019
l[0] = 1
mod = 2019
tmp = 0

for i in range(1,len(S)+1):
    tmp = (tmp + int(S[len(S)-i])*pow(10,i-1,mod))%mod
    l[tmp] += 1
    

for j in range(2019):
    if l[j] >= 2:
        count += l[j]*(l[j]-1)//2

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

def GCD(y,x):
    if y>x:
        p,q=y,x
    else:
        p,q=x,y
    if p%q==0:
        return q
    else:
        return GCD(q,p%q)

ans1=0

K=int(input())
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            ans1+=GCD(GCD(i,j),l)

print(ans1)

### FIXED CODE ###

def GCD(y,x):
    if y>x:
        p,q=y,x
    else:
        p,q=x,y
    if p%q==0:
        return q
    else:
        return GCD(q,p%q)

ans1=0
ans2=0
ans3=0
K=int(input())
for i in range(1,K+1):
    for j in range(i+1,K+1):
        for l in range(j+1,K+1):
            ans1+=GCD(GCD(i,j),l)

for i in range(1,K+1):
    for j in range(i+1,K+1):
        ans2+=GCD(i,j)

for i in range(1,K+1):
    ans3+=i
print(ans1*6+ans2*6+ans3)
### BUGGY CODE ###

import math
import random as rd
import numpy as np

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

s=0
for i in range(n//a+1):
    for j in range((n-a*i)//b+1):
        ck=(n-a*i-b*j)
        if ck%c==0 and ck//c>=0:
            s+=1
        # print(i,j,ck,s)

print(s)



### FIXED CODE ###

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

s=0
for i in range(n//a+1):
    for j in range((n-a*i)//b+1):
        ck=(n-a*i-b*j)
        if ck%c==0 and ck//c>=0:
            s+=1
        # print(i,j,ck,s)

print(s)
### BUGGY CODE ###

def splittingplie(n , a):

    ans = 100000000000000

    for i in range(1 , n):
        rldifference = abs(sum(a[:i]) - sum(a[i:]))
        ans = min(ans , rldifference)
    return ans

def main():
    n = int(input())
    a = list(map(int , input().split()))
    print(splittingplie(n , a))

if __name__ == '__main__':
    main()

### FIXED CODE ###

def splittingplie(n , a):

    ans = 10**18
    allsum = int(sum(a))
    asum = 0

    for i in range(n - 1):
        asum += a[i]
        rldifference = abs(allsum - asum*2)
        ans = min(ans , rldifference)

    return ans

def main():
    n = int(input())
    a = list(map(int , input().split()))
    print(splittingplie(n , a))

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

times = int(input())
nums = list(map(int, input().split()))
total = 1

for i in nums:
    total = total * i

if total < 1000000000000000001:
    print(total)
else:
    print(-1)

### FIXED CODE ###

def main():
    n = int(input())
    l = list(map(int, input().split(' ')))
    l.sort()
    if l[0] == 0:
        print(0)
        return
    
    total = 1

    for i in l:
        total = total * i
        if (total > 1000000000000000000):
            print(-1)
            return
    
    print(total)

main()
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import math

def solve(A: int, B: int, N: int):
    print(max([math.floor(A*x/B) - A*math.floor(x/B) for x in range(1, min(B+1, N+1))]))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(A, B, N)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import math

def solve(A: int, B: int, N: int):
    x = min(B-1, N)
    print(math.floor(A*x/B) - A*math.floor(x/B))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(A, B, N)

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

def abc171d_replacing():
    n = int(input())
    a = list(map(int, input().split()))
    a_dict = {}
    for v in a:
        if a_dict.get(v) is None:
            a_dict[v] = 1
        else:
            a_dict[v] += 1
    q = int(input())
    s = []
    for _ in range(q):
        b, c = map(int, input().split())
        if b in a_dict.keys():
            if c in a_dict.keys():
                a_dict[c] += a_dict[b]
            else:
                a_dict[c] = a_dict[b]
            del a_dict[b]
        total = 0
        for k, v in a_dict.items():
            total += k * v
        s.append(total)

    for v in s:
        print(v)

abc171d_replacing()

### FIXED CODE ###

def abc171d_replacing():
    n = int(input())
    a = list(map(int, input().split()))
    a_dict = {}
    for v in a:
        if a_dict.get(v) is None:
            a_dict[v] = 1
        else:
            a_dict[v] += 1
    q = int(input())
    s = []
    total = 0
    for k, v in a_dict.items():
        total += k * v
    for _ in range(q):
        b, c = map(int, input().split())
        if b in a_dict.keys():
            total += (c * a_dict[b] - b * a_dict[b])
            if c in a_dict.keys():
                a_dict[c] += a_dict[b]
            else:
                a_dict[c] = a_dict[b]
            del a_dict[b]
        s.append(total)

    for v in s:
        print(v)


abc171d_replacing()
### BUGGY CODE ###

from collections import deque, defaultdict
import sys
input=sys.stdin.readline


def solve():
    H, W, K = map(int, input().split())
    y1, x1, y2, x2 = map(int, input().split())
    l = [[1 if s=="@" else 0 for s in input()] for _ in range(H)]
    INF = 10**12

    x1 -= 1
    y1 -= 1
    x2 -= 1
    y2 -= 1

    ddy = [0, 0, -1, 1]
    ddx = [-1, 1, 0, 0]

    dist = defaultdict(lambda :INF)
    dist[(y1, x1)] = 0
    q = deque([(y1, x1)])

    while q:
        y, x = q.popleft()
        for dy, dx in zip(ddy, ddx):
            for j in range(1, K+1):
                if not (0<=y+dy*j<H and 0<=x+dx*j<W):
                    break
                if l[y+dy*j][x+dx*j]:
                    break

                if dist[(y+dy*j, x+dx*j)] > dist[(y, x)] + 1:
                    dist[(y+dy*j, x+dx*j)] = dist[(y, x)] + 1
                    q.append((y+dy*j, x+dx*j))


    ans = dist[(y2, x2)]
    print(ans if ans!=INF else -1)


if __name__ == "__main__":
    solve()


### FIXED CODE ###

from collections import deque, defaultdict
import sys
input=sys.stdin.readline


def solve():
    H, W, K = map(int, input().split())
    y1, x1, y2, x2 = map(int, input().split())
    l = [[1 if s=="@" else 0 for s in input()] for _ in range(H)]
    INF = 10**12

    x1 -= 1
    y1 -= 1
    x2 -= 1
    y2 -= 1

    ddy = [0, 0, -1, 1]
    ddx = [-1, 1, 0, 0]

    dist = defaultdict(lambda :INF)
    dist[(y1, x1)] = 0
    q = deque([(y1, x1)])

    while q:
        y, x = q.popleft()
        for dy, dx in zip(ddy, ddx):
            for j in range(1, K+1):
                if not (0<=y+dy*j<H and 0<=x+dx*j<W):
                    break
                if l[y+dy*j][x+dx*j]:
                    break

                if dist[(y+dy*j, x+dx*j)] > dist[(y, x)] + 1:
                    dist[(y+dy*j, x+dx*j)] = dist[(y, x)] + 1
                    q.append((y+dy*j, x+dx*j))
                elif dist[(y+dy*j, x+dx*j)] == dist[(y, x)] + 1:
                    continue
                else:
                    break


    ans = dist[(y2, x2)]
    print(ans if ans!=INF else -1)


if __name__ == "__main__":
    solve()
### BUGGY CODE ###

n = int(input())
s = input()
s = list(map(lambda x: 0 if x == 'W' else 1, s))
ans = 300000
for i in range(n):
    left = s[:i]
    right = s[i+1:]
    ans = min(ans, len(left)-sum(left)+sum(right))

print(ans)


### FIXED CODE ###

n = int(input())
s = input()
s = list(map(lambda x: 0 if x == 'W' else 1, s))
ans = 300000
beright = [0 for i in range(n)]
beleft = [0 for i in range(n)]
for i in range(1, n):
    beright[i] = beright[i-1] + abs(s[i-1] - 1)
    beleft[-i-1] = beleft[-i] + s[-i]

for br, bl in zip(beright, beleft):
    ans = min(ans, br + bl)

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

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

product = 1
for num in A:
    product = product * num
    if product > 10 ** 18:
        product = -1
    if 0 in A:
        product = 0

print(product)

### FIXED CODE ###

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


def ans():
    if 0 in A:
        return print(0)
    product = 1
    for num in A:
        product = product * num
        if product > 10 ** 18:
            return print(-1)

    print(product)


ans()
### BUGGY CODE ###

#create date: 2020-06-29 09:42

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    alist = [0] * (10**5 + 1)
    for ai in a:
        alist[ai] += 1
    q = ni()
    for i in range(q):
        b, c = na()
        alist[c] += alist[b]
        alist[b] = 0
        ans = 0
        
        for i, num in enumerate(alist):
            ans += i*num
        print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

#create date: 2020-06-29 09:42

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    alist = [0] * (10**5 + 1)
    for ai in a:
        alist[ai] += 1
    asum = 0
    for i, num in enumerate(alist):
            asum += i*num

    q = ni()
    for i in range(q):
        b, c = na()
        asum += alist[b] * (c-b)
        alist[c] += alist[b]
        alist[b] = 0
        print(asum)

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

s = input()
ans = []

for i in range(len(s)):
    if s[i] == "A":
        a = i
        for j in range(len(s)):
            if s[j] == "Z":
                z = j+1
                ans.append(len(s[a:z]))
print(max(ans))


### FIXED CODE ###

s = input()

for i in range(len(s)):
    if s[i] == "A":
        a = i
        break
for i in range(len(s)):
    if s[i] == "Z":
        z = i+1

print(len(s[a:z]))
### BUGGY CODE ###

S = input()
Q = int(input())
qry = [input().split() for _ in range(Q)]
A = ''
B = ''
oq = 0
cnt = 0
for q in qry:
    if q[0] == '1':
        cnt += 1
        if oq == '1':
            continue
        A, B = B[::-1], A[::-1]
    else:
        if q[1] == '1':
            A = q[2] + A
        else:
            B += q[2]

if cnt % 2 == 1:
    S = S[::-1]

print(A + S + B)


### FIXED CODE ###

S = input()
Q = int(input())
qry = [input().split() for _ in range(Q)]
A = ''
B = ''
oq = 0
even = True
for q in qry:
    if q[0] == '1':
        even = not even
        if oq == '1':
            continue
    else:
        if even:
            if q[1] == '1':
                A = q[2] + A
            else:
                B += q[2]
        else:
            if q[1] == '1':
                B += q[2]
            else:
                A = q[2] + A
    oq = q

if even:
    print(A+S+B)
else:
    print(B[::-1]+S[::-1]+A[::-1])
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
save = [0]*n
#Ai + i
save = [a[i]+i for i in range(n)]
    
#j-Aj
ans = 0
for j in range(n):
    b = j-a[j]
    if(b<0):
        continue
    ans += save[0:j].count(b)

print(ans)

### FIXED CODE ###

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

#Ai + i 
#j-Aj
ans = 0
cnt = [0]*(n+1)
for i in range(n-1):
    j=i+1
    a = mp[i]+i
    if(a<=n):
        cnt[a] += 1 
    b = j-mp[j]
    if(b<0):
        continue
    ans += cnt[b]
    

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

# -*- coding: utf-8 -*-
import sys
import numpy as np
input = sys.stdin.readline


def main():
    n = int(input())
    l = np.array(list(map(int, input().split())))
    l = np.sort(l)

    result = 0
    # print(l)
    for i in range(n-2):
        for j in range(i + 1, n - 1):
            target = l[j + 1:]
            count = np.count_nonzero(target < (l[i] + l[j]))
            # print(l[i], l[j], target, count)
            result += count

    print(result)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import bisect
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()

    result = 0
    for i in range(n-2):
        for j in range(i + 1, n - 1):
            result += bisect.bisect_left(l, l[i] + l[j]) - (j + 1)

    print(result)


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

N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N-1):
    result = 0
    for j in range(i, N-1):
        if result <= CSF[j][1]:
            result = CSF[j][0] + CSF[j][1]
        else:
            flag = True
            num = CSF[j][1] + CSF[j][2]
            while flag:
                if num >= result:
                    result = num + CSF[j][0]
                    flag = False
                num += CSF[j][2]

    print(result)

print(0)


### FIXED CODE ###

N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N-1):
    result = 0
    for j in range(i, N-1):
        if result <= CSF[j][1]:
            result = CSF[j][0] + CSF[j][1]
        else:
            result = CSF[j][0] + CSF[j][1] + ((-((-(result-CSF[j][1]))//CSF[j][2])) * CSF[j][2])

    print(result)

print(0)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in a:
    ans*=i
if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
i = 0
ans = 1
if 0 in a:
    print(0)
else:
    while ans<10**18 and i < len(a):
        ans*=a[i]
        i+=1
    if ans<=10**18:
        print(ans)
    else:
        print(-1)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
# N = 10**6
# A = [10**6-i for i in range(N)]

def is_pairwise_coprime():
    l = [0]*(10**6+1)
    for a in A:
        for j in range(2, int(a**(1/2))+2):
            if a % j == 0:
                if l[j]:
                    return False
                l[j] = 1
            while a % j == 0:
                a //= j
        if a != 1:
            if l[a]:
                return False
            l[a] = 1
    return True

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(a, b%a)

def is_setwise_coprime():
    A_gcd = A[0]
    for a in A[1:]:
        A_gcd = gcd(A_gcd, a)
        if A_gcd == 1:
            break
    return (A_gcd == 1)

if is_pairwise_coprime():
    print("pairwise coprime")
elif is_setwise_coprime():
    print("setwise coprime")
else:
    print("not coprime")

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
# N = 10**6
# A = [10**6-i for i in range(N)]

def is_pairwise_coprime():
    l = [0]*(10**6+1)
    for a in A:
        for j in range(2, int(a**(1/2))+2):
            if a % j == 0:
                if l[j]:
                    return False
                l[j] = 1
            while a % j == 0:
                a //= j
        if a != 1:
            if l[a]:
                return False
            l[a] = 1
    return True

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(a, b%a)

def is_setwise_coprime():
    A_gcd = A[0]
    for a in A[1:]:
        A_gcd = gcd(A_gcd, a)
        if A_gcd == 1:
            break
    return (A_gcd == 1)

if is_pairwise_coprime():
    print("pairwise coprime")
elif is_setwise_coprime():
    print("setwise coprime")
else:
    print("not coprime")
### BUGGY CODE ###

s = list(str(input()))
a = [0]
b = [0]*2019
b[0] += 1
for num,i in enumerate(reversed(s)):
  a.append(a[num]+int(i)*10**num)
  b[(a[num+1])%2019] += 1
ans = 0
for i in b:
  ans += i*(i-1)//2
print(ans)


### FIXED CODE ###

s = input()
MOD = 2019
a =[0]*MOD
a[0] = 1
c_ = 0
ans = 0
t = 1
for i in reversed(s):
  c = (c_+int(i)*t)%MOD
  a[c] += 1
  t *= 10
  t %= MOD
  c_ = c
for i in a:
  ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
cnt = 0
for i in range(n):
	for j in range(n):
		if i != j and a[i] == a[j]:
			cnt += 1
			break
print(["NO","YES"][cnt==0])

### FIXED CODE ###

n=input();a=list(map(int,input().split()))
print(["YES","NO"][len(set(a))!=len(a)])
### BUGGY CODE ###

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

    mod = 10**9 + 7
    answer = 0

    for i in range(n):
        sum_sub = 0
        for j in range(i+1, n):
            sum_sub += a[j]
            if sum_sub >= mod:
                sum_sub %= mod
        answer += a[i] * sum_sub
        if answer >= mod:
            answer %= mod
    print(answer)


'''
    for i in range(n):
        for j in range(i+1, n):
            answer += a[i] * a[j]
            if answer >= mod:
                answer %= mod
    print(answer)
'''

if __name__ == "__main__":
    main()

### FIXED CODE ###

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

    mod = 10**9 + 7
    answer = 0
    sum_a = sum(a) % mod

    for i in range(n):
        sum_a = sum_a - a[i]
        answer += a[i] * sum_a
        answer %= mod

    print(answer)


'''
    for i in range(n):
        sum_sub = 0
        for j in range(i+1, n):
            sum_sub += a[j]
            if sum_sub >= mod:
                sum_sub %= mod
        answer += a[i] * sum_sub
        if answer >= mod:
            answer %= mod
    print(answer)
'''

'''
    for i in range(n):
        for j in range(i+1, n):
            answer += a[i] * a[j]
            if answer >= mod:
                answer %= mod
    print(answer)
'''

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

n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [-1]*(k+1)
dp[0] = 0

for i in range(1, k+1):
  temp = 1
  for j in range(n):
    if i - l[j] >= 0:
      temp *= dp[i-l[j]]
  dp[i] = 1-temp
      
if dp[k] == 0:
  print('Second')
else:
  print('First')

### FIXED CODE ###

n, k = map(int, input().split())
l = list(map(int, input().split()))

dp = [-1]*(k+1)
dp[0] = 0

for i in range(1, k+1):
  temp = 1
  for j in range(n):
    if i - l[j] >= 0:
      temp *= dp[i-l[j]]
  dp[i] = 1-temp
      
if dp[k] == 0:
  print('Second')
else:
  print('First')
### BUGGY CODE ###

n=int(input())
li=list(map(int,input().split()))
li.sort()
if li[0]==0:
  print(0)
else:
  ans=1
  for i in li:
    ans*=i
    if ans>1000000000000000000:
        ans=-1
    else:
        continue
    
  if ans>1000000000000000000:
      print(-1)
  else:
      print(ans)


### FIXED CODE ###

import sys
n=int(input())
li=list(map(int,input().split()))
li.sort()
if li[0]==0:
  print(0)
  sys.exit()
else:
  ans=1
  for i in li:
    ans*=i
    if ans>1000000000000000000:
        print(-1)
        sys.exit()
    else:
        continue
    
  if ans>1000000000000000000:
      print(-1)
  else:
      print(ans)