Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())

ans = ''

for i in range(len(s)-1):
    a = 123-ord(s[i])
    if a==26:
        ans += s[i]
    elif a<k:
        ans += 'a'
        k-=a
    else:
        ans += s[i]

ans += chr((ord(s[-1])-97+k)%26+97)

print(ans)

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

ans = ''

for i in range(len(s)-1):
    a = 123-ord(s[i])
    if a==26:
        ans += s[i]
    elif a<=k:
        ans += 'a'
        k-=a
    else:
        ans += s[i]

ans += chr((ord(s[-1])+k%26-97)%26+97)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        ab = fractions.gcd(i,j)
        if ab == 0:
            continue
        for k in range(1,K+1):
            ans += fractions.gcd(ab,k)

print(ans)

Fixed submission:
from math import gcd
K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        ab = gcd(i,j)
        if ab == 0:
            continue
        for k in range(1,K+1):
            ans += gcd(ab,k)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

target = dict()
for i in range(N):
	S = str(input())
	if S in target:
		count = target[S]
		target[S] += 1
	else: 
		target[S] = 1
ans = [k for k, v in target.items() if v == max(target.values())]
ans.sort()

for i in ans:
	print(i)

Fixed submission:
N = int(input())

target = dict()
max_count = 0
max_key = list()
for i in range(N):
	S = str(input())
	if S in target:
		count = target[S] +1
		target[S] = count	
	else:
		target[S] = 1
		count = 1

	if max_count < count:
		max_count = count
		max_key = [S]
	elif max_count == count:
		max_key.append(S)

max_key.sort()
for i in max_key:
	print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
p = list(map(int,input().split()))

# 期待値のリスト生成
ex_list = list()
for i in range(len(p)):
	ex_list.append((1+p[i])/2)

ans = 0
for i in range(N-K+1):
	ex = sum(ex_list[i:i+K])
	if ans < ex:
		ans = ex

print(ans)

Fixed submission:
N,K = map(int,input().split())
p = list(map(int,input().split()))

# 期待値の累積和リストを生成
ex_list = list() 
for i in range(len(p)):
	if i != 0:
		ex_list.append(((1+p[i])/2)+ex_list[-1])
	else:
		ex_list.append((1+p[i])/2)

ans = ex_list[K-1]
for i in range(N-K):
	# print(i,ex_list[i],ex_list[i+K])
	ex = abs(ex_list[i] - ex_list[i+K])
	if ans < ex:
		ans = ex
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
p = list(map(int,input().split()))

ans = 0
ans_list = list()
for i in range(N-K+1):
	ex = sum(p[i:i+K])
	if ans < ex:	
		ans = ex
		ans_list = p[i:i+K]

ans_ex = 0
for i in range(K):
	ans_ex += sum(range(1,ans_list[i]+1))/ans_list[i]
print(ans_ex)

Fixed submission:
N,K = map(int,input().split())
p = list(map(int,input().split()))

# 期待値の累積和リストを生成
ex_list = list() 
for i in range(len(p)):
	if i != 0:
		ex_list.append(((1+p[i])/2)+ex_list[-1])
	else:
		ex_list.append((1+p[i])/2)

ans = ex_list[K-1]
for i in range(N-K):
	# print(i,ex_list[i],ex_list[i+K])
	ex = abs(ex_list[i] - ex_list[i+K])
	if ans < ex:
		ans = ex
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
p = list(map(int,input().split()))

# 期待値のリスト生成
ex_list = list()
for i in range(len(p)):
	ex_list.append(sum(range(1,p[i]+1))/p[i])

ans = 0
for i in range(N-K+1):
	ex = sum(ex_list[i:i+K])
	if ans < ex:
		ans = ex

print(ans)

Fixed submission:
N,K = map(int,input().split())
p = list(map(int,input().split()))

# 期待値の累積和リストを生成
ex_list = list() 
for i in range(len(p)):
	if i != 0:
		ex_list.append(((1+p[i])/2)+ex_list[-1])
	else:
		ex_list.append((1+p[i])/2)

ans = ex_list[K-1]
for i in range(N-K):
	# print(i,ex_list[i],ex_list[i+K])
	ex = abs(ex_list[i] - ex_list[i+K])
	if ans < ex:
		ans = ex
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
'''
期待値
E[X] = sum(1:N)/N
'''

N,K = map(int,input().split())
p = list(map(int,input().split()))

# 期待値のリスト生成
ex_list = list()
for i in range(len(p)):
	ex_list.append(sum(range(1,p[i]+1))/p[i])

ans = list()
for i in range(N-K+1):
	ans.append(sum(ex_list[i:i+K]))
	# ans.append(ex_list[i:i+K])
# print(ans)
ans.sort(reverse=True)
print(ans[0])

Fixed submission:
N,K = map(int,input().split())
p = list(map(int,input().split()))

# 期待値の累積和リストを生成
ex_list = list() 
for i in range(len(p)):
	if i != 0:
		ex_list.append(((1+p[i])/2)+ex_list[-1])
	else:
		ex_list.append((1+p[i])/2)

ans = ex_list[K-1]
for i in range(N-K):
	# print(i,ex_list[i],ex_list[i+K])
	ex = abs(ex_list[i] - ex_list[i+K])
	if ans < ex:
		ans = ex
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))
pre_len = len(a) # 最初の長さ
ans = list()
for i in range(1,N+1):
	try:
		del a[:a.index(i)]
		ans.append(a[0])
	except ValueError :
		break

if len(ans) == 0:
	print(-1)
else:
	print(pre_len-len(ans))



Fixed submission:
N = int(input())
a = list(map(int,input().split()))
pre_len = len(a) # 最初の長さ
ans = list()

target = 1
for i in range(N):
	if a[i] == target:
		ans.append(i+1)
		target += 1


if len(ans) == 0:
	print(-1)
else:
	print(pre_len-len(ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

count = 0
for i in range(N):
	# print('B:',B[A[i]-1])
	# 追加の満足度が入らない場合は除く
	if i == 0:
		count += B[A[i]-1]
	else:
		count += B[A[i]-1]
		if abs(A[i]-A[i-1]) == 1:
			# print('C:',C[A[i-1]-1])
			count += C[A[i-1]-1]
print(count)


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

count = 0
pre   = 0
for i in range(N):
	now = A[i] - 1
	count += B[now]
	if i != 0 and pre == now - 1:
		count += C[pre]
	pre = now
print(count)
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())

target = list()

target.append(A+B)
target.append(A-B)
target.append(A*B)

print(map(target))


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

target = list()

target.append(A+B)
target.append(A-B)
target.append(A*B)

print(max(target))
Buggy python submission (verdict: Runtime Error):
def judge(S):
	S_list  = list(str(S))  #list化
	
	i_pure = None
	for i in S_list:
		if i == i_pure:
			return 'Bad'
		i_pure = i

	return 'Good'


# S = ['3776','8080','1333','0024']

S = stdin.readline()
# for s in S:
# 	print(judge(s))

print(judge(S))

Fixed submission:
from sys import stdin

def judge(S):
	S_list  = list(str(S))  #list化
	
	i_pure = None
	for i in S_list:
		if i == i_pure:
			return 'Bad'
		i_pure = i

	return 'Good'


# S = ['3776','8080','1333','0024']

S = stdin.readline()
# for s in S:
# 	print(judge(s))

print(judge(S))
Buggy python submission (verdict: Runtime Error):
import sys

a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())

gap = [abs(a-e),abs(b-e),abs(c-e),abs(d-e)]

for i in range(len(gap)):
	if gap[i] > k:
		print(':(')
		sys.exit()
print('Yay!')

Fixed submission:
A,B = map(int,input().split())
target = list(range(1,A+1))
target.extend(list(range(1,B+1)))

target.sort(reverse=True)
print(target[0]+target[1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N,W = map(int,input().split())
dp = np.zeros((N+2,W+2), dtype=int)

for i in range(1,N+1):
  w,v = map(int,input().split())
  for j in range(1,W+1):
    if j >= w:
      dp[i+1][j] = max(dp[i][j-w]+v,dp[i][j])
    else: # j < w
      dp[i+1][j] = dp[i][j]

print(dp[-1][-2]) 

Fixed submission:
import numpy as np

N,W = map(int,input().split())
dp = np.zeros(W+1, dtype=int)

for i in range(N):
  w,v = map(int,input().split())
  dp[w:] = np.maximum(dp[w:],dp[:-w]+v)

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
A = list(input())
A.sort()
cost =0
for i in range(len(A)-1):
  cost += abs(A[i]+A[i+1])
print(cost)

Fixed submission:
A = list(map(int,input().split()))
A.sort()
ans = 0
for i in range(len(A)-1):
	ans += abs(A[i]-A[i+1])
print(ans)
Buggy python submission (verdict: Runtime Error):
from dateutil.relativedelta import relativedelta
import datetime
S = str(input())
date_format = datetime.datetime.strptime(S,'%Y/%m/%d')
date_format = date_format+ relativedelta(years=1)
print(date_format.strftime("%Y/%m/%d"))

Fixed submission:
import datetime
S = str(input())
date_format = datetime.datetime.strptime(S,'%Y/%m/%d')
print('2018/'+str(date_format.strftime("%m/%d")))
Buggy python submission (verdict: Runtime Error):
N= int(input())
d = list()
for i in range(N):
    d.append(int(input())

d_set = set(d)
d_list = list(d_set)
d_list.sort()

print(len(d_list))

Fixed submission:
N= int(input())
d = list()
for i in range(N):
	d.append(int(input()))

d_set = set(d)
d_list = list(d_set)
d_list.sort()

print(len(d_list))
Buggy python submission (verdict: Runtime Error):
N = list(map(int,input()))
count = 1
count_list = list()
for i in range(3):
	if N[i] == N[i+1]:
		count += 1
	else:
		count_list.append(count)
		count = 1
print('Yes') if max(count_list) >= 3 else print('No')

Fixed submission:
N = list(map(int,input()))
count = 1
for i in range(3):
	if N[i] == N[i+1]:
		count += 1
		if count == 3:
			break
	else:
		count = 1

print('Yes') if count >= 3 else print('No')
Buggy python submission (verdict: Runtime Error):
a=input()
if a>=30:
  print("Yes")
else:
  print("No")

Fixed submission:
a=input()
if int(a)>=30:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
def can(x):
    i = min(n,x)
    end = min(m,i)
    t = a[i]+b[x-i]
    for k in range(x-i,end+1):
        t = min(t, a[i]+b[k])
        i -= 1
    if t<=k:
        return True
    else:
        return False

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

lo = 0
hi = n+m
while lo<hi:
    mid=lo+((hi-lo+1)>>1)
    if can(mid):
        lo=mid
    else:
        hi = mid-1
print(lo)


Fixed submission:
n,m,k=map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a = [0]+a
for i in range(1,n+1):
    a[i] += a[i-1]
b = [0]+b
for i in range(1,m+1):
    b[i] += b[i-1]

ans,j = 0,m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k-a[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input())
a = [int(i) for i in input().split()]
a.sort()
s = 0
for i in range(k):
  s += a[i]
print(s)

Fixed submission:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
a.sort()
s = 0
for i in range(k):
  s += a[i]
print(s)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
haveSnack = [False]*n
for _ in range(k):
  d = int(input(d))
  for __ in range(d):
    s = [int(i) for i in input().split()]
    for sk in s:
      if not haveSnack[sk-1]:
        haveSnack[sk-1] = True
res=0
for i in range(n):
  if not haveSnack[i]:
    res+=1
print(res)

Fixed submission:
n,k = map(int, input().split())
hs = [False]*n
for _ in range(k):
  d = int(input())
  s = [int(i) for i in input().split()]
  for p in s:
    if not hs[p-1]:
      hs[p-1]=True
res=0
for i in range(n):
  if not hs[i]:
    res+=1
print(res)
Buggy python submission (verdict: Runtime Error):
M = int(input())
if M <= 399:
    pass
elif 400 <= M and M <= 599:
    print("8")
elif M <= 799:
    print("7")
elif M <= 999:
    print("6")
elif M <= 1199:
    print("5")
elif M <= 1399:
    print("4")1
elif M <= 1599:
    print("3")
elif M <= 1799:
    print("2")
elif M <= 1999:
    print("1")

Fixed submission:
M = int(input())
if M <= 399:
    pass
elif 400 <= M and M <= 599:
    print("8")
elif M <= 799:
    print("7")
elif M <= 999:
    print("6")
elif M <= 1199:
    print("5")
elif M <= 1399:
    print("4")
elif M <= 1599:
    print("3")
elif M <= 1799:
    print("2")
elif M <= 1999:
    print("1")
Buggy python submission (verdict: Runtime Error):
import math
A, B, C = list(map(int, input().split()))
K = int(input())
#A, B, C = [7, 4, 2]
#K = 3

i = math.floor(A/(B+1))
K -= i
B = B * (2 ** i)
j = math.floor(B/(C+1))
K -= j
C = C * (2 ** j)
if K >= 0:
    print("Yes")
else:
    print("No")

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
#N, K = 5, 3
#A = [96, 98, 95, 100, 20]
#N, K = 3, 2
#A = [1001, 869120, 1001]
#N, K = 15, 7
#A = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9]

def getA(i):
    if i < 0:
        return 1
    elif i >= N:
        return 1
    else:
        return A[i]
# 
for i in range(K,N):
    #print(i,getA(i-K), getA(i))
    if getA(i-K) < getA(i):
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
cnt = 0
for i in range(len(S)):
    if S[i] != T[i] :
        cnt += 1
prrint(cnt)

Fixed submission:
S = input()
T = input()
cnt = 0
for i in range(len(S)):
    if S[i] != T[i] :
        cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
X = map(int,input().split())
for i in range(5):
    if X[i] != i :
        print(i+1)

Fixed submission:
X = list(map(int,input().split()))
for i in range(5):
    if X[i] != i+1 :
        print(i+1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

def f(A):
    for a in A:
        if a == 0:
            print(0)
            return
    v = 1
    for a in A:
        v *= a
        if v > int(1e+18):
            print(-1)
            return
    print(v)
    return

f(A)

Fixed submission:
A,B = list(map(int,input().split()))
print(A*B)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
v = 1
m = int(1e+18)
for a in A:
    v *= a

if v > m:
    print(-1)
else:
    print(v)

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

def f(A):
    for a in A:
        if a == 0:
            print(0)
            return
    v = 1
    for a in A:
        v *= a
        if v > int(1e+18):
            print(-1)
            return
    print(v)
    return

f(A)
Buggy python submission (verdict: Runtime Error):
K = int(input())
S = input()
if len(S) <= K:
    print(s)
else:
    s = ""
    for i in range(K):
        s += S[i]
    s += "..."
    print(s)

Fixed submission:
K = int(input())
S = input()
if len(S) <= K:
    print(S)
else:
    s = ""
    for i in range(K):
        s += S[i]
    s += "..."
    print(s)
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,input().split()))
s = 0
for i in L:
    s += i
s -= max(L)
if L < s:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
s = 0
for i in L:
    s += i
s -= max(L)
if max(L) < s:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    cnt = [[0] * 18 for _ in range(41)]
    ans = 0
    for _ in range(N):
        a = input()
        if "." in a:
            b = int(a.replace(".", "") + "0" * (10 - (len(a) - a.index("."))))
        else:
            b = int(a) * 10 ** 9
        d2 = 0
        d5 = 0
        while b % 2 == 0:
            d2 += 1
            b //= 2
        while b % 5 == 0:
            d5 += 1
            b //= 5
        for i in range(max(0, 18-d2), 41):
            for j in range(max(0, 18-d5), 18):
                ans += cnt[i][j]
        cnt[d2][d5] += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = int(input())
    cnt = [[0] * 19 for _ in range(44)]
    ans = 0
    for _ in range(N):
        a = input()
        if "." in a:
            b = int(a.replace(".", "")) * 10 ** (10 - (len(a) - a.index(".")))
        else:
            b = int(a) * 10 ** 9
        d2 = 0
        d5 = 0
        while b % 2 == 0:
            d2 += 1
            b //= 2
        while b % 5 == 0:
            d5 += 1
            b //= 5
        for i in range(max(0, 18-d2), 44):
            for j in range(max(0, 18-d5), 19):
                ans += cnt[i][j]
        cnt[d2][d5] += 1
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    h = []
    for a in A:
        heappush(h, [-a, a, 1])
    for i in range(K):
        pri, origlen, cut = heappop(h)
        heappush(h, [-origlen//(cut+1), origlen, cut+1])
    ans = -h[0][0]
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def countcut(A, length):
    ret = 0
    for a in A:
        ret += -(-a//length) - 1
    return ret


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    lo = 1
    hi = int(1e9)
    while lo < hi:
        mid = (lo+hi) // 2
        if countcut(A, mid) <= K:
            hi = mid
        else:
            lo = mid + 1
    print(lo)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter


def is_divideable(a, nums):
    x = 1
    while x ** 2 <= a:
        if a % x == 0:
            if x in nums or (a // x) in nums:
                return True
        x += 1
    return False


def main():
    N = int(input())
    A = list(map(int, input().split()))
    cnt = Counter(A)
    nums = set()
    A.sort()
    ans = 0
    for a in A:
        if cnt[a] == 1 and not is_divideable(a, nums):
            ans += 1
        nums.add(a)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    MAX = max(A)
    dp = [True] * (MAX+1)
    A.sort()
    cnt = Counter(A)
    ans = 0
    for a in A:
        if dp[a]:
            if cnt[a] == 1:
                ans += 1
            x = a
            while x <= MAX:
                dp[x] = False
                x += a
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    path = [-1] * N * 2
    idx = 0
    visited = [False] * N
    cur = 0
    while K:
        if visited[cur]:
            loop = idx - path.index(cur)
            K %= loop
        path[idx] = cur
        visited[cur] = True
        cur = A[cur] - 1
        K -= 1
        idx += 1
    print(cur + 1)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    path = [-1] * N * 2
    idx = 0
    visited = [False] * N
    cur = 0
    loop = -1
    while K:
        K -= 1
        if loop == -1 and visited[cur]:
            loop = idx - path.index(cur)
            K %= loop
        path[idx] = cur
        visited[cur] = True
        cur = A[cur] - 1
        idx += 1
    print(cur + 1)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    path = []
    visited = set()
    cur = 0
    while K:
        if cur in visited:
            loop = len(path) - path.index(cur)
            K %= loop
        path.append(cur)
        visited.add(cur)
        cur = A[cur] - 1
        K -= 1
    print(cur + 1)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    path = [-1] * N * 2
    idx = 0
    visited = [False] * N
    cur = 0
    loop = -1
    while K:
        K -= 1
        if loop == -1 and visited[cur]:
            loop = idx - path.index(cur)
            K %= loop
        path[idx] = cur
        visited[cur] = True
        cur = A[cur] - 1
        idx += 1
    print(cur + 1)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

MOD = 998244353


def main():
    N, S = map(int, input().split())
    A = list(map(int, input().split()))
    dp = [defaultdict(int) for _ in range(S)]
    ans = 0
    for right in range(N):
        num = A[right]
        if num > S:
            continue
        elif num == S:
            ans = (ans + (right+1) * (N-right)) % MOD
            continue
        for left in dp[S-num]:
            cnt = dp[S-num][left]
            ans = (ans + (left+1) * (N-right) * cnt) % MOD
        for i in range(S-num-1, -1, -1):
            for left in dp[i]:
                dp[i+num][left] += dp[i][left]
        dp[num][right] = 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from collections import defaultdict

MOD = 998244353


def main():
    N, S = map(int, input().split())
    A = list(map(int, input().split()))
#    dp = [defaultdict(int) for _ in range(S)]
    dp = [0] * S
    ans = 0
    for right in range(N):
        num = A[right]
        if num > S:
            continue
        elif num == S:
            ans = (ans + (right+1) * (N-right)) % MOD
            continue
        # for left in dp[S-num]:
        #     cnt = dp[S-num][left]
        #     ans = (ans + (left+1) * (N-right) * cnt) % MOD
        # for i in range(S-num-1, -1, -1):
        #     for left in dp[i]:
        #         dp[i+num][left] += dp[i][left]
        # dp[num][right] = 1
        ans = (ans + dp[S-num] * (N-right)) % MOD
        for i in range(S-num-1, -1, -1):
            dp[i+num] += dp[i]
        dp[num] += right + 1
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
MOD = int(1e9+7)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


def main():
    N = int(input())
    A = list(map(int, input().split()))
    M = 60
    bitcnt = [0] * M
    for a in A:
        for i in range(M):
            if a & (1 << i):
                bitcnt[i] += 1
    ans = 0
    for a in A:
        for i in range(M):
            if a & (1 << i):
                ans = (ans + (1 << i) * (N - bitcnt[i])) % MOD
            else:
                ans = (ans + (1 << i) * bitcnt[i]) % MOD
            ans %= MOD
    ans = div(ans, 2)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
MOD = int(1e9+7)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


def main():
    N = int(input())
    A = list(map(int, input().split()))
    M = 60
    bitcnt = [0] * M
    for a in A:
        for i in range(M):
            if a & (1 << i):
                bitcnt[i] += 1
    ans = 0
    for a in A:
        for i in range(M):
            x = 1 << i
            if a & x:
                ans = (ans + x * (N - bitcnt[i])) % MOD
            else:
                ans = (ans + x * bitcnt[i]) % MOD
    ans = div(ans, 2)
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
MOD = int(1e9+7)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


def main():
    N = int(input())
    A = list(map(int, input().split()))
    M = 60
    bitcnt = [0] * M
    for a in A:
        for i in range(M):
            if a & (1 << i):
                bitcnt[i] += 1
    ans = 0
    for a in A:
        for i in range(M):
            if a & (1 << i):
                ans += (1 << i) * (N - bitcnt[i])
            else:
                ans += (1 << i) * bitcnt[i]
            ans %= MOD
    ans = div(ans, 2)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
MOD = int(1e9+7)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


def main():
    N = int(input())
    A = list(map(int, input().split()))
    M = 60
    bitcnt = [0] * M
    for a in A:
        for i in range(M):
            if a & (1 << i):
                bitcnt[i] += 1
    ans = 0
    for a in A:
        for i in range(M):
            x = 1 << i
            if a & x:
                ans = (ans + x * (N - bitcnt[i])) % MOD
            else:
                ans = (ans + x * bitcnt[i]) % MOD
    ans = div(ans, 2)
    print(ans)


if __name__ == "__main__":
    main()