Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)
import itertools as it
import collections as cl
from collections import deque
import math
from functools import reduce
from collections import defaultdict


def li():
    return [int(x) for x in input().split()]


N, X, MOD = li()


n = X
seen = [False] * (10 ** 5)
sums = [X]
zero = False
for i in range(1, N):
    n = pow(n, 2, MOD)
    if n==0:
        zero = True
        break
    if seen[n]:
        break
    seen[n] = True
    # print(n)
    sums.append(n)
# total %= MOD
loop_cnt = N // (i-1) + 1
amari = N % (i-1)
print(amari)
ans = 0
if zero:
    ans = sum(sums)
else:
    ans = (sum(sums) * loop_cnt + sum(sums[:amari]))
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)


def li():
    return [int(x) for x in input().split()]


N, X, MOD = li()


n = X
nums = [X]
loop_start_i = -INF
for i in range(1, N):
    n = pow(n, 2, MOD)
    if n in nums:
        loop_start_i = nums.index(n)
        break
    nums.append(n)
# total %= MOD
loop_length = len(nums) - loop_start_i
loop_cnt = (N - loop_start_i) // loop_length
r = (N - loop_start_i) % loop_length
sum_per_loop = sum(nums[loop_start_i:])
ans = sum(nums[:loop_start_i]) + sum_per_loop * loop_cnt + sum(nums[loop_start_i:loop_start_i+r])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def li():
    return [int(x) for x in input().split()]

N = int(input())
A = [0] + li()
d = 10**9 + 7

total = 0

for i in range(1, N):
    for j in range(i+1, N+1):
        total += ((A[i] % d) * (A[j] % d))
        total = total % d

print(total)

Fixed submission:
def li():
    return [int(x) for x in input().split()]

N = int(input())
A = li()
d = 10**9 + 7
B = [A[i] % d for i in range(len(A))]

s = 0
s2 = 0
for i in range(len(B)):
    s += B[i]
    s = s
    s2 += B[i] ** 2
    s2 = s2

ans = ((s**2 - s2) // 2) % d

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)

def li():
    return [int(x) for x in input().split()]

N, M = li()
L = []
for i in range(M):
    a, b = sorted(li())
    L.append((a, b))

L = set(L)

cnts = [0] * (N+1)

for l in L:
    a, b = l
    cnts[a] += 1
    cnts[b] += 1
# print(cnts)
p = cnts.index(max(cnts))
# print(p)

others = []
for l in L:
    a, b = l
    if a == p:
        others.append(b)
    elif b == p:
        others.append(a)

anothers = []
for other in others:
    for l in L:
        a, b = l
        if a == other:
            anothers.append(b)
        elif b == other:
            anothers.append(a)
#
# print(others)
# print(anothers)

all = list(set(others + anothers))
all.remove(p)
ans = len(all) + 1
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)

def li():
    return [int(x) for x in input().split()]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, 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 = 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):
        root = self.find(x)
        return -self.parents[root]

    def members(self, x):
        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 all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = li()
uf = UnionFind(N)
for i in range(M):
    a, b = li()
    uf.union(a-1, b-1)

ans = max(uf.size(x) for x in range(N))
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def li():
    return [int(x) for x in input().split()]

N = int(input())
A = li()

A.sort(reverse=True)

B = [A[i] for i in range(N) if i < N//2]

# 9 8 7 6 5
# 9 1 8 2 7 3 6 4 5
# 9 6 8 7
# 9+8+7+6+5+6+7+8

# 8 7 6 5
# 8 1 7 2 6 3 5 4
# 8+7+6+5+5+6+7

sm = B[0] + sum(B[i] * 2 for i in range(N/2) if 0 < i)
print(sm)

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

def li():
    return [int(x) for x in input().split()]

N = int(input())
A = li()

A.sort(reverse=True)

B = [A[i] for i in range(N) if i < N//2]

# 9 8 7 6 5
# 9 1 8 2 7 3 6 4 5
# 9 6 8 7
# 9+8+8+7+7+6+6+5

# 8 7 6 5
# 8 1 7 2 6 3 5 4
# 8+7+6+5+5+6+7

if N % 2 == 1:
    B = [A[i] for i in range(N) if i < N // 2 + 1]
    sm = B[0] + B[-1] + sum(B[i]*2 for i in range(N//2) if 0 < i)
    print(sm)
else:
    sm = B[0] + sum(B[i]*2 for i in range(N//2) if 0 < i)
    print(sm)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

x, n = [int(x) for x in input().split()]
if n == 0:
    q = [x for x in range(1, 101)]
else:
    p = [int(x) for x in input().split()]
    q = [x for x in range(1, 101) if x not in p]

diffs = [abs(x-qk) for qk in q]
mindiff = min(diffs)
idx = diffs.index(mindiff)
print(q[idx])

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

def calc():
    x, n = [int(x) for x in input().split()]

    if n == 0:
        q = [x for x in range(102)]
    else:
        p = [int(x) for x in input().split()]
        q = [x for x in range(102) if x not in p]
    diffs = [abs(x - qk) for qk in q]
    mindiff = min(diffs)
    idx = diffs.index(mindiff)
    print(q[idx])

calc()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

x, n = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

q = [x for x in range(1, 101) if x not in p]
diffs = [abs(x-qk) for qk in q]
mindiff = min(diffs)
idx = diffs.index(mindiff)
print(q[idx])

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

def calc():
    x, n = [int(x) for x in input().split()]

    if n == 0:
        q = [x for x in range(102)]
    else:
        p = [int(x) for x in input().split()]
        q = [x for x in range(102) if x not in p]
    diffs = [abs(x - qk) for qk in q]
    mindiff = min(diffs)
    idx = diffs.index(mindiff)
    print(q[idx])

calc()
Buggy python submission (verdict: Time Limit Exceeded):
def li():
    return [int(x) for x in input().split()]
INF = 10**18
import itertools as it


N, A, B, C = li()
sl = [int(input()) for x in range(N)]
todo_stack = [sl]
candidate_lists = []
seen = []
minmp = INF
target = [A, B, C]
target.sort()
minl = []
while len(todo_stack) > 0:
    l = todo_stack.pop()
    if l in seen:
        continue
    seen.append(l)
    n = len(l)
    cs = it.combinations(l, 3)
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if i==j or j==k or k==i:
                    continue
                bamboos = [l[i], l[j], l[k]]
                bamboos.sort()
                diff = abs(bamboos[0] - target[0]) + abs(bamboos[1] - target[1]) + abs(bamboos[2] - target[2])
                mp = (N - n) * 10 + diff
                if mp < minmp:
                    minmp = mp
                    minl = l
    if len(l) <= 3:
        continue
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            syn = l[i] + l[j]
            others = [l[k] for k in range(n) if (k != i and k != j)]
            newl = others + [syn]
            if len(newl) >= 3:
                todo_stack.append(newl)

print(minmp)


Fixed submission:
def li():
    return [int(x) for x in input().split()]
INF = 10**18
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, A, B, C = li()
l = [int(input()) for x in range(N)]

def dfs(index, a, b, c, none):
    # 終端
    if index == N:
        if min(a, b, c) > 0:
            return abs(a - A) + abs(b - B) + abs(c - C)
        else:
            return INF
    # ツリー構造
    v1 = dfs(index+1, a + l[index], b, c, none) + (10 if a > 0 else 0)
    v2 = dfs(index+1, a, b + l[index], c, none) + (10 if b > 0 else 0)
    v3 = dfs(index+1, a, b, c + l[index], none) + (10 if c > 0 else 0)
    v4 = dfs(index+1, a, b, c, none+1)
    return min(v1, v2, v3, v4)

ans = dfs(0, 0, 0, 0, 0)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def li():
    return [int(x) for x in input().split()]


INF = 10 ** 60

N, W = li()
L = [li() for i in range(N)]
V = 10 ** 5
# W <= 10**9 なので、
# dp[i][w]: i番目の選択で重さwだった時の価値の最大値、は計算量厳しい
# dp[i][v]: i番目の選択で価値vだった時の重さの最小値、で考えて重さの最小値がW以下のものから最大価値を算出する

dp = [[INF] * (V+1) for _ in range(N)]

# 初期条件
# 選ばない
dp[0][0] = 0
# 選ぶ
w0, v0 = L[0]
dp[0][v0] = w0

for i in range(1, N):
    for v in range(V+1):
        cw, cv = L[i]
        # 選ばない
        dp[i][v] = min(dp[i][v], dp[i-1][v])
        # 選ぶ
        if v + cv > V:
            continue
        dp[i][v+cv] = min(dp[i][v+cv], dp[i-1][v] + cw)

# 重さの最小値がW以下で達成できるvの最大値
v_max = 0
for v in range(V+1):
    if dp[N-1][v] <= W:
        v_max = v
print(v_max)

Fixed submission:
def li():
    return [int(x) for x in input().split()]


INF = 10 ** 60

N, W = li()
L = [li() for i in range(N)]
V = 10 ** 5
# W <= 10**9 なので、
# dp[i][w]: i番目の選択で重さwだった時の価値の最大値、は計算量厳しい
# dp[i][v]: i番目の選択で価値vだった時の重さの最小値、で考えて重さの最小値がW以下のものから最大価値を算出する

dp = [[INF] * (V+1) for _ in range(N)]

# 初期条件
# 選ばない
dp[0][0] = 0
# 選ぶ
w0, v0 = L[0]
dp[0][v0] = w0

for i in range(1, N):
    for v in range(V+1):
        cw, cv = L[i]
        # 選ばない
        dp[i][v] = min(dp[i][v], dp[i-1][v])
        # 選ぶ
        if v + cv > V:
            continue
        dp[i][v+cv] = min(dp[i][v+cv], dp[i-1][v] + cw)

# 重さの最小値がW以下で達成できるvの最大値
v_max = 0
for v in range(V+1):
    if dp[N-1][v] <= W:
        v_max = v
print(v_max)

Buggy python submission (verdict: Runtime Error):
def li():
    return [int(x) for x in input().split()]


INF = 10 ** 60

N, W = li()
L = [li() for i in range(N)]
V = 1000
# W <= 10**9 なので、
# dp[i][w]: i番目の選択で重さwだった時の価値の最大値、は計算量厳しい
# dp[i][v]: i番目の選択で価値vだった時の重さの最小値、で考えて重さの最小値がW以下のものから最大価値を算出する

dp = [[INF] * V for _ in range(N)]

# 初期条件
# 選ばない
dp[0][0] = 0
# 選ぶ
w0, v0 = L[0]
dp[0][v0] = w0

for i in range(1, N):
    for v in range(V):
        cw, cv = L[i]
        # 選ばない
        dp[i][v] = min(dp[i][v], dp[i-1][v])
        # 選ぶ
        if v + cv >= V:
            continue
        dp[i][v+cv] = min(dp[i][v+cv], dp[i-1][v] + cw)

# 重さの最小値がW以下で達成できるvの最大値
v_max = 0
for v in range(V):
    if dp[N-1][v] <= W:
        v_max = v
print(v_max)

Fixed submission:
def li():
    return [int(x) for x in input().split()]


INF = 10 ** 60

N, W = li()
L = [li() for i in range(N)]
V = 10 ** 5
# W <= 10**9 なので、
# dp[i][w]: i番目の選択で重さwだった時の価値の最大値、は計算量厳しい
# dp[i][v]: i番目の選択で価値vだった時の重さの最小値、で考えて重さの最小値がW以下のものから最大価値を算出する

dp = [[INF] * (V+1) for _ in range(N)]

# 初期条件
# 選ばない
dp[0][0] = 0
# 選ぶ
w0, v0 = L[0]
dp[0][v0] = w0

for i in range(1, N):
    for v in range(V+1):
        cw, cv = L[i]
        # 選ばない
        dp[i][v] = min(dp[i][v], dp[i-1][v])
        # 選ぶ
        if v + cv > V:
            continue
        dp[i][v+cv] = min(dp[i][v+cv], dp[i-1][v] + cw)

# 重さの最小値がW以下で達成できるvの最大値
v_max = 0
for v in range(V+1):
    if dp[N-1][v] <= W:
        v_max = v
print(v_max)
Buggy python submission (verdict: Runtime Error):
def li():
    return [int(x) for x in input().split()]

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

INF = 10 ** 60

G = defaultdict(list)

N, M = li()

for _ in range(M):
    x, y = li()
    G[x].append(y)

dp = [-1] * (10 ** 5)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for cv in G[v]:
        ret = max(ret, dfs(cv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(1, N+1):
    # print(dfs(v))
    ans = max(ans, dfs(v))

print(ans)

Fixed submission:
def li():
    return [int(x) for x in input().split()]

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

INF = 10 ** 60

G = defaultdict(list)

N, M = li()

for _ in range(M):
    x, y = li()
    G[x].append(y)

dp = [-1] * (10 ** 5 + 100)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for cv in G[v]:
        ret = max(ret, dfs(cv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(1, N+1):
    # print(dfs(v))
    ans = max(ans, dfs(v))

print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

def li():
    return [int(x) for x in input().split()]


INF = 10 ** 60

G = defaultdict(list)

N, M = li()

for _ in range(M):
    x, y = li()
    G[x].append(y)

dp = [-1] * (10 ** 5)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for cv in G[v]:
        ret = max(ret, dfs(cv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(1, N+1):
    # print(dfs(v))
    ans = max(ans, dfs(v))

print(ans)

Fixed submission:
def li():
    return [int(x) for x in input().split()]

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

INF = 10 ** 60

G = defaultdict(list)

N, M = li()

for _ in range(M):
    x, y = li()
    G[x].append(y)

dp = [-1] * (10 ** 5 + 100)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    ret = 0
    for cv in G[v]:
        ret = max(ret, dfs(cv) + 1)
    dp[v] = ret
    return ret


ans = 0
for v in range(1, N+1):
    # print(dfs(v))
    ans = max(ans, dfs(v))

print(ans)
Buggy python submission (verdict: Runtime Error):
return 'Yes' if int(input()) >= 30 else 'No'

Fixed submission:
print( 'Yes' if int(input().strip()) >=30 else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input());
l=list(map(int,input().strip().split()))
l.sort()
if l[0] == 0 : 
    print("0")
else :    
    ans = l[0]
    c=0
    for i in range(1, n, 1) :
        if l[i]*ans >  1000000000000000000 :
            print("-1")
            c=1
        ans = ans*l[i]    
    if c == 0 : 
        print(ans)        
    
  

Fixed submission:
n = int(input());
l=list(map(int,input().strip().split()))
l.sort()
if l[0] == 0 : 
    print("0")
else :    
    ans = l[0]
    c=0
    for i in range(1, n) :
        if l[i]*ans >  int(1000000000000000000) :
            print("-1")
            c=1
        if c == 1 : 
            break 
        ans = ans*l[i]    
    if c == 0 : 
        print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input)
print((1000 - (n % 1000)) % 1000)

Fixed submission:
n = int(input())
print((1000 - (n % 1000)) % 1000)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int, input().split()))
#myans_list =  [ [0 for n in range(N)] for nn in range(N) ]
#myans = 0
#for n in range(N):
#    for nn in range(N):
#        myans_list[n][nn] = A_list[n] * A_list[nn]
#for n in myans_list:
#    print(n)
myans = 0
for n in range(N-1):
    for nn in range(n+1, N):
        myans += A_list[n] * A_list[nn]
print(myans%(1000000007))

Fixed submission:
N = int(input())
A_list = list(map(int, input().split()))
#myans_list =  [ [0 for n in range(N)] for nn in range(N) ]
#myans = 0
#for n in range(N):
#    for nn in range(N):
#        myans_list[n][nn] = A_list[n] * A_list[nn]
#for n in myans_list:
#    print(n)
mysum = sum(A_list)
myans = 0
for n in range(N-1):
    mysum -= A_list[n]
    myans +=  mysum*A_list[n]
print(myans%(1000000007))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int, input().split()))
myans_list =  [ [0 for n in range(N)] for nn in range(N) ]
myans = 0
for n in range(N):
    for nn in range(N):
        myans_list[n][nn] = A_list[n] * A_list[nn]
#for n in myans_list:
#    print(n)
myans = 0
for n in range(N-1):
    for nn in range(n+1, N):
        myans += myans_list[n][nn]
print(myans%(1000000007))

Fixed submission:
N = int(input())
A_list = list(map(int, input().split()))
#myans_list =  [ [0 for n in range(N)] for nn in range(N) ]
#myans = 0
#for n in range(N):
#    for nn in range(N):
#        myans_list[n][nn] = A_list[n] * A_list[nn]
#for n in myans_list:
#    print(n)
mysum = sum(A_list)
myans = 0
for n in range(N-1):
    mysum -= A_list[n]
    myans +=  mysum*A_list[n]
print(myans%(1000000007))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


N, M = map(int,input().split())
mymap = [ [] for n in range(N) ]
for m in range(M):
    a, b = map(int, input().split())
    mymap[a-1].append(b-1)
    mymap[b-1].append(a-1)
#print(mymap)
myans = 0
for n in range(N):
    mylist = mymap[n]
    #print(mylist)
    myd = deque()
    for mm in mylist:
        myd.append(mm)
    #print(myd)
    check_list = [0 for n in range(N)]
    mycnt = 1
    check_list[n] = 1
    while myd:
        tgt = myd.popleft()
        #print(tgt)
        if check_list[tgt] == 0 :
            for e in mymap[tgt]:
                if e > n :
                    myd.append(e)
            mycnt += 1
            check_list[tgt] = 1
    if myans < mycnt:
        myans = mycnt
print(myans)

Fixed submission:
from collections import deque


N, M = map(int,input().split())
mymap = [ [] for n in range(N) ]
for m in range(M):
    a, b = map(int, input().split())
    mymap[a-1].append(b-1)
    mymap[b-1].append(a-1)
#print(mymap)
myans = 0
check_list = [0 for n in range(N)]

for n in range(N):
    mylist = mymap[n]
    #print(mylist)
    myd = deque()
    for mm in mylist:
        myd.append(mm)
    #print(myd)
    mycnt = 1
    check_list[n] = 1
    while myd:
        tgt = myd.popleft()
        #print(tgt)
        if check_list[tgt] == 0 :
            for e in mymap[tgt]:
                if e > n :
                    myd.append(e)
            mycnt += 1
            check_list[tgt] = 1
    if myans < mycnt:
        myans = mycnt
print(myans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


N, M = map(int,input().split())
mymap = [ [] for n in range(N) ]
for m in range(M):
    a, b = map(int, input().split())
    mymap[a-1].append(b-1)
    mymap[b-1].append(a-1)
#print(mymap)
myans = 0
for n in range(N):
    mylist = mymap[n]
    #print(mylist)
    myd = deque()
    for mm in mylist:
        myd.append(mm)
    #print(myd)
    check_list = [0 for n in range(N)]
    mycnt = 1
    check_list[n] = 1
    while myd:
        tgt = myd.popleft()
        #print(tgt)
        if check_list[tgt] == 0:
            for e in mymap[tgt]:
                myd.append(e)
            mycnt += 1
            check_list[tgt] = 1
    if myans < mycnt:
        myans = mycnt
print(myans)

Fixed submission:
from collections import deque


N, M = map(int,input().split())
mymap = [ [] for n in range(N) ]
for m in range(M):
    a, b = map(int, input().split())
    mymap[a-1].append(b-1)
    mymap[b-1].append(a-1)
#print(mymap)
myans = 0
check_list = [0 for n in range(N)]

for n in range(N):
    mylist = mymap[n]
    #print(mylist)
    myd = deque()
    for mm in mylist:
        myd.append(mm)
    #print(myd)
    mycnt = 1
    check_list[n] = 1
    while myd:
        tgt = myd.popleft()
        #print(tgt)
        if check_list[tgt] == 0 :
            for e in mymap[tgt]:
                if e > n :
                    myd.append(e)
            mycnt += 1
            check_list[tgt] = 1
    if myans < mycnt:
        myans = mycnt
print(myans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K  = map(int, input().split())
A_list = list(map(int, input().split()))
#print(A_list)
ans_list = [ 0 for n in range(N)]
tmp = 1
for k in range(K):
    tmp *= A_list[k]
    #print(tmp)
ans_list[K-1] = tmp
#print(ans_list)
for k in range(K, N):
    ans_list[k] = ans_list[k-1]//A_list[k-K] * A_list[k]
#print(ans_list)
for k in range(K, N):
    if ans_list[k] > ans_list[k-1]:
        print('Yes')
    else:
        print('No')

Fixed submission:
N, K  = map(int, input().split())
A_list = list(map(int, input().split()))
'''
#print(A_list)
ans_list = [ 0 for n in range(N)]
tmp = 1
for k in range(K):
    tmp *= A_list[k]
    #print(tmp)
ans_list[K-1] = tmp
#print(ans_list)
for k in range(K, N):
    ans_list[k] = ans_list[k-1]//A_list[k-K] * A_list[k]
'''
#print(ans_list)

for k in range(K, N):
    if A_list[k] > A_list[k-K]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import functools
import operator
 
N = int(input())
mylist = list(map(int,input().split()))
Π = functools.partial(functools.reduce, operator.mul)
ans = (Π(mylist))
if ans <= 10**18:
    print(ans)
else:
    print(-1)

Fixed submission:
import math
import sys
N = int(input())
mylist = list(map(int, input().split()))
mylist.sort(reverse = True)
#print(mylist)
if mylist[-1] == 0:
    print(0)
    sys.exit()
else:
    myans = 1
    for m in mylist:
        myans *= m
        if myans > 10**18:
            print(-1)
            sys.exit()
    print(myans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
mylist = list(map(int,input().split()))
if 0 in mylist:
    print(0)
    sys.exit()
else:
    ans = 1
    for i in mylist:
        ans *= i
if ans <= 10**18:
    print(ans)
else:
    print(-1)

Fixed submission:
import math
import sys
N = int(input())
mylist = list(map(int, input().split()))
mylist.sort(reverse = True)
#print(mylist)
if mylist[-1] == 0:
    print(0)
    sys.exit()
else:
    myans = 1
    for m in mylist:
        myans *= m
        if myans > 10**18:
            print(-1)
            sys.exit()
    print(myans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
mylist = map(int,input().split())
myans = 1
for m in mylist:
    myans *= m
if myans <= 10**18:
    print(myans)
else:
    print(-1)


Fixed submission:
import math
import sys
N = int(input())
mylist = list(map(int, input().split()))
mylist.sort(reverse = True)
#print(mylist)
if mylist[-1] == 0:
    print(0)
    sys.exit()
else:
    myans = 1
    for m in mylist:
        myans *= m
        if myans > 10**18:
            print(-1)
            sys.exit()
    print(myans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
A, B, C, K = map(int, input().split())

mycnt = 0
myans = 0

if A >= K:
    print(K)
    sys.exit()
else:    
    while mycnt < K:
        if A>0:
            mycnt += 1
            A -=1
            myans += 1
        elif B>0:
            mycnt += 1
            B -=1
        else:
            mycnt+=1
            myans -=1
print(myans)

Fixed submission:
import sys
A, B, C, K = map(int, input().split())

mycnt = 0
myans = 0

if A >= K:
    print(K)
    sys.exit()
elif A+B >=K:
    print(A)
else:
    print(A+(K-A-B)*-1)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N, K = map(int, input().split())


mylist =  [0] + list(map(int,input().split()))
#print(mylist)

myflag = [0 for n in range(N+1)]
#print(myflag)

myorigine = []
mypos = 1
for n in range(1,N+1):
    if myflag[n] == 0:
        myflag[n] == 1
        myorigine.append(mypos)
        mypos = mylist[mypos]
    elif myflag[n] == 1:
        break
#print(myorigine)
    
mypos = 0
while myorigine[mypos] != myorigine[-1]:
    mypos += 1
#print(mypos)
origin1 = myorigine[:mypos]
origin2 = myorigine[mypos:]
#print(origin1, origin2[:-1])


mymod = K%N
mymod = len(origin1) -1
print(origin2[mymod-1])



Fixed submission:
N, K = map(int, input().split())
mylist =   [0] + list(map(int,input().split()))
#print(mylist)
flag_list = [float('INF') for n in range(N+1)]
#print(flag_list)
myseries = []

myflag = 0
mypos = 1
mycnt = 0 
while myflag == 0:
    if flag_list[mypos] == float('INF'):
        flag_list[mypos] = mycnt
        #print(mypos)
        myseries.append(mypos)
        mypos = mylist[mypos]
        mycnt += 1
    else:
        myflag = 1
        mystart = flag_list[mypos]
        mylen = mycnt-mystart
#print(flag_list)
#print(myseries)
#print(mystart, mylen)

if K < mystart:
    print(myseries[K])
else:
    print(myseries[(K-mystart)%mylen + mystart])
Buggy python submission (verdict: Runtime Error):
S = input()
 
if S = 'ABC':
    print('ARC')
else:
    print('ABC')

Fixed submission:
S = input()
 
if S == 'ABC':
    print('ARC')
else:
    print('ABC')