Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02639 (python)

Fixed submission:
x = list(map(int,input().split()))
ans = x.index(0) + 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

B = [1] * (max(A) + 1)
for a in A:
    for k in range(a  * 2,len(B),a):
            B[k] = 0
print(sum(B[a] == 1 and A.count(a) == 1 for a in A))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

B = [1] * (max(A) + 1)
for a in A:
    for k in range(a  * 2,len(B),a):
            B[k] = 0
print(sum(B[a] == 1 and A.count(a) == 1 for a in A))
Problem p02658 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 1
if 0 in A:
    print(0)
    exit()
for i in range(len(A)):
    ans *= A[i]
    if ans > 10 ** 18:
        print(-1)
        exit()
print(ans)

Buggy submission (verdict: Runtime Error):
from sympy import prime
import numpy as np

N = int(input())
A = list(map(int, input().split()))
ans = np.prod(A)
if ans <= 10 ** 18:
    print(ans)
else:
    print(-1)
Problem p02660 (python)

Fixed submission:
import collections
#nを素因数分解したリストを返す
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

N = int(input())
if N == 1:
    print(0)
else:
    A = prime_decomposition(N)

    c = collections.Counter(A)
    values, counts = zip(*c.most_common())


    cnt = 0
    for i in range(len(counts)):
        for j in range(10,0,-1):
            if counts[i] >= j * (j + 1)//2:
                cnt += j
                break
    print(cnt)

Buggy submission (verdict: Runtime Error):
import sympy
N = int(input())
p_list = list(sympy.primerange(2,1000000))
print(p_list)
cnt = 0
for i in range(10000):
    j = 1
    while N % (p_list[i] ** j) == 0:
        cnt += 1
        N = N / (p_list[i] ** j)
        j += 1
    a = sympy.isprime(N)
    if a == True:
        cnt += 1
        break
print(cnt)
Problem p02681 (python)

Fixed submission:
S = input()
T = input()
U = T[0:len(S)]
if U == S:
    print('Yes')
else:
    print('No')

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

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = [1]
    a = 1
    check = [0] * len(A)
    while True:
        a = A[a - 1]
        if check[a - 1] == 1:
            x = B.index(a)
            roop = B[x:]
            print(roop[(K - x) % len(roop)])
            exit()
        B.append(a)
        check[a - 1] += 1
    if len(B) >= K + 1:
        print(B[K])
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [1]
for i in range(1,K + 1):
    a = A[B[i - 1] - 1]
    if a in B:
        x = B.index(a)
        y = i - x
        z = (K - x) % y
        print(B[x + z])
        exit()
    B.append(a)
if len(B) == K + 1:
    print(B[K])
Problem p02683 (python)

Fixed submission:
import bisect
N, M, X = map(int, input().split())
C = [0] * N
A = [0] * N
for i in range(N):
    x = list(map(int, input().split()))
    C[i] = x[0]
    A[i] = [0] * M
    for j in range(M):
        A[i][j] = x[j + 1]
cnt = [0] * (2 ** N)
ans_list = []
for i in range(2 ** N):
    bag = []
    cnt[i] = [0] * M
    for j in range(N):
        if ((i >> j) & 1):
            bag.append(C[j])
            for k in range(M):
                cnt[i][k] += A[j][k]
    cnt[i].sort()
    if bisect.bisect_left(cnt[i], X) == 0:
        ans_list.append(sum(bag))
if ans_list == []:
    print(-1)
else:
    print(min(ans_list))

Buggy submission (verdict: Runtime Error):
import bisect
N, M, X = map(int, input().split())
C = [0] * N
A = [0] * N
for i in range(N):
    x = list(map(int, input().split()))
    C[i] = x[0]
    A[i] = [0] * M
    for j in range(M):
        A[i][j] = x[j + 1]
cnt = [0] * (2 **N)
ans_list = []
for i in range(2 ** N):
    bag = []
    cnt[i] = [0] * M
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(C[j])  # フラグが立っていたら bag に果物を詰める
            for k in range(M):
                cnt[i][k] += A[j][k]
    if bisect.bisect_left(cnt[i], X) == 0:
        ans_list.append(sum(bag))
if ans_list == []:
    print(-1)
else:
    print(min(ans_list)
Problem p02705 (python)

Fixed submission:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

R = I()
print(2 * math.pi * R)

Buggy submission (verdict: Runtime Error):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

R = I()
print(2 * math.pi * R)
Problem p02708 (python)

Fixed submission:
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

mod = 10 ** 9 + 7
N, K = MI()
def num(self):
    return (-2 * pow(self, 3) + 3 * N * pow(self, 2) + (3 * N + 8) * self) // 6
ans = num(N + 1) - num(K - 1)
print(ans % mod)

Buggy submission (verdict: Runtime Error):
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

mod = 10 ** 9 + 7
N, K = MI()
def num(self):
    return (-2 * pow(self, 3) + 3 * N * pow(self, 2) + (3 * N + 8) * self) // 6
ans = num(N + 1) - num(K - 1)
print(ans % mod)
Problem p02722 (python)

Fixed submission:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

N = I()
B = make_divisors(N - 1)
b = len(B)

A = make_divisors(N)

cnt = 0
for i in range(1, len(A) // 2 + 1):
    x = A[i]
    y = A[-i - 1]
    while y > x:
        if (y - 1) % x == 0:
            cnt += 1
            break
        elif y % x == 0:
            y //= x
        else:
            break
    if y == x:
        cnt += 1

ans = b - 1 + cnt + 1
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

import sympy
N = I()
a = sympy.divisor_count(N - 1)

A = sympy.divisors(N)

cnt = 0
for i in range(1, len(A) // 2 + 1):
    x = A[i]
    y = A[-i - 1]
    while y > x:
        if (y - 1) % x == 0:
            cnt += 1
            break
        elif y % x == 0:
            y //= x
        else:
            break
    if y == x:
        cnt += 1

ans = a - 1 + cnt + 1
print(ans)
Problem p02775 (python)

Fixed submission:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
from collections import defaultdict
def main():
    N = S()
    N =  N[::-1]
    N += '0'
    cnt = 0
    next = 0
    for i in range(len(N)):
        num = int(N[i])
        num += next
        if num <= 4:
            cnt += num
            next = 0
        elif num >= 6:
            cnt += 10 - num
            next = 1
        else:
            if int(N[i + 1]) <= 4:
                cnt += num
                next = 0
            else:
                cnt += 10 - num
                next = 1

    print(cnt)
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
from collections import defaultdict
def main():
    N = S()
    N =  N[::-1]
    cnt = 0
    next = 0
    for i in range(len(N)):
        num = int(N[i])
        num += next
        if num <= 4:
            cnt += num
            next = 0
        elif num >= 6:
            cnt += 10 - num
            next = 1
        else:
            if int(N[i + 1]) <= 4:
                cnt += num
                next = 0
            else:
                cnt += 10 - num
                next = 1

    if next == 1:
        cnt += 1
    print(cnt)
if __name__ == "__main__":
    main()
Problem p03155 (python)

Fixed submission:
n = int(input());h = int(input());w = int(input())
print((n-h+1)*(n-w+1))

Buggy submission (verdict: Runtime Error):
n, h, w = map(int, input().split())
print((n-h+1)*(n-w+1))
Problem p03206 (python)

Fixed submission:
d = int(input())
if d==25:
	print('Christmas')
elif d==24:
	print('Christmas Eve')
elif d==23:
	print('Christmas Eve Eve')
else:
	print('Christmas Eve Eve Eve')

Buggy submission (verdict: Runtime Error):
n = int(input())
if n==22:
  print(Christmas Eve Eve Eve)
elif n==23:
  print(Christmas Eve Eve)
elif n==24:
  print(Christmas Eve)
else:
  print(Christmas)
Problem p03219 (python)

Fixed submission:
x, y = map(int, input().split())
print(x + y//2)

Buggy submission (verdict: Runtime Error):
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    System.out.println(x + y/2);
  }
}
Problem p03402 (python)

Fixed submission:
a, b = map(int, input().split())
grid = [["#" for j in range(100)] for i in range(100)]
for i in range(50, 100):
	for j in range(100):
		grid[i][j] = "."
for i in range(a-1):
	grid[(i//50)*2][(i%50)*2] = "."
for i in range(b-1):
	grid[(i//50)*2+51][(i%50)*2] = "#"
print(100, 100)
for i in range(100):
	print("".join(grid[i]))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
grid = [["#" for j in range(100)] for i in range(100)]
for i in range(50, 100):
	for j in range(100):
		grid[i][j] = "."
for i in range(a-1):
	grid[(i//50)*2][(i%50)*2] = "."
for i in range(b-1):
	grid[(i//50)*2+51][(i%50)*2+51] = "#"
print(100, 100)
for i in range(100):
	print("".join(grid[i]))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
grid = [["#" for j in range(100)] for i in range(100)]
for i in range(50, 100):
	for j in range(100):
		grid[i][j] = "."
for i in range(a-1):
	grid[(i//50)*2][(i%50)*2] = "."
for i in range(b-1):
	grid[(i//50)*2+51][(i%50)*2+51] = "#"
print(100, 100)
for i in range(100):
	print("".join(grid[i]))
Problem p03477 (python)

Fixed submission:
a,b,c,d=map(int, input().split())
x=a+b-c-d
if x>0:
  s="Left"
elif x<0:
  s="Right"
else:
  s="Balanced"
print(s)

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int, input().split())
x=a+b-c-d
if x>0:
  print(Left)
elif x<0:
  print(Right)
else:
  print(Balanced)

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int, input())
x=a+b-c-d
if x>0:
  print(Left)
elif x<0:
  print(Right)
else:
  print(Balanced)
Problem p03797 (python)

Fixed submission:
n, m = map(int, input().split())
print(min(n, m//2)+max(0, (m-n*2)//4))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input())
print(n + max(0, (m-2*n)//4) if m>=2 else "0")

Buggy submission (verdict: Runtime Error):
n, m = map(int, input())
print(n + max(0, (m-2*n)//4) if m>=2 else 0)
Problem p03943 (python)

Fixed submission:
a, b, c = map(int, input().split())
print("Yes" if a+b==c or b+c==a or c+a==b else "No")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print("Yes" if a+b=c or b+c=a or c+a=b else "No")
Problem p03997 (python)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
print((a+b)*h//2)

Buggy submission (verdict: Runtime Error):
a, b, h = map(int, input().split())
print((a+b)*h/2)
Problem p03382 (python)

Fixed submission:
import sys

n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 10000000000
ans = -1
for num in lsnum:
    if num == ma:
        continue
    value = abs(ma-num*2)
    if minvalue >= value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Buggy submission (verdict: Runtime Error):
import sys

n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 100000000
ans = -1
for num in lsnum:
    if num == ma:
        continue
    value = abs(ma-num*2)
    if minvalue >= value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Buggy submission (verdict: Runtime Error):
import sys

n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 100000000
ans = -1
for num in lsnum:
    if num == ma:
        continue
    value = abs(ma//2-num)
    if minvalue >= value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Buggy submission (verdict: Runtime Error):
import sys

n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 100000000
ans = -1
for num in lsnum:
    if num == ma:
        continue
    value = abs(ma/2-num)
    if minvalue >= value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Buggy submission (verdict: Runtime Error):
import sys

n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 100000000
ans = -1
for num in lsnum:
    value = abs(ma/2-num)
    if minvalue >= value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Buggy submission (verdict: Runtime Error):


n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 100000000
ans = -1
for num in lsnum:
    value = abs(ma/2-num)
    if minvalue > value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])

Buggy submission (verdict: Runtime Error):
# 再帰制限に引っかかった場合に外す
# import sys
# sys.setrecursionlimit(100000)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

maxvalue = -1
ans = -1
for num in lsnum:
    val = cmb(ma,num)
    if(ma == num):
        continue
    if maxvalue < val:
        maxvalue = val
        ans = [ma, num]
print (ans[0], ans[1])
Problem p03633 (python)

Fixed submission:

import math

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

N=int(input())

T = []
for i in range(N):
    inp = int(input())
    T.append(inp)

cal = T[0]

i = 1
now = T[0]
while(i<N):
    m = T[i] * now
    now = m // gcd(now, T[i])
    i+=1
print(now)

Buggy submission (verdict: Runtime Error):

import math
N=int(input())

T = []
for i in range(N):
    inp = int(input())
    T.append(inp)

cal = T[0]

i = 1
now = T[0]
while(i<N):
    m = T[i] * now
    now = m // math.gcd(now, T[i])
    i+=1
print(now)
Problem p03227 (python)

Fixed submission:
n = raw_input()
print n if len(n)==2 else n[::-1]

Buggy submission (verdict: Runtime Error):
n = input()
print n if len(n)==2 else n[::-1]
Problem p03447 (python)

Fixed submission:
a=int(raw_input());b=int(raw_input());c=int(raw_input())
print (a-b)%c

Buggy submission (verdict: Runtime Error):
arr=[]
arr.append(int(raw_input());arr.append(int(raw_input());arr.append(int(raw_input())
print (arr[0]-arr[1])%(arr[2])
Problem p02574 (python)

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


def prime_factorize(n):
    r = set()
    while n % 2 == 0:
        r.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            r.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        r.add(n)
    return r


j = 0
a1 = set()
a2 = prime_factorize(A[0])
for a in A[1:]:
    tmp = prime_factorize(a)
    if a1 & tmp:
        j = 1
    a1 |= tmp
    a2 &= tmp
if a2:
    print('not coprime')
elif j:
    print('setwise coprime')
else:
    print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
A = list(set(list(map(int, input().split()))))


def prime_factorize(n):
    r = set()
    if n % 2 == 0:
        r.add(2)
    f = 3
    while f * f <= n:
        if n % f == 0:
            r.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        r.add(n)
    return collections.Counter(r)


a1 = collections.Counter([])
a2 = prime_factorize(A[0])
for a in A:
    tmp = prime_factorize(a)
    a1 += tmp
    a2 &= tmp
if a2:
    print('not coprime')
elif a1.most_common()[0][1] >= 2:
    print('setwise coprime')
else:
    print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
A = set(list(map(int, input().split())))


def prime_factorize(n):
    r = set()
    if n % 2 == 0:
        r.add(2)
    f = 3
    while f * f <= n:
        if n % f == 0:
            r.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        r.add(n)
    return collections.Counter(r)


a1 = collections.Counter([])
a2 = prime_factorize(list(A)[0])
for a in A:
    tmp = prime_factorize(a)
    a1 += tmp
    a2 &= tmp
if a2:
    print('not coprime')
elif a1.most_common()[0][1] >= 2:
    print('setwise coprime')
else:
    print('pairwise coprime')
Problem p02584 (python)

Fixed submission:
x, k, d = map(int, input().split())
x = abs(x)

if d*k < x:
    print(x-d*k)
else:
    if (k-x//d)%2 == 0:
        print(x%d)
    else:
        print(abs(x%d-d))

Buggy submission (verdict: Runtime Error):
x, k, d = map(int, input().split())
x = abs(x)

if d*k < x:
    print(abs(x)-abs(d*k))
else:
    if abs(x%d-d) > abs(x%d):
        if (k-x//d)%2 == 0:
            print(abs(x%d))
        else:
            print(abs(x%d-d))
    elif abs(x%d-d) < abs(x%d)
        if (k-x//(d+1))%2 == 0:
            print(abs(x%d-d))
        else:
            print(abs(x%d))
Problem p02642 (python)

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

a_max = a[-1]
dp = [1]*a_max

for i in set(a):
    j = 2
    while i*j <= a_max:
        dp[i*j-1] = 0
        j += 1

a.append(0)
ans = 0
for i in range(n):
    if dp[a[i]-1] and a[i-1] != a[i] and a[i] != a[i+1]:
        ans += 1
print(ans)

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

a_max = a[-1]
dp = [1]*a_max

for i in set(a):
    j = 2
    while i*j <= a_max:
        dp[i*j-1] = 0
        j += 1

ans = 0
for i in range(n):
    if dp[a[i]-1] and a[i-1] != a[i] and a[i] != a[i+1]:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = list(map(int, input().split()))

a = list(set(a))

count = 0
for i in range(n):
    ans = a[i] % np.array(a)
    if np.count_nonzero(ans == 0) == 1:
        count += 1

print(count)
Problem p02756 (python)

Fixed submission:
from collections import deque
s = deque(input())
q = int(input())

cnt = 0
for _ in range(q):
    i = input().split()
    t = int(i[0])

    if t == 1:
        cnt += 1
    else:
        f = int(i[1])
        c = i[2]
        if (cnt % 2 == 0 and f == 1) or (cnt % 2 == 1 and f == 2):
            s.appendleft(i[2])
        else:
            s.append(i[2])

if cnt % 2 == 1:
    s.reverse()
print(''.join(s))

Buggy submission (verdict: Runtime Error):
from collections import deque
s = deque(input())
q = int(input())

cnt = 0
for _ in range(q):
    i = input().split()
    t = int(i[0])

    if t == 1:
        cnt += 1
    else:
        f = int(i[1])
        c = i[2]
        if (cnt % 2 == 0 and f == 1) or (cnt % 2 == 1 and f == 2):
            s.appendleft(i[2])
        else:
            s.append(i[2])
print(''.join(s) if cnt % 2 == 0 else ''.join(s[::-1]))
Problem p02838 (python)

Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))

    mod = 10**9+7
    ans = 0

    for k in range(60):
        x, y = 0, 0
        for a in A:
            x += 1 & a>>k
        tmp = x*(n-x)%mod
        tmp *= pow(2, k, mod)
        ans += tmp
        ans %= mod
    print(ans)


if __name__ =='__main__':
    main()

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

mod = 10 ** 9 + 7
ans = 0

for k in range(60):
    x, y = 0, 0
    for a in A:
        x += 1 & a >> k
    tmp = x * (n - x) % mod
    tmp *= pow(2, k, mod)
    ans += tmp
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
A = list(map(int, input().split()))

mod = 10**9+7
ans = 0

max_a = max(A)

for k in range(math.floor(math.log(max_a, 2))+1):
    x, y = 0, 0
    for a in A:
        if a & 1<<k:
            x += 1
    ans += x*(n-x)*pow(2, k, mod)
    ans %= mod
print(ans)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500000)

n, q = map(int, input().split())
ab = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)
add = [0]*n
for _ in range(q):
    pp, xx = map(int, input().split())
    add[pp-1] += xx


def dfs(v, p, value):
    value += add[v]
    ans[v] = value
    for c in ab[v]:
        if c == p:
            continue
        dfs(c, v, value)


ans = [0]*n
dfs(0, -1, 0)
print(*ans)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
ab = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)
p, x = [], []
px = dict()
for _ in range(q):
    pp, xx = map(int, input().split())
    p.append(pp-1)
    x.append(xx)
    px[pp-1] = xx


def dfs(now):
    for i in ab[now]:
        if d[i] == -1:
            d[i] = d[now]+1
            dfs(i)


d = [-1]*n
d[0] = 0
dfs(0)
ans = [0]*n
for i in range(len(p)):
    for j in range(n):
        if d[j] >= d[p[i]]:
            ans[j] += x[i]

print(*ans)