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

def lcm(x, y):
   lcm = (x*y)//gcd(x,y)
   return lcm

n = int(input())
ans1 = 1
for _ in range(n):
    t=int(input())
    ans1 = lcm(ans1, t)
print(ans1)

Fixed submission:
from fractions import gcd

def lcm(x, y):
   lcm = (x*y)//gcd(x,y)
   return lcm

n = int(input())
ans1 = 1
for _ in range(n):
    t=int(input())
    ans1 = lcm(ans1, t)
print(ans1)

Buggy python submission (verdict: Runtime Error):
from math import gcd

def lcm(x, y):
   lcm = (x*y)//gcd(x,y)
   return lcm

n = int(input())
ans1 = 1
for _ in range(n):
    t=int(input())
    ans1 = lcm(ans1, t)
print(ans1)

Fixed submission:
from fractions import gcd

def lcm(x, y):
   lcm = (x*y)//gcd(x,y)
   return lcm

n = int(input())
ans1 = 1
for _ in range(n):
    t=int(input())
    ans1 = lcm(ans1, t)
print(ans1)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,m = [int(v) for v in input().split()]
    if m==0:
        print(1)
        return
    groups = []
    g = [-1]*(n+1)
    for _ in range(m):
        a,b = [int(v) for v in input().split()]
        if g[a]!=-1 and g[b]!=-1:
            if g[a]==g[b]: continue
            gb = g[b]
            for no in groups[gb]:
                g[no] = g[a]
                groups[g[a]].append(no)
            groups[gb] = []
        elif g[a]!=-1:
            g[b] = g[a]
            groups[g[a]].append(b)
        elif g[b]!=-1:
            g[a] = g[b]
            groups[g[b]].append(a)
        else:
            g[a] = g[b] = len(groups)
            groups.append([a,b])
    # print(groups, g)
    ans = max([len(v) for v in groups])
    print(ans)

main()


Fixed submission:
def main():
    n,m = [int(v) for v in input().split()]
    if m==0:
        print(1)
        return
    
    g = [set() for _ in range(n+1)]
    seen = [False] * (n+1)
    for _ in range(m):
        a,b = [int(v) for v in input().split()]
        g[a].add(b)
        g[b].add(a)

    ans = 0
    for i in range(1,n+1):
        if seen[i]: continue
        stack = set([i])
        l = 0
        while len(stack)>0:
            no = stack.pop()
            seen[no] = True
            l += 1
            for nn in g[no]:
                if not seen[nn]:
                    stack.add(nn)
        ans = max(ans, l)

    # print(groups, g)
    print(ans)

main()

Buggy python submission (verdict: Runtime Error):
def main():
    n,m = [int(v) for v in input().split()]
    groups = []
    g = [-1]*(n+1)
    for _ in range(m):
        a,b = [int(v) for v in input().split()]
        if g[a]!=-1 and g[b]!=-1:
            if g[a]==g[b]: continue
            gb = g[b]
            for no in groups[gb]:
                g[no] = g[a]
            groups[gb] = {}
        elif g[a]!=-1:
            g[b] = g[a]
            groups[g[a]].append(b)
        elif g[b]!=-1:
            g[a] = g[b]
            groups[g[b]].append(a)
        else:
            g[a] = g[b] = len(groups)
            groups.append([a,b])
    # print(groups, g)
    ans = max([len(v) for v in groups])
    print(ans)

main()

Fixed submission:
def main():
    n,m = [int(v) for v in input().split()]
    if m==0:
        print(1)
        return
    
    g = [set() for _ in range(n+1)]
    seen = [False] * (n+1)
    for _ in range(m):
        a,b = [int(v) for v in input().split()]
        g[a].add(b)
        g[b].add(a)

    ans = 0
    for i in range(1,n+1):
        if seen[i]: continue
        stack = set([i])
        l = 0
        while len(stack)>0:
            no = stack.pop()
            seen[no] = True
            l += 1
            for nn in g[no]:
                if not seen[nn]:
                    stack.add(nn)
        ans = max(ans, l)

    # print(groups, g)
    print(ans)

main()
Buggy python submission (verdict: Runtime Error):
def main():
    nmax = 100000
    n = int(input())
    values = [0] * nmax
    a = [int(v) for v in input().split()]
    for v in a:
        values[v-1] += 1
    asum = sum(a)

    q = int(input())
    for _ in range(q):
        b, c = [int(v) for v in input().split()]
        asum += values[b-1] * (c - b)
        values[c-1] += values[b-1]
        values[b-1] = 0
        print(asum)

main()

Fixed submission:
def main():
    c = input()
    if c>='a' and c<='z':
        print('a')
    else:
        print('A')

main()
Buggy python submission (verdict: Runtime Error):
def main():
    nmax = 10000
    n = int(input())
    values = [0] * nmax
    a = [int(v) for v in input().split()]
    for v in a:
        values[v-1] += 1
    asum = sum(a)

    q = int(input())
    for _ in range(q):
        b, c = [int(v) for v in input().split()]
        asum += values[b-1] * (c - b)
        values[c-1] += values[b-1]
        values[b-1] = 0
        print(asum)

main()

Fixed submission:
def main():
    nmax = 100000
    n = int(input())
    values = [0] * nmax
    a = [int(v) for v in input().split()]
    for v in a:
        values[v-1] += 1
    asum = sum(a)

    q = int(input())
    for _ in range(q):
        b, c = [int(v) for v in input().split()]
        asum += values[b-1] * (c - b)
        values[c-1] += values[b-1]
        values[b-1] = 0
        print(asum)

main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    a = [int(v) for v in input().split()]
    for j in range(n):
        x = 0
        for i in range(0, j):
            x ^= a[i]
        for i in range(j+1, n):
            x ^= a[i]
        print(x)

main()

Fixed submission:
def main():
    n = int(input())
    a = [int(v) for v in input().split()]
    x = 0
    for i in range(n):
        x ^= a[i]
    for i in range(n):
        print(x ^ a[i])

main()
Buggy python submission (verdict: Runtime Error):
x = input()
y = input()
x = int(x)
y = int(y)

if x >= y:
    print(10)
else:
    print(0)

Fixed submission:
x, y= map(int, input().split())

if x >= y:
    print(10)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
x = input()
y = input()

if x >= y:
    print(10)
else:
    print(0)

Fixed submission:
x, y= map(int, input().split())

if x >= y:
    print(10)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
N = int(input())
alphabet_lst = list('abcdefghijklmnopqrstuvwxyz')
#print(alphabet_lst)

keta = 0
keta_lst = []
while N>=sum(keta_lst):
    keta_lst.append(26**keta)
    keta += 1
    
keta -= 1
keta_lst = keta_lst[:keta]
#print(keta_lst)
#print(keta)

ans_lst = []
for i in range(keta):
    ans_n = N // keta_lst[-(i+1)]
    #print(ans_n)
    #print(keta_lst[-(i+1)])
    N -= ans_n*keta_lst[-(i+1)]
    ans_lst.append(alphabet_lst[ans_n-1])

for i in range(keta):
    print(ans_lst[i],end="")

Fixed submission:
N = int(input())
alphabet_lst = list('abcdefghijklmnopqrstuvwxyz')
#print(alphabet_lst)

keta = 0
keta_lst = []
sum_lst = []
while N>=sum(keta_lst):
    keta_lst.append(26**keta)
    sum_keta = sum(keta_lst)
    sum_lst.append(sum_keta)
    keta += 1
    
keta -= 1
keta_lst = keta_lst[:keta]
#print(keta_lst)
#print(keta)

ans_lst = []
for i in range(keta):
    ans_n = (N - sum(keta_lst[:-(i+1)])) // keta_lst[-(i+1)]
    #print(ans_n)
    #print(keta_lst[-(i+1)])
    N -= ans_n*keta_lst[-(i+1)]
    ans_lst.append(alphabet_lst[ans_n-1])

for i in range(keta):
    print(ans_lst[i],end="")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

keihin = []

for i in range(N):
    s = input()
    if s in keihin:
        pass
    else:
        keihin.append(s)
    
print(len(keihin))

Fixed submission:
N = int(input())

keihin = []

for i in range(N):
    keihin.append(input())
    
print(len(set(keihin)))
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

K = int(input())

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

ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for l in range(1,K+1):
            ans += gcd(i,j,l)
            
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):
        for l in range(1,K+1):
            ans += math.gcd(math.gcd(i,j),l)
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

def D_160():
    N, X, Y = map(int, input().split())
    count_list = [[0]*N for i in range(N)]
    for i in range(0,N):
        for j in range(i,N):
            count_list[i][j] = min(j-i,abs(X-1-i) + abs(j-(Y-1)) + 1)
    
    #print(count_list)
    count_list = sum(count_list,[])
    
    for i in range(1,N):
        print(count_list.count(i))

D_160()

Fixed submission:

def D_160():
    N, X, Y = map(int, input().split())
    #count_list = [[0]*N for i in range(N)]
    ans = [0 for i in range(N-1)]
    for i in range(0,N):
        for j in range(1+i,N):
            ans_i = min(j-i,abs((X-1)-i) + abs(j-(Y-1)) + 1)
            ans[ans_i-1] += 1
    
    
    for i in ans:
        print(i)

D_160()

Buggy python submission (verdict: Runtime Error):
import numpy as np
from numba import njit
@nJit
def D_160():
    N, X, Y = map(int, input().split())
    count_list = [[0]*N for i in range(N)]
    for i in range(0,N):
        for j in range(i,N):
            count_list[i][j] = min(j-i,abs(X-1-i) + abs(j-(Y-1)) + 1)
    
    #print(count_list)
    count_list = sum(count_list,[])
    
    for i in range(1,N):
        print(count_list.count(i))

D_160()

Fixed submission:

def D_160():
    N, X, Y = map(int, input().split())
    #count_list = [[0]*N for i in range(N)]
    ans = [0 for i in range(N-1)]
    for i in range(0,N):
        for j in range(1+i,N):
            ans_i = min(j-i,abs((X-1)-i) + abs(j-(Y-1)) + 1)
            ans[ans_i-1] += 1
    
    
    for i in ans:
        print(i)

D_160()

Buggy python submission (verdict: Runtime Error):
from numba import njit
@nJit
def D_160():
    N, X, Y = map(int, input().split())
    count_list = [[0]*N for i in range(N)]
    for i in range(0,N):
        for j in range(i,N):
            count_list[i][j] = min(j-i,abs(X-1-i) + abs(j-(Y-1)) + 1)
    
    #print(count_list)
    count_list = sum(count_list,[])
    
    for i in range(1,N):
        print(count_list.count(i))

D_160()

Fixed submission:

def D_160():
    N, X, Y = map(int, input().split())
    #count_list = [[0]*N for i in range(N)]
    ans = [0 for i in range(N-1)]
    for i in range(0,N):
        for j in range(1+i,N):
            ans_i = min(j-i,abs((X-1)-i) + abs(j-(Y-1)) + 1)
            ans[ans_i-1] += 1
    
    
    for i in ans:
        print(i)

D_160()

Buggy python submission (verdict: Time Limit Exceeded):
def D_160():
    import itertools
    import collections
    N, X, Y = map(int, input().split())
    count_list = [[0]*N for i in range(N)]
    for i in range(0,N):
        for j in range(i,N):
            count_list[i][j] = min(j-i,abs(X-1-i) + abs(j-(Y-1)) + 1)
    
   # print(count_list)
    count_list = sum(count_list,[])
    
    for i in range(1,N):
        print(count_list.count(i))

D_160()

Fixed submission:

def D_160():
    N, X, Y = map(int, input().split())
    #count_list = [[0]*N for i in range(N)]
    ans = [0 for i in range(N-1)]
    for i in range(0,N):
        for j in range(1+i,N):
            ans_i = min(j-i,abs((X-1)-i) + abs(j-(Y-1)) + 1)
            ans[ans_i-1] += 1
    
    
    for i in ans:
        print(i)

D_160()
Buggy python submission (verdict: Runtime Error):

def main():
    from itertools import product

    H,W,K = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    i = 0
    while i < len(S):
        if '1' in S[i]:
            i += 1
        else:
            del S[i]
    H = len(S)
 
    S = [[int(s[i]) for s in S] for i in range(W)]

    if sum(sum(s) for s in S)<=K:
        print(0)
    else:
        answer = (H-1) * (W-1)
        for X in product([False,True], repeat=H-1):
            ans = np.sum(X)
            if ans >= answer:
                continue
            M = [[0]]
            for i, x in enumerate(X):
                if x:
                    M.append([])
                M[-1].append(i+1)
            D = [0]*len(M)
            for s in S:
                for k, m in enumerate(M):
                    D[k] += sum(s[i] for i in m)
                if any(d > K  for d in D):
                    ans += 1
                    if ans >= answer:
                        break
                    for k, m in enumerate(M):
                        D[k] = sum(s[i] for i in m)
                    
                    if any(d > K for d in D):
                        ans = answer + 1
                        break

            answer = min(answer,ans)

        print(answer)

main()

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

print(int((A*(A-1))/2+(B*(B-1))/2))
Buggy python submission (verdict: Runtime Error):
weight_num = int(input())
weight_list = input().split(" ")
t = int(input())
heavy_list = []
light_list = []
for i in range(len(weight_list)):
    weight_list[i] = int(weight_list[i])

    if i>=t:
        heavy_list.append(weight_list[i])
    else:
        light_list.append(weight_list[i])

s1=sum(heavy_list)
s2=sum(light_list)
if (s1-s2)>0:
    print(s1-s2)
else:
    print(s2-s1)

Fixed submission:
weight_num = int(input())
weight_list = input().split(" ")
heavy_list = []
light_list = []
s1 = 0
s2 = 0
for i in range(len(weight_list)):
    weight_list[i] = int(weight_list[i])
max_sum = sum(weight_list)
for i in range(len(weight_list)):
    s1 += weight_list[i]
    s2 = sum(weight_list[i+1:])
    if (s1-s2)>0:
        absolute_num1 = s1-s2 
        s1 -= weight_list[i]
        s2 = sum(weight_list[i:])
        absolute_num2 = s2-s1
        if absolute_num1>absolute_num2:
            print(absolute_num2)
        else:
            print(absolute_num1)
        break
    else:
        pass

Buggy python submission (verdict: Runtime Error):
weight_num = int(input())
weight_list = input().split(" ")
t = int(input())
heavy_list = []
light_list = []
for i in range(len(weight_list)):
    weight_list[i] = int(weight_list[i])

    if i>=t:
        heavy_list.append(weight_list[i])
    else:
        light_list.append(weight_list[i])

s1=sum(heavy_list)
s2=sum(light_list)
if s1-s2>0:
    print(s1-s2)
else:
    print(s2-s1)

Fixed submission:
weight_num = int(input())
weight_list = input().split(" ")
heavy_list = []
light_list = []
s1 = 0
s2 = 0
for i in range(len(weight_list)):
    weight_list[i] = int(weight_list[i])
max_sum = sum(weight_list)
for i in range(len(weight_list)):
    s1 += weight_list[i]
    s2 = sum(weight_list[i+1:])
    if (s1-s2)>0:
        absolute_num1 = s1-s2 
        s1 -= weight_list[i]
        s2 = sum(weight_list[i:])
        absolute_num2 = s2-s1
        if absolute_num1>absolute_num2:
            print(absolute_num2)
        else:
            print(absolute_num1)
        break
    else:
        pass
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if b-a<k:
  if c-a<k:
    if d-a<k:
      if e-a<k:
        print("Yay!")
      else:
        print(":(")
        break
    else:
      print(":(")
      break
  else:
    print(":(")
    break
else:
  print(":(")
  break
 

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e-a<=k:
  print("Yay!")
else:
  print(":(")
Buggy python submission (verdict: Runtime Error):
population = int(input())
a2b = int(input())
b2c = int(input())
c2d = int(input())
d2e = int(input())
e2f = int(input())
vehicle_min = min(vehicle)
vehicle = [a2b,b2c,c2d,d2e,e2f]

print(int(population/vehicle_min) + 5)

Fixed submission:
import math
population = int(input())
a2b = int(input())
b2c = int(input())
c2d = int(input())
d2e = int(input())
e2f = int(input())
city = [population,0,0,0,0,0]
vehicle = [a2b,b2c,c2d,d2e,e2f]
print(math.ceil(population/min(vehicle)) + 4)

Buggy python submission (verdict: Runtime Error):
population = int(input())
a2b = int(input())
b2c = int(input())
c2d = int(input())
d2e = int(input())
e2f = int(input())

vehicle = [a2b,b2c,c2d,d2e,e2f]

print(int(population/vehicle_min) + 5)

Fixed submission:
import math
population = int(input())
a2b = int(input())
b2c = int(input())
c2d = int(input())
d2e = int(input())
e2f = int(input())
city = [population,0,0,0,0,0]
vehicle = [a2b,b2c,c2d,d2e,e2f]
print(math.ceil(population/min(vehicle)) + 4)

Buggy python submission (verdict: Time Limit Exceeded):
population = int(input())
a2b = int(input())
b2c = int(input())
c2d = int(input())
d2e = int(input())
e2f = int(input())
city = [population,0,0,0,0,0]
vehicle = [a2b,b2c,c2d,d2e,e2f]
time = 0
while(city[5]!=population):
    for i in range(5):
        if city[4-i] >= vehicle[4-i]:
            city[5-i] += vehicle[4-i]
            city[4-i] -= vehicle[4-i]
        else:
            city[5-i] += city[4-i]
            city[4-i] = 0
    time += 1

print(time)

Fixed submission:
import math
population = int(input())
a2b = int(input())
b2c = int(input())
c2d = int(input())
d2e = int(input())
e2f = int(input())
city = [population,0,0,0,0,0]
vehicle = [a2b,b2c,c2d,d2e,e2f]
print(math.ceil(population/min(vehicle)) + 4)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
sec = []
for i in range(k):
  l,r = map(int,input().split())
  sec.append([l,r])

dp = [0]*(n+1)
dp[0],dp[1] = 0,1
cumsum = [0]*(n+1)
cumsum[1] = 1
for i in range(2,n+1):
  for l,r in sec:
    if i>l:
      dp[i] += cumsum[i-l]-cumsum[max(0,i-r-1)]
  cumsum[i] = dp[i]+cumsum[i-1]
print(dp[n]%998244353)

Fixed submission:
n,k = map(int,input().split())
sec = []
for i in range(k):
  l,r = map(int,input().split())
  sec.append([l,r])

mod = 998244353
dp = [0]*(n+1)
dp[0],dp[1] = 0,1
cumsum = [0]*(n+1)
cumsum[1] = 1
for i in range(2,n+1):
  for l,r in sec:
    if i>l:
      dp[i] += cumsum[i-l]-cumsum[max(0,i-r-1)]
  cumsum[i] = (dp[i]+cumsum[i-1])%mod
print(dp[n]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
sec = []
for i in range(k):
  l,r = map(int,input().split())
  sec.append([l,r])

dp = [0]*(n+1)
dp[0],dp[1] = 0,1
cumsum = [0]*(n+1)
cumsum[1] = 1
for i in range(2,n+1):
  for l,r in sec:
    if i>l:
      dp[i] += cumsum[i-l]-cumsum[max(0,i-r-1)]
  cumsum[i] = dp[i]+cumsum[i-1]
print(dp[n]%998244353)

Fixed submission:
n,k = map(int,input().split())
sec = []
for i in range(k):
  l,r = map(int,input().split())
  sec.append([l,r])

mod = 998244353
dp = [0]*(n+1)
dp[0],dp[1] = 0,1
cumsum = [0]*(n+1)
cumsum[1] = 1
for i in range(2,n+1):
  for l,r in sec:
    if i>l:
      dp[i] += cumsum[i-l]-cumsum[max(0,i-r-1)]
  cumsum[i] = (dp[i]+cumsum[i-1])%mod
print(dp[n]%mod)
Buggy python submission (verdict: Runtime Error):
h,w,m = map(int,input().split())
row = [0]*(h+1)
col = [0]*(w+1)
bombs = set([])
for i in range(m):
  a,b = map(int,input().split())
  row[a] += 1
  col[b] += 1
  bombs.add((a,b))
r,c = max(row),max(col)
rcnt,ccnt = 0,0
for v in row:
  if v==r:
    rcnt += 1
for v in col:
  if v==c:
    ccnt += 1
doubled = 0
for i,j in bombs:
  if row[i]==r and col[j]==c:
    doubled += 1
if doubled==rcnt*ccnt:
  print(r+c-1)
else:
  print(r+c)

Fixed submission:
n,x,t = map(int,input().split())
print(-(-n//x)*t)
Buggy python submission (verdict: Time Limit Exceeded):
h,w,m = map(int,input().split())
row = [0]*(h+1)
col = [0]*(w+1)
bombs = set([])
for i in range(m):
  a,b = map(int,input().split())
  row[a] += 1
  col[b] += 1
  bombs.add((a,b))
r,c = max(row),max(col)
for i in range(1,h+1):
  if row[i]!=r:
    continue
  for j in range(1,w+1):
    if col[j]!=c:
      continue
    if (i,j) not in bombs:
      print(r+c)
      exit()
else:
  print(r+c-1)

Fixed submission:
h,w,m = map(int,input().split())
row = [0]*(h+1)
col = [0]*(w+1)
bombs = set([])
for i in range(m):
  a,b = map(int,input().split())
  row[a] += 1
  col[b] += 1
  bombs.add((a,b))
r,c = max(row),max(col)
rcnt,ccnt = 0,0
for v in row:
  if v==r:
    rcnt += 1
for v in col:
  if v==c:
    ccnt += 1
doubled = 0
for i,j in bombs:
  if row[i]==r and col[j]==c:
    doubled += 1
if doubled==rcnt*ccnt:
  print(r+c-1)
else:
  print(r+c)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
a = list(map(int,input().split()))
stack = deque()
stack.append([1000,0,0,200])
ans = []
while stack:
  money,kabu,i,temp = stack.pop()
  ans.append(money)
  if i<n:
    stack.append([money,kabu,i+1,temp])
    if a[i]<temp and a[i]<=money:
      kabu += money//a[i]
      money %= a[i]
      stack.append([money,kabu,i+1,a[i]])
    elif a[i]>temp and kabu>=1:
      money += a[i]*kabu
      kabu = 0
      stack.append([money,kabu,i+1,a[i]])
    ans.append(money)
print(max(ans))

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
money = 1000
kabu = 0
for i in range(n-1):
  if kabu==0:
    if a[i]<=a[i+1]:
      kabu += money//a[i]
      money %= a[i]
  else:
    if a[i]>a[i+1]:
      money += kabu*a[i]
      kabu = 0
print(money+kabu*a[-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
a = list(map(int,input().split()))
stack = deque()
stack.append([1000,0,0,200])
ans = []
while stack:
  money,kabu,i,temp = stack.pop()
  ans.append(money)
  if i<n:
    stack.append([money,kabu,i+1,temp])
    if a[i]<temp and a[i]<=money:
      kabu += money//a[i]
      money %= a[i]
    elif a[i]>temp and kabu>=1:
      money += a[i]*kabu
      kabu = 0
    stack.append([money,kabu,i+1,a[i]])
    ans.append(money)
print(max(ans))

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
money = 1000
kabu = 0
for i in range(n-1):
  if kabu==0:
    if a[i]<=a[i+1]:
      kabu += money//a[i]
      money %= a[i]
  else:
    if a[i]>a[i+1]:
      money += kabu*a[i]
      kabu = 0
print(money+kabu*a[-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
h,w,k = map(int,input().split())
c = np.zeros((h,w))
for _ in range(h):
  row = [1 if a=='#' else 0 for a in input()]
  c[_]=row
ans = 0
for bit in range(1<<h+w):
  d = np.copy(c)
  for i in range(h+w):
    if (bit>>i)&1:
      if i<h:
        d[i]=0
      else:
        d[:,i-h]=0
  if np.sum(d)==k:
    ans += 1
print(ans)

Fixed submission:
import numpy as np
h,w,k = map(int,input().split())
c = []
for _ in range(h):
  row = [1 if a=='#' else 0 for a in input()]
  c.append(row)
c = np.array(c).reshape(h,w)
ans = 0
for bith in range(1<<h+w):
  d = np.copy(c)
  for i in range(h+w):
    if (bith>>i)&1:
      if i<h:
        d[i]=0
      else:
        d[:,i-h]=0
  if np.sum(d)==k:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]
ans = 0
temp = a[0]
lim = 1
cnt = 1
nb = iter(set(a))
poy = next(nb)
nxt = next(nb)
for v in a[1:]:
  if lim==0:
    cnt = 2
    temp = nxt
    lim = cnt
    nxt = next(nb)
  ans += temp
  if temp==v:
    cnt += 1
    lim = cnt
  else:
    lim -= 1
print(ans)

Fixed submission:
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]
ans = 0
for i in range(1,n):
  ans += a[i//2]
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]
ans = 0
temp = a[0]
lim = 1
cnt = 1
nb = iter(set(a))
poy = next(nb)
nxt = next(nb)
for v in a[1:]:
  if lim==0:
    cnt = 2
    temp = nxt
    lim = cnt
    nxt = next(nb)
  ans += temp
  if temp==v:
    cnt += 1
    lim = cnt
  else:
    lim -= 1
  print(ans)  

Fixed submission:
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]
ans = 0
for i in range(1,n):
  ans += a[i//2]
print(ans)