Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(n):
  if a[i] in dic:
    dic[a[i]]+=1
  else:
    dic[a[i]]=1
q=int(input())
for i in range(q):
  b,c=map(int,input().split())
  if b in dic:
    if c in dic:
      dic[c]+=dic[b]
      del dic[b]
    else:
      dic[c]=dic[b]
      del dic[b]
  ans=0
  for key,value in dic.items():
    ans+=key*value
  print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(n):
  if a[i] in dic:
    dic[a[i]]+=1
  else:
    dic[a[i]]=1
q=int(input())
ans=0
for key,value in dic.items():
  ans+=key*value
for i in range(q):
  b,c=map(int,input().split())
  if b in dic:
    if c in dic:
      dic[c]+=dic[b]
      ans+=dic[b]*(c-b)
      del dic[b]
    else:
      dic[c]=dic[b]
      ans+=dic[b]*(c-b)
      del dic[b]
  print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
dic={}
wk=1
start=0
for i in range(1,n+1):
  wk=a[wk-1]
  if wk in dic:
    start=dic[wk]
    break
  dic[wk]=i
end=len(dic)
loopcnt=end-start+1
keys=list(dic.keys())
if k<start:
  print(keys[k-1])
else:
  chk=(k-start+1)%loopcntac
  if chk==0:
    chk=loopcnt
  print(keys[(start-1)+chk-1])


Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dic={}
wk=1
start=0
for i in range(1,n+1):
  wk=a[wk-1]
  if wk in dic:
    start=dic[wk]
    break
  dic[wk]=i
end=len(dic)
loopcnt=end-start+1
keys=list(dic.keys())
if k<start:
  print(keys[k-1])
else:
  chk=(k-start+1)%loopcnt
  if chk==0:
    chk=loopcnt
  print(keys[(start-1)+chk-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for i in range(q)]
ans=0
for i in range(1<<q):
  A=[1]*n
  arrj=[]
  sumd=0
  hantei=True
  for j in range(q):
    if ((i>>j)&1):
      a,b,c,d=abcd[j][0],abcd[j][1],abcd[j][2],abcd[j][3]
      if A[a-1]!=1 and A[b-1]!=1:
        if A[b-1]-A[a-1]!=c:
          hantei=False
          break
      elif A[a-1]==1 and A[b-1]!=1:
        A[a-1]=A[b-1]-c
        if A[a-1]<1:
          hantei=False
          break
      else:
        A[b-1]=A[a-1]+c
        if A[b-1]>m:
          hantei=False
          break
      sumd+=d
      arrj.append(j)
  if hantei:
    for j in arrj:
      a,b,c,d=abcd[j][0],abcd[j][1],abcd[j][2],abcd[j][3]
      if A[b-1]-A[a-1]!=c:
        hantei=False
        break
  if hantei:
    for j in range(n-1):
      if A[j]>A[j+1]:
        hantei=False
        break
  if hantei and sumd>ans:
    ans=sumd
print(ans)

Fixed submission:
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for i in range(q)]
ans=0

def calc(arr):
  score=0
  for a,b,c,d in abcd:
    if arr[b-1]-arr[a-1]==c:
      score+=d
  return score

def dfs(arr, i):
  global ans
  if len(arr)==n:
    ans=max(ans,calc(arr))
    return
  for j in range(i,m+1):
    arr.append(j)
    dfs(arr, j)
    arr.pop()
dfs([], 1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,q=map(int,input().split())
abcd=[]
for i in range(q):
  abcd.append(list(map(int,input().split())))
ans=0
for i in range(1<<q):
  A=[1]*n
  sumd=0
  hantei=True
  for j in range(q):
    if ((i>>j)&1):
      a,b,c,d=abcd[j][0],abcd[j][1],abcd[j][2],abcd[j][3]
      if A[a-1]!=1 and A[b-1]!=1:
        if A[b-1]-A[a-1]!=c:
          hantei=False
          break
      elif A[a-1]==1 and A[b-1]!=1:
        A[a-1]=A[b-1]-c
        if A[a-1]<1:
          hantei=False
          break
      else:
        A[b-1]=A[a-1]+c
        if A[b-1]>m:
          hantei=False
          break
      sumd+=d
  if hantei:
    for j in range(q):
      if ((i>>j)&1):
        a,b,c,d=abcd[j][0],abcd[j][1],abcd[j][2],abcd[j][3]
        if A[b-1]-A[a-1]!=c:
          hantei=False
          break
  if hantei:
    for j in range(n-1):
      if A[j]>A[j+1]:
        hantei=False
        break
  if hantei and sumd>ans:
    ans=sumd
print(ans)

     
      

Fixed submission:
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for i in range(q)]
ans=0

def calc(arr):
  score=0
  for a,b,c,d in abcd:
    if arr[b-1]-arr[a-1]==c:
      score+=d
  return score

def dfs(arr, i):
  global ans
  if len(arr)==n:
    ans=max(ans,calc(arr))
    return
  for j in range(i,m+1):
    arr.append(j)
    dfs(arr, j)
    arr.pop()
dfs([], 1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[]
for i in range(n):
  a=input()
  if not a in s:
    s.append(a)
print(len(s))

Fixed submission:
n=int(input())
s=set()
for i in range(n):
  s.add(input())
print(len(s))
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
ans=0
for i in range(4,len(s)+1):
  for j in range(len(s)-i+1):
    if(int(s[j:j+i])%2019==0):
      ans+=1
print(ans)

Fixed submission:
s=input()
tmp,mod,n,ans=0,2019,len(s),0
dic={0:1}
for i in range(len(s)):
  tmp=(tmp+int(s[i])*pow(10,n-i-1,mod))%mod
  if tmp in dic.keys():
    dic[tmp]+=1
  else:
    dic[tmp]=1
for i in dic.items():
  ans+=(i[1]*(i[1]-1))//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for h in range(1,k+1):
      ans+=math.gcd(math.gcd(i,j),h)
print(ans)

Fixed submission:
import math
k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    tmp=math.gcd(i,j)
    for h in range(1,k+1):
      ans+=math.gcd(tmp,h)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x,y):
  while y>0:
    bk=x%y
    x=y
    y=bk
  return x

k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for h in range(1,k+1):
      ans+=gcd(gcd(i,j),h)
print(ans)

Fixed submission:
import math
k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    tmp=math.gcd(i,j)
    for h in range(1,k+1):
      ans+=math.gcd(tmp,h)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for h in range(1,k+1):
      p=i
      q=j
      r=h
      while q>=1:
        bk=p%q
        p=q
        q=bk
      while p>=1:
        bk=r%p
        r=p
        p=bk
      ans+=r
print(ans)

Fixed submission:
import math
k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    tmp=math.gcd(i,j)
    for h in range(1,k+1):
      ans+=math.gcd(tmp,h)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
r,g,b=[],[],[]
ans=0
for i in range(n):
  if s[i]=="R":
    r.append(i)
  elif s[i]=="G":
    g.append(i)
  elif s[i]=="B":
    b.append(i)
for i in range(len(r)):
  for j in range(len(g)):
    l=[r[i],g[j],b[2*j-i]]
    l.sort()
    if l[1]-l[0]!=l[2]-l[1]:
      ans+=1
print(ans)  

Fixed submission:
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
for i in range(n):
  for j in range(i+1,n):
    if 2*j-i<n:
      if s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
        ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
r,g,b=[],[],[]
ans=0
for i in range(n):
  if s[i]=="R":
    r.append(i)
  elif s[i]=="G":
    g.append(i)
  elif s[i]=="B":
    b.append(i)
for i in range(len(r)):
  for j in range(len(g)):
    for k in range(len(b)):
      l=[r[i],g[j],b[k]]
      l.sort()
      if l[1]-l[0]!=l[2]-l[1]:
        ans+=1
print(ans)  

Fixed submission:
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
for i in range(n):
  for j in range(i+1,n):
    if 2*j-i<n:
      if s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
        ans-=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      a,b,c=l[i],l[j],l[k]
      if abs(a-b)<c<a+b:
        ans+=1
print(ans)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n):
  k=i
  for j in range(i+1,n):
    while k<n and l[k]<l[i]+l[j]:
      k+=1
    ans+=k-(j+1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      a,b,c=l[i],l[j],l[k]
      if a<b+c and b<c+a and c<a+b:
        ans+=1
print(ans)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n):
  k=i
  for j in range(i+1,n):
    while k<n and l[k]<l[i]+l[j]:
      k+=1
    ans+=k-(j+1)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
ans="Yes"
cngh=0
bkh=0
for i in range(n):
  if bkh>h[i]:
    if cngh!=h[i-1]:
      if bkh-1==h[i]:
      	cngh=h[i]
      else:
        ans="No"
        break
    else:
      if cngh!=h[i]:
        ans="No"
        break
  bkh=h[i]
print(ans)

Fixed submission:
a,b,c=map(int,input().split())
print(0 if c-(a-b)<0 else c-(a-b))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[0]*n
for i in range(n):
  a[i]=int(input())
for i in range(n):
  wk=a.copy()
  wk.pop(i)
  print(max(wk))

Fixed submission:
n=int(input())
a={}
maxkey=0
maxindex=0
bkmaxkey=0
for i in range(n):
  key=int(input())
  if key in a:
    a[key]+=1
  else:
    a[key]=1
  if maxkey<key:
    if bkmaxkey!=0:
      bkmaxkey=maxkey
    maxkey=key
    maxindex=i
if a[maxkey]>1:
  for i in range(n):
    print(maxkey)
else:
  for i in range(n):
    if i==maxindex:
      a.pop(maxkey)
      print(max(a))
    else:
      print(maxkey)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
dic={}
for i in range(m):
  b,c=map(int,input().split())
  if c in dic:
    dic[c]+=b
  else:
    dic[c]=b
ol=sorted(dic.items(), reverse=True, key=lambda x:x[0])
index=0
loopstop=False
for li in ol:
  for i in range(li[1]):
    if li[0]>a[index]:
      a[index]=li[0]
      index+=1
    else:
      loopstop=True
      break;
  if loopstop or index>=n :
    break
print(sum(a))

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
dic={}
for i in range(m):
  b,c=map(int,input().split())
  if c in dic:
    dic[c]+=b
  else:
    dic[c]=b
ol=sorted(dic.items(), reverse=True, key=lambda x:x[0])
index=0
loopstop=False
for li in ol:
  for i in range(li[1]):
    if li[0]>a[index]:
      a[index]=li[0]
      index+=1
      if index>=n:
        loopstop=True
        break;
    else:
      loopstop=True
      break;
  if loopstop:
    break
print(sum(a))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
dic={}
for i in range(m):
  b,c=map(int,input().split())
  if c in dic:
    dic[c]+=b
  else:
    dic[c]=b
ol=sorted(dic.items(), reverse=True, key=lambda x:x[0])
index=0
loopstop=False
for li in ol:
  for i in range(li[1]):
    if li[0]>a[index]:
      a[index]=li[0]
      index+=1
    else:
      loopstop=True
      break;
  if loopstop:
    break
print(sum(a))

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
dic={}
for i in range(m):
  b,c=map(int,input().split())
  if c in dic:
    dic[c]+=b
  else:
    dic[c]=b
ol=sorted(dic.items(), reverse=True, key=lambda x:x[0])
index=0
loopstop=False
for li in ol:
  for i in range(li[1]):
    if li[0]>a[index]:
      a[index]=li[0]
      index+=1
      if index>=n:
        loopstop=True
        break;
    else:
      loopstop=True
      break;
  if loopstop:
    break
print(sum(a))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
for i in range(m):
  b,c=map(int,input().split())
  chk=False
  for j in range(b):
    if a[j]<c:
      a[j]=c
      chk=True
    else:
      break
  j+=1
  if chk:
    for k in range(j,n):
      if a[k]>c:
        break
    a=a[j:k]+a[0:j]+a[k:n] 
print(sum(a))

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
dic={}
for i in range(m):
  b,c=map(int,input().split())
  if c in dic:
    dic[c]+=b
  else:
    dic[c]=b
ol=sorted(dic.items(), reverse=True, key=lambda x:x[0])
index=0
loopstop=False
for li in ol:
  for i in range(li[1]):
    if li[0]>a[index]:
      a[index]=li[0]
      index+=1
      if index>=n:
        loopstop=True
        break;
    else:
      loopstop=True
      break;
  if loopstop:
    break
print(sum(a))
Buggy python submission (verdict: Runtime Error):
from numba import jit
@jit
n,k=map(int,input().split())
h=list(map(int,input().split()))
cost=[0]
for i in range(1,n):
  wk=[]
  for j in range(1,min(k,i)+1):
    wk.append(cost[i-j]+abs(h[i]-h[i-j]))
  cost.append(min(wk))
print(cost[n-1])

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
cost=[0,abs(h[1]-h[0])]
for i in range(2,n):
  cost.append(min(cost[i-2]+abs(h[i]-h[i-2]),cost[i-1]+abs(h[i]-h[i-1])))
print(cost[n-1])
Buggy python submission (verdict: Runtime Error):
from numba import jit
@jit
n,k=map(int,input().split())
h=list(map(int,input().split()))
cost=[0]
for i in range(1,n):
  wk=[]
  for j in range(1,min(k,i)+1):
    wk.append(cost[i-j]+abs(h[i]-h[i-j]))
  cost.append(min(wk))
print(cost[n-1])

Fixed submission:
from numba import jit
n,k=map(int,input().split())
h=list(map(int,input().split()))
@jit
def jitcalc(n,k,h):
  cost=[0]
  for i in range(1,n):
    wk=[]
    for j in range(1,min(k,i)+1):
      wk.append(cost[i-j]+abs(h[i]-h[i-j]))
    cost.append(min(wk))
  print(cost[n-1])
jitcalc(n,k,h)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
cost=[0]
for i in range(1,n):
  wk=[]
  for j in range(1,min(k,i)+1):
    wk.append(cost[i-j]+abs(h[i]-h[i-j]))
  cost.append(min(wk))
print(cost[n-1])

Fixed submission:
from numba import jit
n,k=map(int,input().split())
h=list(map(int,input().split()))
@jit
def jitcalc(n,k,h):
  cost=[0]
  for i in range(1,n):
    wk=[]
    for j in range(1,min(k,i)+1):
      wk.append(cost[i-j]+abs(h[i]-h[i-j]))
    cost.append(min(wk))
  print(cost[n-1])
jitcalc(n,k,h)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
cost=[0]
for i in range(1,n):
  wk=-1
  for j in range(1,min(i,k)+1):
    if wk==-1:
      wk=cost[i-j]+abs(h[i]-h[i-j])
    else:
      wk=min(wk,cost[i-j]+abs(h[i]-h[i-j]))
  cost.append(wk)
print(cost[n-1])

Fixed submission:
from numba import jit
n,k=map(int,input().split())
h=list(map(int,input().split()))
@jit
def jitcalc(n,k,h):
  cost=[0]
  for i in range(1,n):
    wk=[]
    for j in range(1,min(k,i)+1):
      wk.append(cost[i-j]+abs(h[i]-h[i-j]))
    cost.append(min(wk))
  print(cost[n-1])
jitcalc(n,k,h)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
cost=[0]
for i in range(1,n):
  wk=[]
  for j in range(1,min(i,k)+1):
    wk.append(cost[i-j]+abs(h[i]-h[i-j]))
  cost.append(min(wk))
print(cost[n-1])

Fixed submission:
from numba import jit
n,k=map(int,input().split())
h=list(map(int,input().split()))
@jit
def jitcalc(n,k,h):
  cost=[0]
  for i in range(1,n):
    wk=[]
    for j in range(1,min(k,i)+1):
      wk.append(cost[i-j]+abs(h[i]-h[i-j]))
    cost.append(min(wk))
  print(cost[n-1])
jitcalc(n,k,h)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict,deque
#from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()
sys.setrecursionlimit(10**6)
"""========main code==============="""

t=ii()
if t>=30:
    print("Yes")
else:
    print("No")

Fixed submission:

from collections import defaultdict,deque
#from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

t=ii()
if t>=30:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
#import sys
#input = sys.stdin.readline

import math
from collections import defaultdict,deque
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

def fast_expo(x,y,m):
    res=1
    while(y):
        if(y&1):
            res*=x
            res%=m
        x*=x
        x%=m
        y>>=1
    return res    

dp=defaultdict(int)
dp[1]=1
dp[2]=1
for i in range(3,200001):
    s=""
    k=i
    cnt=0
    while(k):
        if(k%2): cnt+=1
        k>>=1
    dp[i]=dp[i%cnt]+1
n=ii()
a=ip()
a=a[::-1]
c=a.count('1')

min_1=0
max_1=0

for i in range(n):
    if(a[i]=='1'):
        min_1+=fast_expo(2,i,c-1)
        max_1+=fast_expo(2,i,c+1)
        min_1%=(c-1)
        max_1%=(c+1)
    
ans=[]    

for i in range(n):
    if(a[i]=='1'):
        ans.append(dp[(min_1-fast_expo(2,i,c-1)+(c-1))%(c-1)]+1)
    else:
        ans.append(dp[(max_1+fast_expo(2,i,c+1))%(c+1)]+1)
ans=ans[::-1]
for i in ans:
    print(i)

Fixed submission:
#import sys
#input = sys.stdin.readline

import math
from collections import defaultdict,deque
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

def fast_expo(x,y,m):
    res=1
    while(y):
        if(y&1):
            res*=x
            res%=m
        x*=x
        x%=m
        y>>=1
    return res    

dp=defaultdict(int)
dp[1]=1
dp[2]=1
for i in range(3,200001):
    k=i
    cnt=0
    while(k):
        if(k%2): cnt+=1
        k>>=1
    dp[i]=dp[i%cnt]+1
n=ii()
a=ip()
a=a[::-1]
c=a.count('1')

min_1=0
max_1=0

for i in range(n):
    if(a[i]=='1'):
        if(c-1!=0):
            min_1+=fast_expo(2,i,c-1)
            min_1%=(c-1)
        max_1+=fast_expo(2,i,c+1)
        
        max_1%=(c+1)
    
ans=[]    

for i in range(n):
    if(a[i]=='1'):
        if(c-1==0):
            ans.append(0)
        else:    
            ans.append(dp[(min_1-fast_expo(2,i,c-1)+(c-1))%(c-1)]+1)
    else:
        ans.append(dp[(max_1+fast_expo(2,i,c+1))%(c+1)]+1)
ans=ans[::-1]
for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

a,b=ml()
n=set()
for i in range(b):
    n.add(ii())
r=0
for i in range(a,1001):
    if(i not in n):
        r=i
        break
l=0    
for i in range(a-1,-1,-1):
    if(i not in n):
        l=i
        break
if(abs(l-a)<=abs(r-a)):
    print(l)
else:
    print(r)

Fixed submission:
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

a,b=ml()
if(b==0):
    n=set()
else:
    n=ll()
    n=set(n)
r=0
for i in range(a,1001):
    if(i not in n):
        r=i
        break
l=0    
for i in range(a-1,-1,-1):
    if(i not in n):
        l=i
        break
if(abs(l-a)<=abs(r-a)):
    print(l)
else:
    print(r)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())

"""========main code==============="""
t=ii()

a=ll()
s=1
f=0
val=10**18
for i in a:
    s*=i
    
if s>val:
    print(-1)
else:
    print(s)


Fixed submission:
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())

"""========main code==============="""
t=ii()

a=ll()
s=1
f=0
val=10**18
if 0 in a:
    print(0)
else:    
    for i in a:
        s*=i
        if(s>val):
            f=1
            break
    if f:
        print(-1)
    else:
        print(s)
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
print((x*(x-1)//2+(y*(y-1)//2)

Fixed submission:
x,y=map(int,input().split())
print((x*(x-1)//2)+(y*(y-1)//2))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import math
sieve=[1]*10001
i=2
while i*i<=10001:
    if sieve[i]:
        for j in range(i+i,10001,i):
            sieve[j]=0
        
    i+=1    
lol=[]
for i in range(2,10001):
    if sieve[i]:
        lol.append(i)
mod=10**9+7
def gcd(x,y):
    if x==0:
        return y
    return gcd(y%x,x)    
x=int(input())
a=list(map(int,input().split()))
d=defaultdict(int)
for i in a:
    k=0

    while lol[k]*lol[k]<=i:
        c=0
        #print("AScasc",i)
        j=lol[k]
        if i%j==0:    
            while i%j==0:
                i//=j
                c+=1
            d[j]=max(c,d[j])    
        k+=1    
    if i>=2:
        c=1
        d[i]=max(c,d[i])
        
y=0
s=d.keys()
#print(s,d)
for i in a:
    d0=d.copy()
    k=0
    while lol[k]*lol[k]<=i:
        j=lol[k]
        if i%j==0:    
            while i%j==0:
                i//=j
                d0[j]-=1
        k+=1
    if i>=2:
        d0[i]-=1
    z=1
    for j in d0.keys():
        z*=pow(j,d0[j],mod)
    y+=z%mod    
print(y%mod)        

Fixed submission:
from collections import defaultdict
import math
sieve=[1]*10001
i=2
while i*i<=10001:
    if sieve[i]:
        for j in range(i+i,10001,i):
            sieve[j]=0
        
    i+=1    
lol=[]
for i in range(2,10001):
    if sieve[i]:
        lol.append(i)
mod=10**9+7
def gcd(x,y):
    if x==0:
        return y
    return gcd(y%x,x)    
x=int(input())
a=list(map(int,input().split()))
d=defaultdict(int)
for i in a:
    k=0

    while lol[k]*lol[k]<=i:
        c=0
        #print("AScasc",i)
        j=lol[k]
        if i%j==0:    
            while i%j==0:
                i//=j
                c+=1
            d[j]=max(c,d[j])    
        k+=1    
    if i>=2:
        c=1
        d[i]=max(c,d[i])
        
y=0
s=d.keys()
#print(s,d)
z=1
for i in s:
    z*=pow(i,d[i])
for i in a:
    y+=((z%mod)*pow(i,mod-2,mod))%mod
print(y%mod)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x,y):
    if x==0:
        return y
    return gcd(y%x,x)    
x=int(input())
a=list(map(int,input().split()))
k=a[0]

for i in range(1,x):
    k=(k*a[i])//gcd(k,a[i])
s=0
mod=10**9+7
for i in a:
    s=(s+(k//i))%mod
print(s%mod)    

Fixed submission:
from collections import defaultdict
import math
sieve=[1]*10001
i=2
while i*i<=10001:
    if sieve[i]:
        for j in range(i+i,10001,i):
            sieve[j]=0
        
    i+=1    
lol=[]
for i in range(2,10001):
    if sieve[i]:
        lol.append(i)
mod=10**9+7
def gcd(x,y):
    if x==0:
        return y
    return gcd(y%x,x)    
x=int(input())
a=list(map(int,input().split()))
d=defaultdict(int)
for i in a:
    k=0

    while lol[k]*lol[k]<=i:
        c=0
        #print("AScasc",i)
        j=lol[k]
        if i%j==0:    
            while i%j==0:
                i//=j
                c+=1
            d[j]=max(c,d[j])    
        k+=1    
    if i>=2:
        c=1
        d[i]=max(c,d[i])
        
y=0
s=d.keys()
#print(s,d)
z=1
for i in s:
    z*=pow(i,d[i])
for i in a:
    y+=((z%mod)*pow(i,mod-2,mod))%mod
print(y%mod)
Buggy python submission (verdict: Runtime Error):
import math
#x=int(input())
a,b=map(int,input().split())
c=math.gcd(a,b)
print((a*b)//c)

Fixed submission:
def gcd(a,b):
    if a==0:
        return b
    else:
        return gcd(b%a,a)
#x=int(input())
a,b=map(int,input().split())
c=gcd(a,b)
print((a*b)//c)

Buggy python submission (verdict: Runtime Error):
import math
#x=int(input())
a,b=map(int,input().split())
c=math.gcd(a,b)
print((a*b)/c)

Fixed submission:
def gcd(a,b):
    if a==0:
        return b
    else:
        return gcd(b%a,a)
#x=int(input())
a,b=map(int,input().split())
c=gcd(a,b)
print((a*b)//c)