Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
#import time
import copy
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**20
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = ri()
a = rl()
ans=1
for i in a:
    ans*=i
    
if ans>10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
import sys
#import time
import copy
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**20
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = ri()
a = rl()
ans=1
flag=False
for i in a:
    ans*=i
    if ans>10**18:
        flag=True
        break
   
zero=False
for i in a:
    if i==0:
        zero=True
        break
if zero:
    print(0)    
elif flag:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
start=time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
h,w = rl()
s = [list(rs()) for i in range(h)]
u=[[0]*w for i in range(h)]
b=[[0]*w for i in range(h)]
l=[[0]*w for i in range(h)]
r=[[0]*w for i in range(h)]

#縦方向
for i in range(w):
    if s[0][i]==".":
        u[0][i]=1
for i in range(w):
    for j in range(1,h):
        if s[j][i]==".":
            u[j][i]=u[j-1][i]+1
for i in range(w):
    if s[-1][i]==".":
        b[-1][i]=1
for i in range(w):
    for j in range(1,h):
        if s[-j-1][i]==".":
            b[-j-1][i]=b[-j][i]+1            
            

#横方向
for i in range(h):
    if s[i][0]==".":
        l[i][0]=1
for i in range(1,w):
    for j in range(h):
        if s[j][i]==".":
            l[j][i]=l[j][i-1]+1
for i in range(h):
    if s[i][-1]==".":
        r[i][-1]=1
for i in range(1,w):
    for j in range(h):
        if s[j][-i-1]==".":
            r[j][-i-1]=r[j][-i]+1
ans=0
for i in range(w):
    for j in range(h):
        ans=max(u[j][i]+b[j][i]+l[j][i]+r[j][i]-3, ans)
print(ans)            
    

Fixed submission:
import sys
import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
start=time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
h,w = rl()
s = [list(rs()) for i in range(h)]
u=[[0]*w for i in range(h)]
b=[[0]*w for i in range(h)]
l=[[0]*w for i in range(h)]
r=[[0]*w for i in range(h)]

#縦方向
for i in range(w):
    if s[0][i]==".":
        u[0][i]=1
for i in range(w):
    for j in range(1,h):
        if s[j][i]==".":
            u[j][i]=u[j-1][i]+1
for i in range(w):
    if s[-1][i]==".":
        b[-1][i]=1
for i in range(w):
    for j in range(1,h):
        if s[-j-1][i]==".":
            b[-j-1][i]=b[-j][i]+1            
            

#横方向
for i in range(h):
    if s[i][0]==".":
        l[i][0]=1
for i in range(1,w):
    for j in range(h):
        if s[j][i]==".":
            l[j][i]=l[j][i-1]+1
for i in range(h):
    if s[i][-1]==".":
        r[i][-1]=1
for i in range(1,w):
    for j in range(h):
        if s[j][-i-1]==".":
            r[j][-i-1]=r[j][-i]+1
ans=0
for i in range(w):
    for j in range(h):
        ans=max(u[j][i]+b[j][i]+l[j][i]+r[j][i]-3, ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

stdin = sys.stdin

ni = lambda: int(ns()) #int
na = lambda: list(map(int, stdin.readline().split())) #int,list
ns = lambda: stdin.readline().rstrip()  # str

n,m=na()
a=na()
for i in range(m):
	b,c=na()
	a.extend([c]*b)

print(sum(sorted(a)[-n:]))

Fixed submission:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n,m = rl()
a = rl()

li=dict(Counter(a))
for _ in range(m):
    b, c = rl()
    if c in li:
        li[c]+=b
    else:
        li[c]=b
li=sorted(li.items(),key=lambda x: -x[0])
ans=0
res=n
for pair in li:
    if res<=0:
        continue
    if res>=pair[1]:
        ans+=pair[0]*pair[1]
        res-=pair[1]
    else:
        ans+=pair[0]*res
        res=0
print(ans)

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

stdin = sys.stdin

ni = lambda: int(ns()) #int
na = lambda: list(map(int, stdin.readline().split())) #int,list
ns = lambda: stdin.readline().rstrip()  # str

n,m=na()
a=na()
for i in range(m):
	b,c=na()
	for i in range(b):
		a.append(c)

print(sum(sorted(a)[-n:]))

Fixed submission:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n,m = rl()
a = rl()

li=dict(Counter(a))
for _ in range(m):
    b, c = rl()
    if c in li:
        li[c]+=b
    else:
        li[c]=b
li=sorted(li.items(),key=lambda x: -x[0])
ans=0
res=n
for pair in li:
    if res<=0:
        continue
    if res>=pair[1]:
        ans+=pair[0]*pair[1]
        res-=pair[1]
    else:
        ans+=pair[0]*res
        res=0
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ni = lambda: int(ns()) #int
na = lambda: list(map(int, stdin.readline().split())) #int,list
ns = lambda: stdin.readline().rstrip()  # str

n,k = na()
s=ns()
print(s.replace(s[k+1],s[k+1].lower()))

Fixed submission:
import sys

stdin = sys.stdin

ni = lambda: int(ns()) #int
na = lambda: list(map(int, stdin.readline().split())) #int,list
ns = lambda: stdin.readline().rstrip()  # str

n,k = na()
s=ns()
print(s[:k-1]+s[k-1].lower()+s[k:])
Buggy python submission (verdict: Runtime Error):
zimport sys
import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
start=time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
a,b = rl()
c=a%4
d=b%4
ans=0
for i in range(4-c):
    ans^=a+i
for i in range(d+1):
    ans^=b-i
print(ans)

Fixed submission:
import sys
import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
start=time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
a,b = rl()
c=a%4
d=b%4
ans=0
for i in range(4-c):
    ans^=a+i
for i in range(d+1):
    ans^=b-i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A,B = map(int,input().split())
li=[]
for i in range(A,B+1):
	li.append(format(i,"b"))
bin_sum=0
for i in li:
	bin_sum+=int(i)
	bin_sum=int(str(bin_sum).replace("2","0"))

print(int(str(bin_sum),2))

Fixed submission:
import sys
import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
start=time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
a,b = rl()
c=a%4
d=b%4
ans=0
for i in range(4-c):
    ans^=a+i
for i in range(d+1):
    ans^=b-i
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B = list(map(int,input().split()))
if (A==0) or (B == 0);
	print(A-B)

elif B%A ==0 :
	print(A+B)

else:
	print(A-B)

Fixed submission:
A, B = list(map(int,input().split()))

if B%A ==0:
	print(A+B)

else:
	print(B-A)

Buggy python submission (verdict: Runtime Error):
A, B = list(map(int,input().split()))
if A or B == 0;
	print(A-B)

elif B%A ==0 :
	print(A+B)

else:
	print(A-B)

Fixed submission:
A, B = list(map(int,input().split()))

if B%A ==0:
	print(A+B)

else:
	print(B-A)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
#import time
#import copy
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
import heapq
import time

start = time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
q = ri()
lr = [rl() for _ in range(q)]

def Is_prime(n):
    if n<2:return False
    elif n==2:return True
    elif n>3 and n%2==0:return False
    for i in range(3, n):
        if i*i>n:
            break
        if n%i==0:return False
    return True

for j in lr:
    ans=0
    for i in range(j[0], j[1]+1):
        if i%2==0:continue
        if Is_prime(i) and Is_prime((i+1)//2):ans+=1
    print(ans)

Fixed submission:
import sys
#import time
#import copy
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
import heapq
import time

start = time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
q = ri()
lr = [rl() for _ in range(q)]

def Is_prime(n):
    if n<2:return False
    elif n==2:return True
    elif n>3 and n%2==0:return False
    for i in range(3, n):
        if i*i>n:
            break
        if n%i==0:return False
    return True

dp=[0]*(10**5+1)
for i in range(1,10**5+1):
    if i%2==0:
        dp[i]=dp[i-1]
    if Is_prime(i) and Is_prime((i+1)//2):
        dp[i]=dp[i-1]+1
    else:
        dp[i]=dp[i-1]

for j in lr:
    print(dp[j[1]]-dp[j[0]-1])
Buggy python submission (verdict: Runtime Error):
import itertools
import bisect
n = int(input())
#a=sorted(list(map(int, input().split())))
b=sorted(list(map(int, input().split())))
c=sorted(list(map(int, input().split())))
cnt=0

for i in range(0,len(c)):
    b_index=bisect.bisect_left(b,c[-i-1])
    for u in range(b_index):
        cnt+=bisect.bisect_left(a,b[b_index-1-u])
    
print(cnt)

Fixed submission:
import itertools
import bisect
n = int(input())
a=sorted(list(map(int, input().split())))
b=sorted(list(map(int, input().split())))
c=sorted(list(map(int, input().split())))
cnt=0

for i in range(0,len(b)):
    a_index = bisect.bisect_left(a,b[i])
    c_index = bisect.bisect_right(c,b[i])
    cnt+=a_index*(len(c)-c_index)
    
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import bisect
n = int(input())
a=sorted(list(map(int, input().split())))
b=sorted(list(map(int, input().split())))
c=sorted(list(map(int, input().split())))
cnt=0

for i in range(0,len(c)):
    b_index=bisect.bisect_left(b,c[-i-1])
    for u in range(b_index):
        cnt+=bisect.bisect_left(a,b[b_index-1-u])
    
print(cnt)

Fixed submission:
import itertools
import bisect
n = int(input())
a=sorted(list(map(int, input().split())))
b=sorted(list(map(int, input().split())))
c=sorted(list(map(int, input().split())))
cnt=0

for i in range(0,len(b)):
    a_index = bisect.bisect_left(a,b[i])
    c_index = bisect.bisect_right(c,b[i])
    cnt+=a_index*(len(c)-c_index)
    
print(cnt)
Buggy python submission (verdict: Runtime Error):
n,k = list(map(int, input().split()))
a=list(map(int, input().split()))

ans=[]
    


for i in range(1<<n):
    
    if bin(i).count("1")==k:
        cst=0
        use=a.copy()
        for u in range(1,n):
            if(i>>u&1):
                left_max=max(use[:u])
                cst+=left_max-use[u]+1
                use[u]= left_max+1
        ans.append(cst)   
print(min(ans))


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

ans=[]
for i in range(1<<n):
    
    if bin(i).count("1")==k:
        cst=0
        use=a.copy()
        for u in range(1,n):
            if(i>>u&1):
                left_max=max(use[:u])
                cst+=left_max-use[u]+1 if left_max>=use[u] else 0
                use[u]= max(left_max+1, use[u])
        ans.append(cst)
print(min(ans))

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

ans=[]
    


for i in range(1<<n):
    
    if bin(i).count("1")==k:
        cst=0
        use=a.copy()
        for u in range(1,n):
            if(i>>u&1):
                left_max=max(use[:u])
                cst+=left_max-use[u]+1
                use[u]= left_max+1
        ans.append(cst)   
print(min(ans))


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

ans=[]
for i in range(1<<n):
    
    if bin(i).count("1")==k:
        cst=0
        use=a.copy()
        for u in range(1,n):
            if(i>>u&1):
                left_max=max(use[:u])
                cst+=left_max-use[u]+1 if left_max>=use[u] else 0
                use[u]= max(left_max+1, use[u])
        ans.append(cst)
print(min(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

R = s.count('R')
G = s.count('G')
B = n - R - G

err = 0
for i in range(n - 2):
    span = 1
    while i + 2 * span < n:
        if all([s[i + span * t] for t in range(3)].count(c) for c in ['R', 'G', 'B']):
            err += 1
        span += 1

print(R * G * B - err)

Fixed submission:
n = int(input())
s = input()

R = s.count('R')
G = s.count('G')
B = n - R - G

err = 0
for i in range(n - 2):
    span = 1
    while i + 2 * span < n:
        if s[i] != s[i + span] and s[i + span] != s[i + 2 * span] and s[i + 2 * span] != s[i]:
            err += 1
        span += 1

print(R * G * B - err)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

R = s.count('R')
G = s.count('G')
B = n - R - G

err = 0
for i in range(n - 2):
    span = 1
    while i + 2 * span < n:
        if all([s[i + span * t] for t in range(3)].count(c) for c in ['R', 'G', 'B']):
            err += 1
        span += 1

print(R * G * B - err)

Fixed submission:
n = int(input())
s = input()

R = s.count('R')
G = s.count('G')
B = n - R - G

err = 0
for i in range(n - 2):
    span = 1
    while i + 2 * span < n:
        if s[i] != s[i + span] and s[i + span] != s[i + 2 * span] and s[i + 2 * span] != s[i]:
            err += 1
        span += 1

print(R * G * B - err)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

cnt = 0
for i in range(q):
    a = [i for i in input().split()]
    if a[0] == '1':
        cnt += 1
    else:
        if (a[1] == '1' and cnt % 2 == 0) or (a[1] == '2' and cnt % 2 == 1):
            s = a[2] + s
        else:
            s = s + a[2]

if cnt % 2 == 0:
    print(s)
else:
    print(''.join(list(reversed(s))))


Fixed submission:
s = input()
q = int(input())

cnt = 0
left = []
right = []
for j in range(q):
    a = [str(i) for i in input().split()]
    if a[0] == '1':
        cnt += 1
    else:
        if (a[1] == '1' and cnt % 2 == 0) or (a[1] == '2' and cnt % 2 == 1):
            right.append(a[2])
        else:
            left.append(a[2])

if cnt % 2 == 0:
    print(''.join(reversed(right)) + s + ''.join(left))
else:
    print(''.join(reversed(left)) + ''.join(list(reversed(s))) + ''.join(right))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]

mod = 10 ** 9 + 7

cnt = [0] * 60
for i in range(n):
    for j in range(60):
        cnt[j] += a[i] % 2
        a[i] = a[i] // 2

ans = 0
for i in range(60):
    ans = (ans + (2 ** i) * cnt[i] * (n - cnt[i])) % mod

print(ans)


Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]

mod = 10 ** 9 + 7

j_max = 0
cnt = [0] * 60
for i in range(n):
    for j in range(60):
        cnt[j] += a[i] % 2
        a[i] = a[i] // 2
        if a[i] == 0:
            j_max = max(j_max, j)
            break

ans = 0
for i in range(j_max + 1):
    ans = (ans + (2 ** i) * cnt[i] * (n - cnt[i])) % mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]

sum = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        sum += int(a[i] ^ a[j]) % (10 ** 9 + 7)

print(sum % (10 ** 9 + 7))


Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]

mod = 10 ** 9 + 7

j_max = 0
cnt = [0] * 60
for i in range(n):
    for j in range(60):
        cnt[j] += a[i] % 2
        a[i] = a[i] // 2
        if a[i] == 0:
            j_max = max(j_max, j)
            break

ans = 0
for i in range(j_max + 1):
    ans = (ans + (2 ** i) * cnt[i] * (n - cnt[i])) % mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]

sum = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        sum += int(a[i] ^ a[j])

print(sum % (10 ** 9 + 7))


Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]

mod = 10 ** 9 + 7

j_max = 0
cnt = [0] * 60
for i in range(n):
    for j in range(60):
        cnt[j] += a[i] % 2
        a[i] = a[i] // 2
        if a[i] == 0:
            j_max = max(j_max, j)
            break

ans = 0
for i in range(j_max + 1):
    ans = (ans + (2 ** i) * cnt[i] * (n - cnt[i])) % mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = [int(i) for i in input().split()]

if d[0] != 0 or d.count(0) > 1:
    print(0)
    exit()

ans = 1
for i in range(1, max(d) + 1):
    ans *= d.count(i - 1) ** d.count(i)

print(ans % 998244353)

Fixed submission:
from collections import Counter

n = int(input())
d = [int(i) for i in input().split()]
c = Counter(d)

if d[0] != 0 or c[0] > 1:
    print(0)
    exit()

ans = 1
for i in range(1, len(c) + 1):
    ans *= c[i - 1] ** c[i]

print(ans % 998244353)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n, q = map(int, (input().split()))

t = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, (input().split()))
    t[a].append(b)
    t[b].append(a)

cnt = [0 for i in range(n + 1)]
for i in range(q):
    p, x = map(int, (input().split()))
    cnt[p] += x

d = deque()
d.append(1)
chked = []
while d:
    stat = d.pop()
    chked.append(stat)
    for v in t[stat]:
        if v not in chked:
            d.append(v)
            cnt[v] += cnt[stat]

print(*cnt[1:])


Fixed submission:
from collections import deque

n, q = map(int, (input().split()))

t = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, (input().split()))
    t[a].append(b)
    t[b].append(a)

cnt = [0 for i in range(n + 1)]
for i in range(q):
    p, x = map(int, (input().split()))
    cnt[p] += x

d = deque()
d.append(1)
chked = set()
while d:
    stat = d.pop()
    chked.add(stat)
    for v in t[stat]:
        if v not in chked:
            d.append(v)
            cnt[v] += cnt[stat]

print(*cnt[1:])
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, (input().split()))
print(max(c - (a - b), 0))
a, b, c = map(int, (input().split()))
print(max(c - (a - b), 0))
a, b, c = map(int, (input().split()))
print(max(c - (a - b), 0))
a, b, c = map(int, (input().split()))
print(max(c - (a - b), 0))
a, b, c = map(int, (input().split()))
print(max(c - (a - b), 0))
a, b, c = map(int, (input().split()))
print(max(c - (a - b), 0))
a, b, c = map(int, (input().split()))
print(max(c - (a - b), 0))
a, b, c = map(int, (input().split()))
print(max(c - (a - b), 0))
a, b, c = map(int, (input().split()))
print(max(c - (a - b), 0))
a, b, c = map(int, (input().split()))
print(max(c - (a - b), 0))


Fixed submission:
a, b, c = map(int, (input().split()))
print(max(c - (a - b), 0))
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, (input().split()))
s = input()

tbl = [0] * n
for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        tbl[i] = 1

for i in range(q):
    l, r = map(int, input().split())
    print(sum(tbl[l - 1:r - 1]))


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

tbl = [0] * n
cnt = 0
for i in range(1, n):
    if s[i - 1] == 'A' and s[i] == 'C':
        cnt += 1
    tbl[i] = cnt

for i in range(q):
    l, r = map(int, input().split())
    print(tbl[r - 1] - tbl[l - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, (input().split()))
s = input()
lst = [list(map(int, input().split())) for i in range(q)]

for i in range(q):
    print(s[lst[i][0] - 1:lst[i][1]].count('AC'))


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

tbl = [0] * n
cnt = 0
for i in range(1, n):
    if s[i - 1] == 'A' and s[i] == 'C':
        cnt += 1
    tbl[i] = cnt

for i in range(q):
    l, r = map(int, input().split())
    print(tbl[r - 1] - tbl[l - 1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = [int(i) for i in input().split()]

if all([i % min(lst) == 0 for i in lst]):
    print(min(lst))
    exit()

gcm = 1
j = 2
lmt = int(min(lst) ** 0.5) + 1
while j <= lmt:
    if all([i % j == 0 for i in lst]):
        lst = [i / j for i in lst]
        gcm *= j
    else:
        j += 1

print(gcm)


Fixed submission:
from functools import reduce

n = int(input())
lst = [int(i) for i in input().split()]


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


print(reduce(gcd, lst))
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, (input().split()))
lst = [list(map(int, input().split())) for i in range(n)]

dp = [0] * (w + 1)

for i in range(n):
    for j in range(w, lst[i][0] - 1, -1):
        dp[j] = max(dp[j - lst[i][0]] + lst[i][1], dp[j])

print(dp[w])


Fixed submission:
n, w = map(int, (input().split()))
lst = [list(map(int, input().split())) for i in range(n)]

dp = [0] * (w + 1)

for i in range(n):
    for j in range(w, lst[i][0] - 1, -1):
        dp[j] = max(dp[j - lst[i][0]] + lst[i][1], dp[j])

print(dp[w])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort()
L.reverse()
C = 0

for i in range(N-2):
	for j in range(i+1, N-1):
		M = L[j+1::]
		k = 0
		while k<len(M) and M[k]>(L[i]-L[j]):
			k += 1
			C += 1
				
print(C)


Fixed submission:
from bisect import bisect
from bisect import bisect_left

_ = input()
l = input()
l = sorted(list(map(int, l.split())))
count = 0

for i in range(len(l)):
	for j in range(i+1, len(l)):
		c = l[i]+l[j]
		count += bisect_left(l,c) - (j+1)

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort()
L.reverse()
C = 0

for i in range(N-2):
	for j in range(i+1, N-1):
		K = L[j+1::]
		K = list(filter(lambda x:x>(L[i]-L[j]), K))
		C += len(K)
				
print(C)


Fixed submission:
from bisect import bisect
from bisect import bisect_left

_ = input()
l = input()
l = sorted(list(map(int, l.split())))
count = 0

for i in range(len(l)):
	for j in range(i+1, len(l)):
		c = l[i]+l[j]
		count += bisect_left(l,c) - (j+1)

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
C = 0

for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      if L[i]<(L[j]+L[k]) and L[j]<(L[i]+L[k]) and L[k]<(L[i]+L[j]):
        C += 1
        
print(C)

Fixed submission:
from bisect import bisect
from bisect import bisect_left

_ = input()
l = input()
l = sorted(list(map(int, l.split())))
count = 0

for i in range(len(l)):
	for j in range(i+1, len(l)):
		c = l[i]+l[j]
		count += bisect_left(l,c) - (j+1)

print(count)