Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

import math

from functools import lru_cache
#上手くいかない時は下
# from functools32 import lru_cache 

@lru_cache(None)
def prime_factorization_1(num):
    if num <= 1:
        return False
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        dict_counter = defaultdict(int)
        for prime in prime_list:
            while num % prime == 0:
                dict_counter[prime] += 1
                num //= prime
        if num != 1:
            dict_counter[num] += 1

        dict_counter = dict(dict_counter)

        return dict_counter
def search_divisor_num_2(num):
    if num < 0:
        return None
    elif num == 1:
        return 1
    else:
        divisor_num = 1
        dict_fact = prime_factorization_1(num)
        for value in dict_fact.values():
            divisor_num *= (value + 1)
        return divisor_num
    
N=int(input())
cnt=0
for i in range(1,N):
    cnt += search_divisor_num_2(N-i)
    
print(cnt)

Fixed submission:
N=int(input())

ans=0
for a in range(1,N):
    ans += (N-1)//a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math

from functools import lru_cache
#上手くいかない時は下
# from functools32 import lru_cache 

@lru_cache(None)
def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]

def search_divisor_num_1(num):
    if num < 0:
        return None
    elif num == 1:
        return 1
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        divisor_num = 1
        for prime in prime_list:
            count = 1
            while num % prime == 0:
                num //= prime
                count += 1
            divisor_num *= count

        if num != 1:
            divisor_num *= 2

        return divisor_num
    
N=int(input())
cnt=0
for i in range(1,N):
    cnt += search_divisor_num_1(N-i)
    
print(cnt)

Fixed submission:
N=int(input())

ans=0
for a in range(1,N):
    ans += (N-1)//a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


N=int(input())
cnt=0
for i in range(1,N):
    cnt += len(make_divisors(N-i))
    
print(cnt)

Fixed submission:
N=int(input())

ans=0
for a in range(1,N):
    ans += (N-1)//a
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

N=int(input())
A = list(map(int,input().split()))
 
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

if gcd_list(A) > 1:
    print("not coprime")
    sys.exit()

D = [i for i in range(max(A)+1)] #iを割り切る最小の素数を格納
p = 2
 
while(p*p<=max(A)):
    if D[p]==p:
        for i in range(2*p,max(A)+1,p):
            if D[i]==i:
                D[i]=p
 
    p+=1
    
prime = set()
for a in A:
    tmp=D[a]
    L=set()
    while(a>1):
        a=a//tmp
        L.add(tmp)
        tmp=D[a]

    for l in L:
        if l in prime:
            print("setwise coprime")
            sys.exit()
        else:
            prime.add(l)

print("pairwise coprime")

Fixed submission:
D,T,S=map(int,input().split())

if D <= T*S:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
import sys

N=int(input())
A = list(map(int,input().split()))
 
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

if gcd_list(A) > 1:
    print("not coprime")
    sys.exit()

D = [i for i in range(max(A)+1)] #iを割り切る最小の素数を格納
p = 2
 
while(p*p<=max(A)):
    if D[p]==p:
        for i in range(p*p,max(A)+1,p):
            if D[i]==i:
                D[i]=p
 
    p+=1
    
prime = set()
for a in A:
    tmp=D[a]
    L=set()
    while(a>1):
        a=a//tmp
        L.add(tmp)
        tmp=D[a]

    for l in L:
        if l in prime:
            print("setwise coprime")
            sys.exit()
        else:
            prime.add(l)

print("pairwise coprime")

Fixed submission:
D,T,S=map(int,input().split())

if D <= T*S:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())

G=[[] for i in range(N)]
for i in range(M):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)

from collections import deque

over=[] #探索ずみ
before=[] #探索前
for i in range(N):
    before.append(i)

dist=[float('inf')]*N
cnt=0
cup=[]
while before:
    v=before.pop(0)
    que=deque([v])
    dist[v]=0
    cuppy=[]
    cuppy.append(v)
    while que:
        u=que.popleft()
        
        for e in G[u]:
            if dist[e] == float('inf'):
                
                que.append(e)
                before.remove(e)
                cuppy.append(e)
                dist[e]=dist[u] + 1
    
    cup.append(cuppy)
    cnt += 1


ans=0
for i in range(len(cup)):
    ans = max(ans,len(cup[i]))
print(ans)

Fixed submission:
N,M=map(int,input().split())

class UnionFind():
    def __init__(self,n): #n:要素数
        self.n=n
        self.parents = [-1]*n 
        #parents:各要素の親要素番号を格納
        #要素が根である場合、-(そのグループの要素数)を格納する
    
    def find(self,x): #xが属する根を返す
        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のグループとyのグループを併合する
        x = self.find(x)
        y = self.find(y)
        
        if x==y:
            return
        
        if self.parents[x] > self.parents[y]: #|xのグループ|<|yのグループ|
            x,y=y,x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        #よりグループ数が多い方の根にもう一方のグループを接続
        
    def size(self,x): #xの属するグループのサイズ
        return -self.parents[self.find(x)]

uf=UnionFind(N)
for i in range(M):
    a,b=map(lambda x:int(x)-1,input().split())
    uf.union(a,b)

ans=0

for i in range(N):
    if uf.size(i) > ans:
        ans=uf.size(i)
        
print(ans)
Buggy python submission (verdict: Runtime Error):
K=int(input())

flag=0　#Kで割れた時にflag=1となる。

a=7 #第i項
i=0 #index

if (K%2 !=　0):
    print(-1)

else:
    while(flag==0):
        if(a%k==0):
            flag==1
        i += 1
        a=10*a+7

    print(i)

Fixed submission:
K=int(input())

a=7 #第1項
b=10
i=0 #index

if (K%7 == 0):
    L = 9*K/7
else:
    L = 9*K
    
if (L%2==0 or L%5==0):
    print(-1)
else:
    while(i<=L):
        if (b%L==1):
            break
        else:
            b=10*(b%L)
            i += 1
    print(i+1)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

c=list(input())

def split(c,i):
    left=c[:i]
    right=c[i:]
    return left,right

minimum=len(c)

for i in range(0,len(c)+1):
    left,right=split(c,i)
    W=left.count('W')
    R=right.count('R')
    min_i=max(W,R)
    if min_i < minimum:
        minimum=min_i

print(minimum)

Fixed submission:
N=int(input())

c=list(input())

minimum=len(c)
W=0
R=c.count('R')

for i in range(0,len(c)):
    if c[i]=='W':
        W += 1
    else :
        R -= 1
    min_i=max(W,R)
    if min_i < minimum:
        minimum=min_i

if c.count('R')==0:
    minimum=0

print(minimum)
Buggy python submission (verdict: Runtime Error):
mod=10**9+7
n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True,key=lambda x:abs(x)) #絶対値の順にソートする
if k==n: #k=nのときはすべてを掛け合わせるほかない
  ans=1
  for i in range(n):
    ans*=arr[i]
    ans%=mod
  print(ans)
else:
  if k%2==1 and max(arr)<0: #答えが負になる場合は絶対値の小さい順にK個掛け合わせる
    ans=1
    for i in range(k):
      ans*=arr[n-1-i]
      ans%=mod
      print(ans)
  else:
    ans=1
    cnt=0
    for i in range(k): #絶対値の大きい順にK個掛け合わせる
      if arr[i]<0: #負数を掛けた回数を数えておく
        cnt+=1
      ans*=arr[i]
      ans%=mod
    if cnt%2==0: #負数を偶数回掛けていれば答えは非負なのでそのまま出力
      print(ans)
    else: #そうでなければ調整を行う
      min_plus=-1
      min_minus=1
      for i in range(k): #絶対値の大きい順にK個を見て最小の非負の数・負の数を探す
        if arr[i]>=0:
          min_plus=arr[i]
        else:
          min_minus=arr[i]
      max_plus=-1
      max_minus=1
      for i in range(k,n): #残るN-K個を見て最大の非負の数・負の数を探す
        if arr[i]>=0 and max_plus==-1:
          max_plus=arr[i]
        if arr[i]<0 and max_minus==1:
          max_minus=arr[i]
      if min_plus==-1: #もし最小の非負の数がなければ、最小の負の数を取り除くしかない
        arr.remove(min_minus)
        ans=1
        for i in range(k-1):
          ans*=arr[i]
          ans%=mod
        ans*=max_plus
        ans%=mod
      elif min_minus==1: #もし最小の負の数がなければ、最小の非負の数を取り除くしかない
        arr.remove(min_plus)
        ans=1
        for i in range(k-1):
          ans*=arr[i]
          ans%=mod
        ans*=max_minus
        ans%=mod
      elif min_plus*max_plus>=min_minus*max_minus: #そうでなければより倍率の大きいほうを選ぶ
        arr.remove(min_minus)
        ans=1
        for i in range(k-1):
          ans*=arr[i]
          ans%=mod
        ans*=max_plus
        ans%=mod
      else:
        arr.remove(min_plus)
        ans=1
        for i in range(k-1):
          ans*=arr[i]
          ans%=mod
        ans*=max_minus
        ans%=mod
      print(ans)

Fixed submission:
N=int(input())

if N%1000==0:
    print(0)
else:
    print(-(N%1000)+1000)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
if n==1:
    print(1)
else:
    g=[list(map(int,input().split())) for i in range(n-1)]
    
    edge_sum=0
    
    for l in range(1,n+1):
        for r in range(l,n+1):
            edge_num=0
            edge_num += r-l+1
            for k in range(n-1):
                if l<=g[k][0]<=r and l<=g[k][1]<=r:
                    edge_num -= 1
            
            edge_sum +=edge_num
    print(edge_sum)

Fixed submission:
n=int(input())
ans=0
for i in range(1,n+1):
    ans += i*(i+1)/2
for i in range(n-1):
    u,v=map(int,input().split())
    if u > v:
        u,v=v,u
    ans -= u*(n-v+1)
print(int(ans))
Buggy python submission (verdict: Runtime Error):
b=a+ a**2 + a**3
print(b)

Fixed submission:
a=int(input())

print(a+a**2+a**3)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
import bisect

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

acum1=[0]
for i in range(n): #累積和ai,bjを求める
    acum1.append(acum1[-1]+arr1[i])
for i in range(m):
    acum2.append(acum2[-1]+arr2[i])

ans = 0
for an in range(n + 1):
    rem = k - acum1[an]
    if rem < 0:
        # aをこれ以上読めません
        break

    bn = bisect.bisect_right(acum2, rem)
    ans = max(ans, an + bn)

print(ans)

Fixed submission:
from itertools import accumulate
import bisect

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

a_acc = [0] + list(accumulate(a))  # aを0冊読む=1冊も読まない場合があるので、[0]を先頭に追加します
b_acc = list(accumulate(b))  # bisect_rightでは、x以下の要素がいくつあるか？を求めるので、こちらに0は入れません

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        # aをこれ以上読めません
        break

    bn = bisect.bisect_right(b_acc, rem)
    ans = max(ans, an + bn)

print(ans)

Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
import bisect
 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
 
acum1=[0]
for i in range(n): #累積和ai,bjを求める
    acum1.append(acum1[-1]+arr1[i])
for i in range(m):
    acum2.append(acum2[-1]+arr2[i])
 
ans = 0
for an in range(n + 1):
    rem = k - acum1[an]
    if rem < 0:
        # aをこれ以上読めません
        break
 
    bn = bisect.bisect_right(acum2, rem)
    ans = max(ans, an + bn)
 
print(ans)

Fixed submission:
from itertools import accumulate
import bisect

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

a_acc = [0] + list(accumulate(a))  # aを0冊読む=1冊も読まない場合があるので、[0]を先頭に追加します
b_acc = list(accumulate(b))  # bisect_rightでは、x以下の要素がいくつあるか？を求めるので、こちらに0は入れません

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        # aをこれ以上読めません
        break

    bn = bisect.bisect_right(b_acc, rem)
    ans = max(ans, an + bn)

print(ans)

Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
import bisect

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

acum1=[0]
for i in range(n): #累積和ai,bjを求める
    acum1.append(acum1[-1]+arr1[i])
for i in range(m):
    acum2.append(acum2[-1]+arr2[i])

ans = 0
for an in range(n + 1):
    rem = k - acum1[an]
    if rem < 0:
        # aをこれ以上読めません
        break

    bn = bisect.bisect_right(acum2, rem)
    ans = max(ans, an + bn)

print(ans)

Fixed submission:
from itertools import accumulate
import bisect

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

a_acc = [0] + list(accumulate(a))  # aを0冊読む=1冊も読まない場合があるので、[0]を先頭に追加します
b_acc = list(accumulate(b))  # bisect_rightでは、x以下の要素がいくつあるか？を求めるので、こちらに0は入れません

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        # aをこれ以上読めません
        break

    bn = bisect.bisect_right(b_acc, rem)
    ans = max(ans, an + bn)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
q=int(input())

summ=sum(a)
num=[a.count(i) for i in range(100001)]
for i in range(q):
    b,c=map(int,input().split())
    b_num=num[b]
    num[c] += b_num
    num[b]=0
    summ +=(c-b)*b_num
    print(summ)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
q=int(input())

summ=sum(a)
num=[0 for i in range(10**5+1)]
for i in range(n):
    num[a[i]] += 1
for i in range(q):
    b,c=map(int,input().split())
    b_num=num[b]
    num[c] += b_num
    num[b]=0
    summ +=(c-b)*b_num
    print(summ)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
q=int(input())

summ=sum(a)
num=[a.count(i) for i in range(1,100000)]
for i in range(q):
    b,c=map(int,input().split())
    b_num=num[b]
    num[c] += num[b]
    num[b]=0
    summ +=(c-b)*b_num
    print(summ)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
q=int(input())

summ=sum(a)
num=[0 for i in range(10**5+1)]
for i in range(n):
    num[a[i]] += 1
for i in range(q):
    b,c=map(int,input().split())
    b_num=num[b]
    num[c] += b_num
    num[b]=0
    summ +=(c-b)*b_num
    print(summ)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
q=int(input())

summ=sum(a)
for i in range(q):
    b,c=map(int,input().split())
    b_num=a.count(b)
    a=[c if i==b else i for i in a]
    summ +=(c-b)*b_num
    print(summ)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
q=int(input())

summ=sum(a)
num=[0 for i in range(10**5+1)]
for i in range(n):
    num[a[i]] += 1
for i in range(q):
    b,c=map(int,input().split())
    b_num=num[b]
    num[c] += b_num
    num[b]=0
    summ +=(c-b)*b_num
    print(summ)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

xor=0
for i in a:
    xor ^= i

pop=0 #xorのpopにする
while(xor >> pop >=1):
    pop += 1

sum_xor=0 #各猫の排他的論理和
if N%2==1:
    for i in range(pop):
        sum_xor += 2 **i
else:
    sum_xor=xor

ans=[]
for i in range(n):
    x=a[i]^sum_xor
    if i<n-1:
        print(x,end=' ')
    else:
        print(x)

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

xor=0
for i in a:
    xor ^= i

pop=0 #xorのpopにする
while(xor >> pop >=1):
    pop += 1

sum_xor=xor #各猫の排他的論理和

ans=[]
for i in a:
    x=i^sum_xor
    ans.append(x)

print(" ".join(map(str, ans)))

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

xor=0
for i in a:
    xor ^= i

pop=0 #xorのpopにする
while(xor >> pop >=1):
    pop += 1

sum_xor=0 #各猫の排他的論理和
if N%2==1:
    for i in range(pop):
        sum_xor += 2 **i
else:
    sum_xor=xor

for i in range(n):
    x=a[i]^sum_xor
    print(x,end=' ')

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

xor=0
for i in a:
    xor ^= i

pop=0 #xorのpopにする
while(xor >> pop >=1):
    pop += 1

sum_xor=xor #各猫の排他的論理和

ans=[]
for i in a:
    x=i^sum_xor
    ans.append(x)

print(" ".join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
x=list(map(int,input().split()))

for i in range(len(x)):
  if x[i]==0:
    print(i+1)
    break:

Fixed submission:
x=list(map(int,input().split()))
 
for i in range(len(x)):
    if x[i]==0:
        print(i+1)
        break
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())

G=[[] for i in range(N)] #グラフを隣接リストで表現
for j in range(M):
    x,y=map(lambda x:int(x)-1,input().split())
    G[x].append(y)

dp=[-1]*N

def longest_path(v): #vを始点とした時の最長パスの長さ
    if dp[v] != -1: #更新済みの場合
        return dp[v]
    
    #更新されていなかった場合
    tmp_max = 0
    for u in G[v]:
        tmp_max = max(tmp_max,longest_path(u)+1)
    dp[v] = tmp_max #きちんとメモする
    
    return dp[v]

ans=0
for i in range(N):
    ans = max(ans,longest_path(i))

print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**5+10)

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

G=[[] for i in range(N)] #グラフを隣接リストで表現
for j in range(M):
    x,y=map(lambda x:int(x)-1,input().split())
    G[x].append(y)

dp=[-1]*N

def longest_path(v): #vを始点とした時の最長パスの長さ
    if dp[v] != -1: #更新済みの場合
        return dp[v]
    
    #更新されていなかった場合
    tmp_max = 0
    for u in G[v]:
        tmp_max = max(tmp_max,longest_path(u)+1)
    dp[v] = tmp_max #きちんとメモする
    
    return dp[v]

ans=0
for i in range(N):
    ans = max(ans,longest_path(i))

print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
xbox=[]
ybox=[]
for i in range(n):
    x,y = map(int,input().split())
    xbox.append(x)
    ybox.append(y)
xmax=max(xbox)
xmin = min(xbox)
ymax=max(ybox)
ymin=min(ybox)
box1=[]
box2=[]
box3=[]
box4=[]
for i in range(n):
    box1.append(xmax+ymax-xbox[i]-ybox[i])
    box2.append(-xmin + ymax + xbox[i] - ybox[i])
    box2.append(xmax - ymax - xbox[i] + ybox[i])
    box2.append(-xmax - ymax + xbox[i] + ybox[i])
print(max([max(box1)-min(box1),max(box2)-min(box2),max(box3)-min(box3),max(box4)-min(box4)]))


Fixed submission:
n=int(input())
xbox=[]
ybox=[]
for i in range(n):
    x,y = map(int,input().split())
    xbox.append(x)
    ybox.append(y)
xmax=max(xbox)
xmin = min(xbox)
ymax=max(ybox)
ymin=min(ybox)
box1=[]
box2=[]
box3=[]
box4=[]
for i in range(n):
    box1.append(xmax+ymax-xbox[i]-ybox[i])
    box2.append(-xmin + ymax + xbox[i] - ybox[i])
    box3.append(xmax - ymax - xbox[i] + ybox[i])
    box4.append(-xmax - ymax + xbox[i] + ybox[i])
print(max([max(box1)-min(box1),max(box2)-min(box2),max(box3)-min(box3),max(box4)-min(box4)]))
Buggy python submission (verdict: Runtime Error):
x=int(iput())
if x>=30:
    print('Yes')
else:
    print('No')

Fixed submission:
x=int(input())
if x>=30:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n= int(input())
a = list(map(int,input().split()))
s=0
k=0
top=[]
bottom=[]
t=0
ans=1000
ka=0
while a[s]==a[s+1] and s<n-1:
    s+=1
if s==n-1:
    print(ans)
else:
    if a[s]>a[s+1]:
        k=-1
        t=1
    else:
        k=1

    while s<n-1:
        while a[s]*k <= a[s+1]*k and s<n-1:
            s+=1
            if s==n-1:
                break
        if k ==-1:
            bottom.append(a[s])
        else:
            top.append(a[s])
        k *= -1
        s+=1
    if k == 1:
        top.append(a[-1])
    else:
        bottom.append(a[-1])
    if t==1:
        for i in range(len(top)):
            ka+=ans//bottom[i]
            ans = ans % bottom[i]
            ans += ka*top[i]
            ka = 0
    else:
        for i in range(len(top)):
            
            if i== 0:
                ka += ans // a[i]
                ans = ans % a[i]
                ans += ka * top[i]
                ka = 0
            else:
                ka+=ans//bottom[i-1]
                ans = ans % bottom[i-1]
                ans += ka*top[i]
                ka = 0
    print(ans)

Fixed submission:
n= int(input())
a = list(map(int,input().split()))
s=0
k=0
top=[]
bottom=[]
t=0
ans=1000
ka=0
while a[s]==a[s+1] and s<n-1:
    s+=1
    if s == n - 1:
        break
if s==n-1:
    print(ans)
else:
    if a[s]>a[s+1]:
        k=-1
        t=1
    else:
        k=1

    while s<n-1:
        while a[s]*k <= a[s+1]*k and s<n-1:
            s+=1
            if s==n-1:
                break
        if k ==-1:
            bottom.append(a[s])
        else:
            top.append(a[s])
        k *= -1
        s+=1
    if k == 1:
        top.append(a[-1])
    else:
        bottom.append(a[-1])
    if t==1:
        for i in range(len(top)):
            ka+=ans//bottom[i]
            ans = ans % bottom[i]
            ans += ka*top[i]
            ka = 0
    else:
        for i in range(len(top)):

            if i== 0:
                ka += ans // a[i]
                ans = ans % a[i]
                ans += ka * top[i]
                ka = 0
            else:
                ka+=ans//bottom[i-1]
                ans = ans % bottom[i-1]
                ans += ka*top[i]
                ka = 0
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
s = len(bin(max(a)))-2

box = [0] * s
bbbox = [] * n
for i in range(n):
    bbbox.append(format(a[i],'b').zfill(s))
    for j in range(s):
        box[j] += int(bbbox[-1][-j-1])
        

ans = [0] * n
for i in range(s):
    for j in range(n):
        if box[i] % 2 == 0:
            if bbbox[j][-1-i] == '1':
                ans[j] += 2 ** i
        else:
            if bbbox[j][-1-i] == '0':
                ans[j] += 2 ** i
print(*ans)



Fixed submission:
n = int(input())
a = list(map(int,input().split()))
s = len(bin(max(a)))-2

box = [0] * s
bbbox = [] * n
for i in range(n):
    bbbox.append(format(a[i],'b').zfill(s))
    for j in range(s):
        box[j] += int(bbbox[-1][-j-1])


ans = [0] * n
for i in range(s):
    for j in range(n):
        if box[i] % 2 == 0:
            if bbbox[j][-1-i] == '1':
                ans[j] += 2 ** i
        else:
            if bbbox[j][-1-i] == '0':
                ans[j] += 2 ** i
print(*ans)
Buggy python submission (verdict: Runtime Error):
n = I()
a = LI()
ans = 1
a.sort()
for i in range(n):
    ans *= a[i]
    if ans > 10**18+1:
        print(-1)
        exit()
    elif ans == 0:
        print(0)
        exit()
print(int(ans))

Fixed submission:
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def MS(): return map(str, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# N = I()
# A = [LI() for _ in range(N)]


n = I()
a = LI()
ans = 1
a.sort()
for i in range(n):
    ans *= a[i]
    if ans >= 10**18+1:
        print(-1)
        sys.exit()
    elif ans == 0:
        print(0)
        sys.exit()
print(int(ans))