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

import heapq
from itertools import accumulate
inf = float('inf')

def dijkstra(ad_lst, n, s):
    costs = [inf for i in range(n+1)]
    costs[s] = 0
    Q = []
    heapq.heappush(Q, [costs[s], s])

    while(Q != []):
        c, u = heapq.heappop(Q)
        for v, c in ad_lst[u]:
            if costs[u] + c < costs[v]:
                alt = costs[u] + c
                heapq.heappush(Q, [alt, v])
                costs[v] = alt

    return costs

n,m,s,t, = map(int, input().split())

route_y = {i: [] for i in range(n+1)}
route_s = {i: [] for i in range(n+1)}
for i in range(m):
    u, v, a, b = map(int, input().split())
    route_y[u].append([v,a])
    route_y[v].append([u,a])
    route_s[u].append([v,b])
    route_s[v].append([u,b])

cost_y = dijkstra(route_y, n, s)
cost_s = dijkstra(route_s, n, t)
result = list(accumulate([y+s for y,s in zip(cost_y, cost_s)][::-1], min))
yen = 10**15
[print(yen-result[i]) for i in range(n-1, -1, -1)]


### FIXED CODE ###

import heapq
from itertools import accumulate
inf = float('inf')

def dijkstra(ad_lst, n, s):
    costs = [inf for i in range(n+1)]
    costs[s], Q = 0, []
    heapq.heappush(Q, [costs[s], s])

    while(Q != []):
        c, u = heapq.heappop(Q)
        for v, c in ad_lst[u].items():
            if costs[u] + c < costs[v]:
                heapq.heappush(Q, [costs[u] + c, v])
                costs[v] = costs[u] + c

    return costs

n,m,s,t, = map(int, input().split())

route_y = {i: {} for i in range(n+1)}
route_s = {i: {} for i in range(n+1)}
for i in range(m):
    u, v, a, b = map(int, input().split())
    route_y[u][v] = a
    route_y[v][u] = a
    route_s[u][v] = b
    route_s[v][u] = b

cost_y = dijkstra(route_y, n, s)
cost_s = dijkstra(route_s, n, t)
result = list(accumulate([y+s for y,s in zip(cost_y, cost_s)][::-1], min))
yen = 10**15
[print(yen-result[i]) for i in range(n-1, -1, -1)]
### BUGGY CODE ###

#13:12
import sys
input = sys.stdin.readline
n,q = map(int,input().split())
event = []
for _ in range(n):
  s,t,x = map(int,input().split())
  event.append((s-x,1,x))
  event.append((t-x,0,x))
event.sort()
t = 0
now = set()
for _ in range(q):
  d = int(input())
  if t == 2*n:
    print(-1)
    continue
  while event[t][0] <= d:
    if event[t][1] == 1:
      now.add(event[t][2])
    else:
      now.remove(event[t][2])
    t += 1
    if t == 2*n:
      break
  try:
    print(min(now))
  except:
    print(-1)

### FIXED CODE ###

#13:12
n,q = map(int,input().split())
import heapq
import sys
input = sys.stdin.readline
event = []
for _ in range(n):
  s,t,x = map(int,input().split())
  heapq.heappush(event,(s-x,t-x,x))
t = 0
now = []
for _ in range(q):
  d = int(input())
  if event:
    while event[0][0] <= d:
      tmp = heapq.heappop(event)
      heapq.heappush(now,(tmp[2],tmp[1]))
      if not event:
        break
  if now:
    while now[0][1] <= d:
      heapq.heappop(now)
      if not now:
        print(-1)
        break
    else:
      print(now[0][0])
  else:
    print(-1)
### BUGGY CODE ###

N = int(input())
sum_digit = 0
while N > 0:
    sum_digit += N % 10
    N //= 10
if sum_digit % 9 == 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N = input()
sum_digit = 0
for i in range(len(N)):
    sum_digit += int(N[i])
if sum_digit % 9 == 0:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###


S = input()
#Slist = list(S)
#A = list(map(int, input().split()))
answer = ()
chinpo = True

while True:
        
    kintama = S.find("RL")

    if (int(kintama) % 2 == 0):
        for i in range(int(kintama)-2):
            print("0")
        print(int(kintama)-1)
        print("0")
        S[int(kintama):]
    else:
        for i in range(int(kintama)-1):
            print("0")
        print(int(kintama)-1)
        S[int(kintama):]


### FIXED CODE ###

import sys
input = sys.stdin.readline

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

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

poi=[]
pon=[]
s=input().rstrip("\n")
for i in range(len(s)-1):
    if s[i:i+2] == "RL":
        poi.append(i)
    if s[i:i+2] == "LR":
        pon.append(i)

r=[]
l=[]
k=0
ans=[0]*len(s)
if pon!=[]:
    for i in range(pon[-1]+1):
        if (poi[k]-i)%2==0:#L
            ans[poi[k]]+=1
        else:
            ans[poi[k]+1]+=1
        #print(ans)
        if i==pon[k]:
            k+=1
    for i in range(pon[-1]+1,len(s)):
        if (poi[k]-i) % 2 == 0:  # L
            ans[poi[k]] += 1
        else:
            ans[poi[k]+1] += 1
else:
    for i in range(len(s)):
        if (poi[k]-i) % 2 == 0:  # L
            ans[poi[k]] += 1
        else:
            ans[poi[k]+1] += 1      
print(*ans)
### BUGGY CODE ###

# 入力
N = int(input())
c = [0]*4
for a in input().split():
    c[int(a)] += 1

# DPテーブルを初期化
dp = [[[-1 for k in range(310)] for j in range(310)] for i in range(310)]
dp[0][0][0] = 0


for k in range(0, c[3] + 1):
    for j in range(0, c[2]+c[3]-k + 1):
        for i in range(0, c[1]+c[2]+c[3]-j-k + 1):
            if i == j == k == 0:
                continue
            dp[i][j][k] = (N+i*dp[i - 1][j][k]+j *
                           dp[i + 1][j - 1][k]+k*dp[i][j + 1][k - 1])/(i+j+k)


# 答えを得て出力
print(dp[c[1]][c[2]][c[3]])


### FIXED CODE ###

import collections

# 入力
N = int(input())
c = collections.Counter(list(map(int, input().split())))

# DPテーブルを初期化
dp = [[[0.0 for k in range(310)] for j in range(310)] for i in range(310)]


for k in range(0, c[3] + 1):
    for j in range(0, c[2]+c[3]-k + 1):
        for i in range(0, c[1]+c[2]+c[3]-j-k + 1):
            if i == j == k == 0:
                continue
            dp[i][j][k] = (N+i*dp[i - 1][j][k]+j *
                           dp[i + 1][j - 1][k]+k*dp[i][j + 1][k - 1])/(i+j+k)


# 答えを得て出力
print(dp[c[1]][c[2]][c[3]])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N,W = [int(i) for i in input().split()]
weight = [0] * N
value= [0] * N
for i in range(N) :
    w,v = [int(i) for i in input().split()]
    value[i] = v
    weight[i] = w
dp = [[0] * (W+1) for _ in range(N+1)]
for i in range(N):
    for w in range(W+1) :
        if w >= weight[i] :
            dp[i+1][w] = max(dp[i][w-weight[i]]+value[i],dp[i][w])
        else :
            dp[i+1][w] = dp[i][w]
print(dp[N][W])

### FIXED CODE ###

import sys
input = sys.stdin.readline
import numpy as np
N, W = map(int, input().split())
w, v = [], []
for i in range(N):
    a, b = map(int, input().split())
    w += [a]
    v += [b]

DP = np.zeros(W+1, dtype=int)
# i 円以下で買える商品の最大価値
for i in range(N):
    DP[w[i]:] = np.maximum(DP[:-w[i]]+ v[i], DP[w[i]:])
print(DP[-1])
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cta=[0]*(n)
ctb=[0]*(n)
for i in range(n):
  cta[a[i]-1]+=1
  ctb[b[i]-1]+=1

for i in range(n):
  if cta[i]+ctb[i]>n:
    print('No')
    exit()

sa=[0]
sb=[0]
for i in range(n):
  sa.append(cta[i]+sa[-1])
  sb.append(ctb[i]+sb[-1])
l=[]
for i in range(n):
  l.append(sa[i+1]-sb[i])
ans=[]
for i in range(n):
  ans.append(str(b[(i-max(l))%n]))
print('Yes')
print(' '.join(ans))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cta=[0]*n
ctb=[0]*n
for i in range(n):
  cta[a[i]-1]+=1
  ctb[b[i]-1]+=1

for i in range(n):
  if cta[i]+ctb[i]>n:
    print('No')
    exit()

sa=[0]
sb=[0]
for i in range(n):
  sa.append(cta[i]+sa[-1])
  sb.append(ctb[i]+sb[-1])
l=[]
for i in range(n):
  l.append(sa[i+1]-sb[i])
ans=[]
maxl=max(l)
for i in range(n):
  ans.append(str(b[(i-maxl)%n]))
print('Yes')
print(' '.join(ans))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()
ans=1

for i in arr:
    ans*=i
if ans<=10**18:
    print(ans)
else:
    print(-1)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()
ans=1

if 0 in arr:
    print(0)
    exit()

for i in arr:
    ans*=i
    if ans>10**18:
        print(-1)
        exit()
if ans<=10**18:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
ans = 1
flag = 0
zeroflag = 0
for a in A:
    ans *= a
    if ans > pow(10, 18):
        flag = 1
    if a == 0:
        zeroflag = 1
if flag:
    ans = -1
if zeroflag:
    ans = 0
print(ans if ans <= pow(10, 18) else -1)


### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
ans = 1
flag = 0
zeroflag = 0
for a in A:
    if a == 0:
        print(0)
        exit()
for a in A:
    ans *= a
    if ans > pow(10, 18):
        print(-1)
        exit()
print(ans)
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

H, W, K = mapint()
y1, x1, y2, x2 = mapint()
pond = [list(input()) for _ in range(H)]
from collections import deque
Q = deque([(y1-1, x1-1)])

inf = 10**18
dist = [[inf]*W for _ in range(H)]
dist[y1-1][x1-1] = 0
while Q:
    y, x = Q.popleft()
    if y==y2-1 and x==x2-1:
        break
    for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        for i in range(1, K+1):
            ny, nx = y+dy*i, x+dx*i
            if ny<0 or ny>=H or nx<0 or nx>=W:
                break
            if pond[ny][nx]=='@':
                break
            if dist[ny][nx]<dist[y][x]:
                break
            if dist[ny][nx]>dist[y][x]+1:
                dist[ny][nx] = dist[y][x]+1
                Q.append((ny, nx))
if dist[y2-1][x2-1]>=10**17:
    print(-1)
else:
    print(dist[y2-1][x2-1])

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from collections import deque
inf = 10**18
H, W, K = mapint()
y1, x1, y2, x2 = mapint()
query = [list(str(input())) for _ in range(H)]
dirc = [(0, 1), (-1, 0), (0, -1), (1, 0)]

checked = [[-1]*W for _ in range(H)]
checked[y1-1][x1-1] = 0

queue = deque([(y1-1, x1-1)])
def bfs(queue):
    while queue:
        y, x = queue.popleft()
        if y==y2-1 and x==x2-1:
            return checked[y][x]
        for dy, dx in dirc:
            for i in range(1, K+1):
                ny, nx = y+(dy*i), x+(dx*i)
                if ny>=H or ny<0 or nx>=W or nx<0:
                    continue
                if query[ny][nx]=='@':
                    break
                if checked[ny][nx]<0:
                    checked[ny][nx] = checked[y][x]+1
                    queue.append((ny, nx))
                elif checked[ny][nx]<=checked[y][x]:
                    break
    return -1

print(bfs(queue))
### BUGGY CODE ###

import copy
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

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

ans = 0
for i in range(N):
    tmp = copy.copy(A)
    tmp.pop(i)
    ans = max(ans, gcd(*tmp))

print(ans)

### FIXED CODE ###

def gcd(x, y):
    while y != 0:
        x, y = y, x%y
    return x

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

L = [0]*(N+1)
R = [0]*(N+1)
for i in range(1, N+1):
    L[i] = gcd(L[i-1], A[i-1])
    R[N-i] = gcd(R[N-i+1], A[N-i])

ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i],R[i+1]))

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

mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b=mi()
l=list(mi())
dp=[sys.maxsize]*a
dp[0]=0
for i in range(1,a):
  for j in range(min(i,b)):
    dp[i]=min(dp[i],abs(l[i]-l[i-j-1])+dp[i-j-1])
print(dp[-1])

### FIXED CODE ###

mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b=mi()
l=list(mi())
dp=[sys.maxsize]*a
dp[0]=0
for i in range(1,a):
  for j in range(min(i,b)):
    dp[i]=min(dp[i],abs(l[i]-l[i-j-1])+dp[i-j-1])
print(dp[-1])
### BUGGY CODE ###

from collections import deque
import heapq
H, W, M = map(int, input().split())
bomb = []
heapq.heapify(bomb)
counth = deque([0 for k in range(H)])
countw = deque([0 for k in range(W)])
for k in range(M):
  h, w = map(int, input().split())
  h -= 1
  w -= 1
  heapq.heappush(bomb, h+ w*H)
  counth[h] += 1 
  countw[w] += 1

maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = []
k = 0
while k < H:
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)
  k += 1
k = 0
while k < W:
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)
  k += 1
ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)

if lenh*lenw > M:
  ans += 1
else:
  kouho = []
  heapq.heapify(kouho)
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      heapq.heappush(kouho, h+ H*w)
  B = heapq.heappop(bomb)
  K = heapq.heappop(kouho)
  while True:
    if B > K:
      ans += 1
      break
    elif B == K:
      if len(kouho) == 0:
        break
      else:
        K = heapq.heappop(kouho)
    else:
      if len(bomb) == 0:
        ans += 1
        break
      else:
        B = heapq.heappop(bomb)
print(ans)



### FIXED CODE ###

from collections import deque
H, W, M = map(int, input().split())
bomb = []
counth = [0 for k in range(H)]
countw = [0 for k in range(W)]
for k in range(M):
  h, w = map(int, input().split())
  h -= 1
  w -= 1
  bomb.append(h+ w*H)
  counth[h] += 1 
  countw[w] += 1
counth = deque(counth)
countw = deque(countw)

def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            #return mid
            return True
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    #return None
    return False


maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = []
for k in range(H):
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)

for k in range(W):
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)

ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)


if lenh*lenw > M:
  ans += 1
else:
  bomb.sort()
  kouho = []
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      kouho.append(h+ H*w)
  for K in kouho:
    if binary_search(bomb, K):
      continue
    else:
      ans += 1
      break
    
print(ans)
### BUGGY CODE ###

N = int(input())
A = [int(a) for a in input().split()]

ans = 0
maxh = A[-1]

while 1:
    complete = True
    for i in range(1, len(A))[::-1]:
        if A[i-1] > A[i]:
            diff = A[i-1] - A[i]
            ans += diff
            A[i] += diff
            complete = False
    if complete:
        break

print(ans)

### FIXED CODE ###

N = int(input())
A = [int(a) for a in input().split()]

ans = 0

for i in range(len(A)-1):
    if A[i] > A[i+1]:
        diff = A[i] - A[i+1]
        A[i+1] += diff
        ans += diff

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

# Problem D - Line++

# input
N, X, Y = map(int, input().split())

# initialization
graph = [[float('INF')]*(N+1) for i in range(N+1)]
for i in range(1, N):
    graph[i][i+1] = 1
graph[X][Y] = 1
kyori = [0]*N

# dp
for i in range(1, N):
    for j in range(i+1, N+1):
        if j<=X:
            graph[i][j] = min(graph[i][j], abs(j - i))
        else:
            graph[i][j] = min(graph[i][j], abs(j - i), abs(X - i)+1+abs(j - Y))

# kyori count
for i in range(1, N+1):
    for j in range(i+1, N+1):
        if not graph[i][j]==float('INF'):
            kyori[graph[i][j]] += 1

# output
for i in range(1, N):
    print(kyori[i])


### FIXED CODE ###

# Problem D - Line++

# input
N, X, Y = map(int, input().split())

# initialization
INF = N
kyori_graph = [[INF]*N for i in range(N)]
kosu_list = [0]*(N-1)
for i in range(N):
    for j in range(i+1, N):
        if j==i+1:
            kyori_graph[i][j] = 1
        else:
            kyori_graph[i][j] = INF
kyori_graph[X-1][Y-1] = 1

# graph search
for i in range(N):
    for j in range(i+1, N):
        # グラフの更新
        kyori_graph[i][j] = min(abs(j-i), abs(X-1-i)+1+abs(j-(Y-1)), abs((Y-1)-i)+1+abs(j-(X-1)))

# 個数の数え上げ
for i in range(N):
    for j in range(i+1, N):
        kyori = kyori_graph[i][j]
        kosu_list[kyori-1] += 1

# output
for k in kosu_list:
    print(k)
### BUGGY CODE ###

def resolve():
    import sys
    input = sys.stdin.readline
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    p1 = list(map(lambda x: (x+1)/2, p))
    ans = 0
    if k==1:
        print(max(p1))
        exit()
    else:
        for i in range(n-k+1):
            cal = sum(p1[i:i+k])
            if ans <= cal:
                ans = cal
    print(ans)
resolve()

### FIXED CODE ###

def resolve():
    import sys
    input = sys.stdin.readline
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    p1 = list(map(lambda x: (x+1)/2, p))
    ans = 0
    if k==1:
        print(max(p1))
        exit()
    else:
        initial = sum(p1[0:k])
        if ans <= initial:
            ans = initial
            cal = initial
        for i in range(n-k):
            cal = cal-p1[i]+p1[i+k]
            if ans <= cal:
                ans = cal
    print(ans)
resolve()
### BUGGY CODE ###

import sys
 
x = int(input())
 
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
 
    # divisors.sort()
    return divisors
 
 
for i in range(len(make_divisors(x))):
    for j in range(150):
        if j ** 5 - (j - make_divisors(x)[i]) ** 5 == x:
            print(j, j - make_divisors(x)[i])
            sys.exit()

### FIXED CODE ###

import sys
 
x = int(input())
 
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
 
    # divisors.sort()
    return divisors
 
 
for i in range(len(make_divisors(x))):
    for j in range(130):
        if j ** 5 - (j - make_divisors(x)[i]) ** 5 == x:
            print(j, j - make_divisors(x)[i])
            sys.exit()
### BUGGY CODE ###

import math
from collections import deque
from collections import defaultdict

import time

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n = readInt()
a = readInts()

ans = 1

if 0 in a:
	print(0)
	exit()

for i in a:
	ans*=i

if ans>10**18:
	print(-1)
else:
	print(ans)

### FIXED CODE ###

import math
from collections import deque
from collections import defaultdict


#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))


n = readInt()
a = readInts()

ans = 1

d = defaultdict(int)

if 0 in a:
	print(0)
	exit()

for i in a:
	d[i]+=1

for k in d:
	ans*=k**d[k]
	if ans>10**18:
		print(-1)
		exit()

else:
	print(ans)