Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, W = map(int, input().split())
wv = []

for i in range(N):
    w, v = map(int, input().split())
    wv.append([w, v])

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j - wv[i][0] >= 0:
            dp[i+1][j] = max(dp[i][j], dp[i][j-wv[i][0]]+wv[i][1])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())
wv = []

for i in range(N):
    w, v = map(int, input().split())
    wv.append([w, v])
MAX_V = 10**5+100
INF = 10**10
dp = [[INF]*MAX_V for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(MAX_V):
        if j - wv[i][1] >= 0:
            dp[i+1][j] = min(dp[i][j], dp[i][j-wv[i][1]]+wv[i][0])
        else:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
ans = 0
for i in range(MAX_V):
    if dp[N][i] <= W:
        ans = i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))
h.sort()

sub = 10 ** 9
for i in range(n-k+1):
    hmax = max(h[i:i+k])
    hmin = min(h[i:i+k])
    sub = min(hmax - hmin, sub)
print(sub)

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

sub = 10 ** 9
for i in range(n-k+1):
    hmax = h[i+k-1]
    hmin = h[i]
    sub = min(hmax - hmin, sub)
print(sub)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
city = []
for i in range(m):
    city.append(list(map(int, input().split())))

sortedcity = sorted(city)
cnt = {}
ans = []

for i in range(m):
    pref = sortedcity[i][0]
    year = sortedcity[i][1]
    if pref in cnt:
        cnt[pref].append(year)
    else:
        cnt[pref] = [year]

for i in range(m):
    pref = city[i][0]
    year = city[i][1]
    num = cnt[pref].index(year) + 1
    tmp = str(pref).zfill(6) + str(num).zfill(6)
    ans.append(tmp)
    print(ans[i])


Fixed submission:
n, m = map(int, input().split())
city = []
for i in range(m):
    x, y = map(int, input().split())
    city.append(list([x, y, i]))

city.sort()
cnt = 1

tmppref = city[0][0]

for i in range(m):
    city[i][1] = cnt
    cnt += 1
    if i < m - 1 and tmppref != city[i + 1][0]:
        cnt = 1
        tmppref = city[i+1][0]
city = sorted(city, key=lambda x: x[2])
for i in range(m):
    pref = city[i][0]
    num = city[i][1]
    ans = str(pref).zfill(6) + str(num).zfill(6)
    print(ans)

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

sortedcity = sorted(city)
cnt = {}
ans = []

for i in range(m):
    pref = sortedcity[i][0]
    year = sortedcity[i][1]
    if pref in cnt:
        cnt[pref].append(year)
    else:
        cnt[pref] = [year]

for i in range(m):
    pref = city[i][0]
    year = city[i][1]
    num = cnt[pref].index(year) + 1
    tmp = str(pref).zfill(6) + str(num).zfill(6)
    ans.append(tmp)
    print(ans[i])


Fixed submission:
n, m = map(int, input().split())
city = []
for i in range(m):
    x, y = map(int, input().split())
    city.append(list([x, y, i]))

city.sort()
cnt = 1

tmppref = city[0][0]

for i in range(m):
    city[i][1] = cnt
    cnt += 1
    if i < m - 1 and tmppref != city[i + 1][0]:
        cnt = 1
        tmppref = city[i+1][0]
city = sorted(city, key=lambda x: x[2])
for i in range(m):
    pref = city[i][0]
    num = city[i][1]
    ans = str(pref).zfill(6) + str(num).zfill(6)
    print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
s = input()
k = input()

for i in range(len(s)):
    if s[i] != "1" and i + 1 < k:
        print(s[i])
        sys.exit(0)
print(1)


Fixed submission:
s = input()
k = int(input())
tmp = 1
for i in range(len(s)):
    if s[i] != '1' and i + 1 <= k:
        tmp = int(s[i])
        break
print(tmp)
Buggy python submission (verdict: Runtime Error):
from functools import reduce
n = int(input())
a = list(map(int, input().split()))

def gcd(x, y):
    try:
    if y == 0:
        return x
    return gcd(y, x % y)
    

def gcd2(number):
    return reduce(gcd, number)

def lcm(x, y):
    return x * y // gcd(x, y)
def lcm2(number):
    return reduce(lcm, number)

m = lcm2(a) - 1
#print(m)
ans = 0
for i in range(n):
    ans += m % a[i]
print(ans)

Fixed submission:
import fractions
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
m = lcm(*a)

ans = 0

for i in range(n):
    ans += (m - 1) % a[i]
print(int(ans))

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

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

def gcd2(number):
    return reduce(gcd, number)

def lcm(x, y):
    return int(x * y / gcd(x, y))
def lcm2(number):
    return reduce(lcm, number)

m = lcm2(a) - 1
#print(m)
ans = 0
for i in range(n):
    ans += m % a[i]
print(ans)

Fixed submission:
import fractions
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
m = lcm(*a)

ans = 0

for i in range(n):
    ans += (m - 1) % a[i]
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D, E, F = map(int,input().split())

water = []
sugar =[]
ans = [-1] * 3
for i in range(F+1):
    for j in range(F+1):
        y = i * C + j * D
        if y <= F:
            sugar.append(y)

for i in range(F + 1):
    for j in range(F + 1):
        x = i * 100 * A + j * 100 * B
        if x <= F:
            water.append(x)

for i in range(len(water)):
    for j in range(len(sugar)):
        a = water[i]
        b = sugar[j]
        if a + b <= F and a / 100 * E >= b:
            if ans[0] * (a + b) < 100 * b:
                ans[0] = 100 * b / (a + b)
                ans[1] = a + b
                ans[2] = b
print("{} {}".format(ans[1], ans[2]))


Fixed submission:
A, B, C, D, E, F = map(int,input().split())

water = []
sugar =[]
ans = [-1] * 3
for i in range(F+1):
    for j in range(F+1):
        y = i * C + j * D
        if y <= F:
            sugar.append(y)

for i in range(F + 1):
    for j in range(F + 1):
        x = i * 100 * A + j * 100 * B
        if x <= F:
            water.append(x)

for i in range(len(water)):
    for j in range(len(sugar)):
        a = water[i]
        b = sugar[j]
        if a + b <= F and a / 100 * E >= b:
            if ans[0] * (a + b) < 100 * b:
                ans[0] = 100 * b / (a + b)
                ans[1] = a + b
                ans[2] = b
print("{} {}".format(ans[1], ans[2]))
Buggy python submission (verdict: Runtime Error):
import sys
S = input()
cnt = [False] * 30
for i in S:
    if i in "abcdefghijklmnopqrstuvwxyz"
        cnt[ord(i) - ord('a')] = True
 
for i in range(len(cnt)):
    if not cnt[i]:
        print(chr(ord('a')+i))
        sys.exit()
print("None")

Fixed submission:
import sys
S = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"

for s in alphabet:
    if s not in S:
        print(s)
        sys.exit()

print("None")

Buggy python submission (verdict: Runtime Error):
import sys
S = input()
cnt = [False] * 30
for i in S:
    if i in "abcdefghijklmnopqrstuvwxyz"
    cnt[ord(i) - ord('a')] = True
 
for i in range(len(cnt)):
    if not cnt[i]:
        print(chr(ord('a')+i))
        sys.exit()
print("None")

Fixed submission:
import sys
S = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"

for s in alphabet:
    if s not in S:
        print(s)
        sys.exit()

print("None")

Buggy python submission (verdict: Runtime Error):
S = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"

for s in alphabet:
    if s not in S:
        print(s)
        sys.exit()

print("None")

Fixed submission:
import sys
S = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"

for s in alphabet:
    if s not in S:
        print(s)
        sys.exit()

print("None")

Buggy python submission (verdict: Runtime Error):
import sys
S = input()
cnt = [0] * 26
for i in range(len(S)):
    cnt[ord(S[i]) - ord('a')] += 1

for i in range(len(S)):
    if not cnt[i]:
        print(chr(ord('a')+i))
        sys.exit()
print("None")

Fixed submission:
import sys
S = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"

for s in alphabet:
    if s not in S:
        print(s)
        sys.exit()

print("None")

Buggy python submission (verdict: Runtime Error):
S = input()
cnt = [0] * 26
for i in range(len(S)):
    cnt[ord(S[i]) - ord('a')] += 1

for i in range(len(S)):
    if not cnt[i]:
        print(chr(ord('a')+i))
        break

Fixed submission:
import sys
S = input()
alphabet = "abcdefghijklmnopqrstuvwxyz"

for s in alphabet:
    if s not in S:
        print(s)
        sys.exit()

print("None")
Buggy python submission (verdict: Runtime Error):
N, C, K = map(int, input().split())
T = []
for i in range(N):
    T.append(int(input()))

T.sort()
i = 0
start = 0
ans = 0
limit = C
for i in range(N):
    if T[start] + K >= T[i + 1] and limit > 1 :
        limit -= 1
    elif T[start] + K < T[i + 1] and limit > 1:
        ans += 1
        limit = C
        start = i + 1
    elif T[start] + K >= T[i + 1] and limit == 1:
        ans += 1
        limit = C
        start = i + 1
if start != N:
    ans += 1
print(ans)

Fixed submission:
N, C, K = map(int, input().split())
T = []
for i in range(N):
    T.append(int(input()))

T.sort()
i = 0
start = 0
ans = 0
limit = C
for i in range(N - 1):
    if T[start] + K >= T[i + 1] and limit > 1 :
        limit -= 1
    elif T[start] + K < T[i + 1] and limit > 1:
        ans += 1
        limit = C
        start = i + 1
    elif limit == 1:
        ans += 1
        limit = C
        start = i + 1
if start != N:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M,Q = gets.split.map(&:to_i)
a = []
b = []
c = []
d = []
Q.times do |i|
  a[i], b[i], c[i], d[i] = gets.split.map(&:to_i)
  a[i] -= 1
  b[i] -= 1
end

def score(array,a,b,c,d)
  tmp = 0
  for ai,bi,ci,di in a.zip(b,c,d)
    tmp += di if array[bi] - array[ai] == ci
  end
  tmp
end

def dfs(array,a,b,c,d)
  if array.length == N
    return score(array,a,b,c,d)
  end
  result = 0
  array.length > 0 ? (prev_last = array[-1]) : (prev_last = 0)
  for v in prev_last..M
    array.push(v)
    result = [result, dfs(array,a,b,c,d)].max
    array.pop
  end
  result
end

puts dfs(Array.new,a,b,c,d)


Fixed submission:
N, M, Q = map(int, input().split())
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1

# スコア計算
def score(A):
    tmp = 0
    for ai, bi, ci, di in zip(a, b, c, d):
        if A[bi] - A[ai] == ci:
            tmp += di
    return tmp

# DFS
def dfs(A):
    if len(A) == N:
        return score(A) # 数列 A のスコアを返す
    res = 0
    prev_last = A[-1] if len(A) > 0 else 0
    for v in range(prev_last, M):
        A.append(v)
        res = max(res, dfs(A)) # 再帰呼出しながら、スコア最大値も更新
        A.pop()
    return res

# 求める
print(dfs([]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans =  0

for i in range(1, n):
  for j in range(1, (n - 1) // i + 1):
    if i * j <= n - 1:
      ans += 1
    
print(ans)

Fixed submission:
n = int(input())

ans =  0

for i in range(1, n):
  ans += (n - 1) // i 
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(' ')))

ans = 0
mod = 10 ** 9 + 7

for i in range(n):
  for j in range(i+1, n):
    k = (a[i] * a[j]) % mod
    ans += k
    ans %= mod
    
print(ans)

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

s = [0 for i in range(n-1)]
s[0] = sum(a) - a[0]
for i in range(1, n-1):
  s[i] = s[i-1] - a[i]

ans = 0
mod = 10 ** 9 + 7

for i in range(n - 1):
  k = a[i] * s[i] % mod
  ans += k
  ans %= mod
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import collections
import sys
import resource
sys.setrecursionlimit(200000)

n, m = map(int, input().split(' '))

f = [x for x in range(n)]

def find(x):
  if f[x] == x:
    return x
  root = find(f[x])
  f[x] = root
  return root

for i in range(m):
  a, b = map(int, input().split(' '))
  a -= 1
  b -= 1
  if find(a) != find(b):
    f[find(a)] = find(b)

for i in range(n):
  find(i)
  
print(max(collections.Counter(f).values()))

Fixed submission:
import collections
import sys
import resource
sys.setrecursionlimit(1000000)

n, m = map(int, input().split(' '))

f = [x for x in range(n)]

def find(x):
  if f[x] == x:
    return x
  root = find(f[x])
  f[x] = root
  return root

for i in range(m):
  a, b = map(int, input().split(' '))
  a -= 1
  b -= 1
  if find(a) != find(b):
    f[find(a)] = find(b)

for i in range(n):
  find(i)
  
print(max(collections.Counter(f).values()))

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

n, m = map(int, input().split(' '))

if m == 0:
  print(1)
  sys.exit()

f = [x for x in range(n)]

def find(x):
  if f[x] == x:
    return x
  root = find(f[x])
  f[x] = root
  return root

for i in range(m):
  a, b = map(int, input().split(' '))
  a -= 1
  b -= 1
  if find(a) != find(b):
    f[find(a)] = find(b)

for i in range(n):
  find(i)
  
print(max(collections.Counter(f).values()))

Fixed submission:
import collections
import sys
import resource
sys.setrecursionlimit(1000000)

n, m = map(int, input().split(' '))

f = [x for x in range(n)]

def find(x):
  if f[x] == x:
    return x
  root = find(f[x])
  f[x] = root
  return root

for i in range(m):
  a, b = map(int, input().split(' '))
  a -= 1
  b -= 1
  if find(a) != find(b):
    f[find(a)] = find(b)

for i in range(n):
  find(i)
  
print(max(collections.Counter(f).values()))

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

n, m = map(int, input().split(' '))

f = [x for x in range(n)]

def find(x):
  if f[x] == x:
    return x
  root = find(f[x])
  f[x] = root
  return root

for i in range(m):
  a, b = map(int, input().split(' '))
  a -= 1
  b -= 1
  if find(a) != find(b):
    f[find(a)] = find(b)

for i in range(n):
  find(i)
  
print(max(collections.Counter(f).values()))
print(f)

Fixed submission:
import collections
import sys
import resource
sys.setrecursionlimit(1000000)

n, m = map(int, input().split(' '))

f = [x for x in range(n)]

def find(x):
  if f[x] == x:
    return x
  root = find(f[x])
  f[x] = root
  return root

for i in range(m):
  a, b = map(int, input().split(' '))
  a -= 1
  b -= 1
  if find(a) != find(b):
    f[find(a)] = find(b)

for i in range(n):
  find(i)
  
print(max(collections.Counter(f).values()))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

sum=[]
for i in range(1,n+1):
  divisors=[]
  for j in range(1,i+1):
    if i%j == 0:
      divisors.append(j)
  sum.append(i*len(divisors))

ans=0
for k in range(n):
  ans+=sum[k]

print(ans)

Fixed submission:
n = int(input())

ans = 0
for i in range(1, n + 1):
  for j in range(1, n//i + 1):
    if i * j <= n:
      ans += i * j
    else:
      break
      
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
num = list(map(int, (input().split(' '))))

ans = 1
for i in range(n):
  ans *= num[i]
  
if ans <= 10**18:
  print(ans) 
else:
  print('-1')

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

flag = 1
if 0 in num:
  print(0)
  flag=0

if flag == 1:  
  ans = 1
  for i in range(n):
    if flag == 1:
      ans *= num[i]
      if ans > 10**18:
        flag = 0
        print('-1')
        break

if flag==1:
  print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
X=int(input())
flag=1
for c in range(np.power(10,9)):
    c+=1
    x=X
    if x%c==0:
        x=x//c
        for a in range(np.power(10,3)):
            if (np.power(a,4) + np.power(a,3)*(a-c) + np.power(a,2)*np.power(a-c,2) + a*np.power(a-c,3) + np.power(a-c,4))==x:
                print(a,a-c)
                flag=0
                break
    if flag==0:
        break

Fixed submission:
N, M = list(map(int, input().split()))
record = [1 for i in range(N)]
H = list(map(int, input().split()))
grid = []
for i in range(M):
    array = list(map(int, input().split()))
    grid.append(array)

for i in range(M):
    if H[grid[i][0]-1] > H[grid[i][1]-1]:
        record[grid[i][1]-1] = 0
    elif H[grid[i][0]-1] < H[grid[i][1]-1]:
        record[grid[i][0]-1] = 0
    elif H[grid[i][0]-1] == H[grid[i][1]-1]:
        record[grid[i][0]-1] = 0
        record[grid[i][1]-1] = 0

flag = 0
for i in range(N):
    if record[i] == 1:
        flag += 1
print(flag)
Buggy python submission (verdict: Runtime Error):
import numpy as np
H, W, M = map(int, input().split())
HW = [list(map(int, input().split())) for i in range(M)]

grid = np.zeros((H, W))
for h, w in HW:
    grid[h-1][w-1] = 1

max_h = 0
at_h = -1
for h in range(H):
    tmp = np.count_nonzero(grid[h, :])
    if tmp > max_h:
        max_h = tmp
        at_h = h + 1
max_w = 0
at_w = -1
for w in range(W):
    tmp = np.count_nonzero(grid[:, w])
    if tmp > max_w:
        max_w = tmp
        at_w = w + 1

if [at_h, at_w] in HW:
    print(max_h + max_w - 1)
else:
    print(max_h + max_w)

Fixed submission:
H, W, M = map(int, input().split())
HW = [list(map(int, input().split())) for i in range(M)]

g_h = [0] * (H+1)
g_w = [0] * (W+1)

for h, w in HW:
    g_h[h] += 1
    g_w[w] += 1

mxh = max(g_h)
mxw = max(g_w)

cnt = 0
for h, w in HW:
    if g_h[h] == mxh and g_w[w] == mxw:
        cnt += 1
if cnt == g_h.count(mxh) * g_w.count(mxw):
    print(mxh + mxw - 1)
else:
    print(mxh + mxw)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = list(map(int, input().split()))

cr = 1
for a in A[:k]:
    cr *= a

for i in range(n-k):
    tmp = A[k+i] * cr // A[i]
    if tmp > cr:
        print("Yes")
    else:
        print("No")
    cr = tmp


Fixed submission:
import numpy as np
n, k = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A)

for i in range(n-k):
    if A[k+i] > A[i]:
        print("Yes")
    else:
        print("No")

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

cr = 1
for a in A[:k]:
    cr *= a

for i in range(n-k):
    tmp = A[k+i] * cr // A[i]
    if tmp > cr:
        print("Yes")
    else:
        print("No")
    cr = tmp


Fixed submission:
import numpy as np
n, k = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A)

for i in range(n-k):
    if A[k+i] > A[i]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
import numpy as np
import copy
from itertools import product
h, w, k = map(int, input().split())
C = [list(input()) for _ in range(h)]
C = np.array(C)

cnt = 0
for i in product([True, False], repeat=h):
    c = copy.deepcopy(C)
    c = np.array(c)
    for p, q in enumerate(i):
        if q:
            c[p, :] = "$"
    for j in product([True, False], repeat=w):
        d = copy.deepcopy(c)
        d = np.array(d)
        for s,t in enumerate(j):
            if t:
                d[:, s] = "$"
        if np.count_nonzero(d == "#") == k:
            cnt += 1

print(cnt)

Fixed submission:
import numpy as np
import copy
from itertools import product
h, w, k = map(int, input().split())
C = [list(input()) for _ in range(h)]
C = np.array(C)

cnt = 0
for i in product([True, False], repeat=h):
    c = copy.deepcopy(C)
    c = np.array(c)
    for p, q in enumerate(i):
        if q:
            c[p, :] = "$"
    for j in product([True, False], repeat=w):
        d = copy.deepcopy(c)
        d = np.array(d)
        for s,t in enumerate(j):
            if t:
                d[:, s] = "$"
        if np.count_nonzero(d == "#") == k:
            cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

asum = list(accumulate(a))
bsum = list(accumulate(b))

ans, j = 0, m-1
for i in range(n):
    if asum[i] > k:
        break
    while bsum[j] > k - asum[i]:
        j -= 1
    ans = max(ans, i+1+j+1)
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.insert(0,0)
b.insert(0,0)

asum = list(accumulate(a))
bsum = list(accumulate(b))

ans = 0
for i, v in enumerate(asum):
    if v > k:
        break
    index = bisect.bisect_right(bsum, k-v)
    ans = max(ans, i + index-1)
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

asum = list(accumulate(a))
bsum = list(accumulate(b))

ans, j = 0, m-1
for i in range(n):
    if asum[i] > k:
        break
    while bsum[j] > k - asum[i]:
        j -= 1
    ans = max(ans, i+1+j+1)
print(ans)

Fixed submission:
n = int(input())                                                
                                                                
ans = 0                                                         
for i in range(1, n + 1):                                       
    terms = n // i    # 項数                                      
    ans += terms * (i + i * terms) // 2  # 項数＊(初項＋末項)//2        
                                                                
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())

a = Counter(a)
for _ in range(q):
    b, c = map(int, input().split())
    a[c] += a[b]
    del a[b]
    print(sum(a.elements()))


Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
total = sum(a)

a = Counter(a)
for _ in range(q):
    b, c = map(int, input().split())
    total += a[b] * c
    total -= a[b] * b
    a[c] += a[b]
    del a[b]
    print(total)

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

a = Counter(a)
for _ in range(q):
    b, c = map(int, input().split())
    a[c] += a[b]
    del a[b]
    ans = [x * y for x, y in a.items()]
    print(sum(ans))

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
total = sum(a)

a = Counter(a)
for _ in range(q):
    b, c = map(int, input().split())
    total += a[b] * c
    total -= a[b] * b
    a[c] += a[b]
    del a[b]
    print(total)

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

a = Counter(a)
for _ in range(q):
    b, c = map(int, input().split())
    a[c] += a[b]
    a.pop(b)
    ans = [x * y for x, y in a.items()]
    print(sum(ans))


Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
total = sum(a)

a = Counter(a)
for _ in range(q):
    b, c = map(int, input().split())
    total += a[b] * c
    total -= a[b] * b
    a[c] += a[b]
    del a[b]
    print(total)

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

a = Counter(a)
for _ in range(q):
    b, c = map(int, input().split())
    a[c] += a[b]
    a[b] = 0
    ans = [x * y for x, y in a.items()]
    print(sum(ans))


Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
total = sum(a)

a = Counter(a)
for _ in range(q):
    b, c = map(int, input().split())
    total += a[b] * c
    total -= a[b] * b
    a[c] += a[b]
    del a[b]
    print(total)