Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

def f(m, input):
  r = 0
  for i in input:
    r += m % i
  return r

N = map(int, input())
a_n = list(map(int, input().split(" ")))
a_n = sorted(a_n)

max = 0
for x in a_n:
  max += x
 
# result = []
# for m in range(max):
  # out = f(m, a_n)
  # result.append(out)
# re = sorted(result)
#print(re[-1])
#print(max) #994 518 941 851 647 2 581 -> 4534
print(max - len(a_n))

Fixed submission:
l = list(map(int, input().split(" ")))

l = sorted(l)
cost_1 = abs(l[1] - l[0])
cost_2 = abs(l[2] - l[1])
r = cost_1 + cost_2
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

def f(m, input):
  r = 0
  for i in input:
    r += m % i
  return r

N = map(int, input())
a_n = list(map(int, input().split(" ")))
a_n = sorted(a_n)

max = 0
for x in a_n:
  max += x
 
result = []
for m in range(max):
  out = f(m, a_n)
  result.append(out)
re = sorted(result)
#print(re[-1])
#print(max) #994 518 941 851 647 2 581 -> 4534
print(max - len(a_n))

Fixed submission:
# def gcd(a, b):
# 	while b:
# 		a, b = b, a % b
# 	return a

# def lcm(a, b):
# 	return a * b // gcd (a, b)

# def f(m, input):
#   r = 0
#   for i in input:
#     r += m % i
#   return r

N = map(int, input())
a_n = list(map(int, input().split(" ")))
# a_n = sorted(a_n)

max = 0
for x in a_n:
  max += x
 
# result = []
# for m in range(max):
  # out = f(m, a_n)
  # result.append(out)
# re = sorted(result)
#print(re[-1])
#print(max) #994 518 941 851 647 2 581 -> 4534
print(max - len(a_n))
Buggy python submission (verdict: Runtime Error):
def solve():
    n, y = map(int, input().split())
    y = y // 1000
    for nogu in range(n+1):
        for higu in range(n + 1 - nogu):
            yuki = n - higu - nogu
            total = yuki*10 + higu*5 + nogu
            if total == y:
                print(yuki, higu, nogu)
                return
    print("-1 -1 -1")

solve()

Fixed submission:
def solve():
    s = input().split("/")
    print("2018/{}/{}".format(s[1], s[2]))

solve()
Buggy python submission (verdict: Runtime Error):
def solve():
    s = input()
    t = input()

    s = sorted(s)
    t = sorted(t, reversed=True)

    if "".join(s) < "".join(t):
        print("Yes")
    else:
        print("No")
solve()

Fixed submission:
def solve():
    s = input()
    t = input()

    s = sorted(s)
    t = sorted(t, reverse=True)

    if "".join(s) < "".join(t):
        print("Yes")
    else:
        print("No")
solve()
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    an = sorted(map(int, input().split(' ')))
    
    # N = 6
    # an = [2, 7, 1, 8, 2, 8]
    # an = [1, 2, 3, 4]
    
    # a = [i % 4 for i in an]
    
    for i in range(len(N)-1):
        a = an[i]
        b = an[i+1]
        c = a * b
        if c % 4 != 0:
            print('No')
            
    print('Yes')
    
    
    
    
    
    
main()

Fixed submission:
from collections import Counter

def main():
    N = int(input())
    an = sorted(map(int, input().split(' ')))
    
    # N = 6
    # an = [1, 10, 100]
    # an = [2, 7, 1, 8, 2, 8]
    # an = [1, 2, 3, 4]
    # an = [1, 4, 1]
    # an = [846579189, 56223110]
    
    out = []
    
    for a in an:
        if a % 2 != 0:
            out.append('A')
        elif a % 4 != 0:
            out.append('B')
        else:
            out.append('C') 
    # print(out)
    counter = Counter(out)
    # print(counter)
    num_A = counter['A']
    num_B = counter['B']
    num_C = counter['C']
    # print(num_A, num_B, num_C)
    
    if num_A == 1 and num_B == 1 and num_C ==0:
        print('No')
        return
    
    if not ('B' in out):
        if (num_C + 1) >= num_A:
            print('Yes')
            # return
        else:
            print('No')
            # return
    else:
        if num_B >= num_A:
            print('Yes')
        else:
            print('No')
        
        
        
        
    
main()
Buggy python submission (verdict: Runtime Error):
def solve():
    n, m = map(int, input().split())
    lists = []

    for _ in range(m):
        lists += input().split()
    
    for i in range(i, n + 1):
        print(lists.count(str(i)))


solve()

Fixed submission:
def solve():
    n, m = map(int, input().split())
    lists = []

    for _ in range(m):
        lists += input().split()
    
    for i in range(1, n + 1):
        print(lists.count(str(i)))


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

num = 1
for i in range(n):
    pre_num = num
    num *= a[i]
    if i >= k:
        num /= a[i-k]
    if i >= k and num > pre_num:
        print('Yes')
    elif i >= k and num <= pre_num:
        print('No')


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

for i in range(n):
    if i >= k:
        if a[i] > a[i-k]:
            print('Yes')
        else:
            print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

for i in range(min(k, 50)):
    b = [0] * n
    b = np.array(b)
    for j in range(n):
        mi = max(0, j-a[j])
        ma = min(n-1, j+a[j])
        b[mi] += 1
        if ma + 1 <= n -1:
            b[ma+1] -= 1
    c = [0] * n
    s = 0
    for k in range(n):
        s += b[k]
        c[k] = s
    a = c

for i in a:
    print(i, end=' ')

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

for i in range(min(k, 45)):
    b = [0] * n
    for j in range(n):
        mi = max(0, j-a[j])
        ma = min(n-1, j+a[j])
        b[mi] += 1
        if ma + 1 <= n -1:
            b[ma+1] -= 1
    c = [0] * n
    s = 0
    for k in range(n):
        s += b[k]
        c[k] = s
    a = c

for i in a:
    print(i, end=' ')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
ans = [0 for _ in range(n)]

explored = [0]

for _ in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

q = deque()
parent = 0
for k in graph[0]:
    ans[k] = 0
    q.append(k)
    explored.append(k)
ans[0] = 0
while len(q) != 0:
    now = q.popleft()
    parent = now
    for node in graph[now]:
        if node not in explored:
            q.append(node)
            ans[node] = parent
            explored.append(node)

print('Yes')
for i in range(1, n):
    print(ans[i]+1)

Fixed submission:
from collections import deque

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
ans = [0 for _ in range(n)]

explored = {0}

for _ in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

q = deque()
parent = 0
for k in graph[0]:
    ans[k] = 0
    q.append(k)
    explored.add(k)
ans[0] = 0
while len(q) != 0:
    now = q.popleft()
    parent = now
    for node in graph[now]:
        if node not in explored:
            q.append(node)
            ans[node] = parent
            explored.add(node)

print('Yes')
for i in range(1, n):
    print(ans[i]+1)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1]
l = len(s)
MOD = 2019
ans = 0
mods = [0] * 2019
mods[0] = 1
num = 0
cnt = 0
for i in s:
    num += int(i) * (10**cnt)
    num %= MOD
    mods[num] += 1
    cnt += 1

for j in mods:
    ans += int(j*(j-1)/2)

print(ans)


Fixed submission:
s = input()[::-1]
l = len(s)
MOD = 2019
ans = 0
mods = [0] * 2019
mods[0] = 1
num = 0
cnt = 0
d = 1
for i in s:
    num += int(i) * d
    num %= MOD
    mods[num] += 1
    d *= 10
    d %= MOD

for j in mods:
    ans += int(j*(j-1)/2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import Counter

s = list(input())

l = len(s)
ans = 0

dp = np.zeros((3, l))

for i in range(l):
    dp[0][i] = int(s[i])
    dp[1][i] = (int(s[i]) * (10**(l-i-1))) % 2019

dp[2][l-1] = dp[0][l-1]

for i in range(l-2, -1, -1):
    dp[2][i] = (dp[1][i] + dp[2][i+1]) % 2019

c = Counter(dp[2])
for i, j in c.items():
    if i == 0:
        ans += int(j*(j+1)/2)
    elif j >= 2:
        ans += int(j*(j-1)/2)

print(ans)

Fixed submission:
s = input()[::-1]
l = len(s)
MOD = 2019
ans = 0
mods = [0] * 2019
mods[0] = 1
num = 0
cnt = 0
d = 1
for i in s:
    num += int(i) * d
    num %= MOD
    mods[num] += 1
    d *= 10
    d %= MOD

for j in mods:
    ans += int(j*(j-1)/2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
np.set_printoptions(suppress=True)
from collections import Counter
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

s = list(input())

l = len(s)
ans = 0

dp = np.zeros((3, l))

for i in range(l):
    dp[0][i] = int(s[i])
    dp[1][i] = (int(s[i]) * (10**(l-i-1))) % 2019

dp[2][l-1] = dp[0][l-1]

for i in range(l-2, -1, -1):
    c = i
    a = dp[1][i]
    b = dp[2][i+1]
    dp[2][i] = (dp[1][i] + dp[2][i+1]) % 2019

c = Counter(dp[2])
for i, j in c.items():
    if i == 0:
        ans += combinations_count(j+1, 2)
    elif j >= 2:
        ans += combinations_count(j, 2)

print(ans)

Fixed submission:
s = input()[::-1]
l = len(s)
MOD = 2019
ans = 0
mods = [0] * 2019
mods[0] = 1
num = 0
cnt = 0
d = 1
for i in s:
    num += int(i) * d
    num %= MOD
    mods[num] += 1
    d *= 10
    d %= MOD

for j in mods:
    ans += int(j*(j-1)/2)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

array = np.zeros(n+1)

for i in a:
    array[i] += 1

sum = 0
for i in array:
    if i > 1:
        sum += combinations_count(i, 2)

for i in a:
    tmp = sum
    if array[i] > 2:
        tmp -= (combinations_count(array[i],2) - combinations_count(array[i]-1, 2))
    elif array[i] == 2:
        tmp -= combinations_count(array[i], 2)
    elif array[i] == 1:
        tmp = tmp
    print(tmp)



Fixed submission:
from collections import Counter

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

c = Counter(a)

total = 0
for i in c.items():
    x = i[1]
    total += x*(x-1)//2

for i in a:
    ans = total
    ans -= (c[i] - 1)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

p = np.array(list(map(int, input().split())))

max = 0
index = 0
for j in range(n-k+1):
    goukei = sum(p[j:j+k])
    if goukei > max:
        max = goukei
        index = j

ans = 0
for i in range(index, index+k):
    ans += ((p[i]+1)*0.5)

print(ans)

Fixed submission:
import numpy as np

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

p = np.array(list(map(int, input().split())))


index = 0
goukei = sum(p[0:k])
max = goukei
for j in range(n-k):
    goukei = (goukei - p[j] + p[j+k])
    if goukei > max:
        max = goukei
        index = j+1

ans = 0
for i in range(index, index+k):
    ans += ((p[i]+1)*0.5)

print(ans)

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

p = list(map(int, input().split()))
hope_list = []
max = 0
index = 0
for j in range(n-k+1):
    goukei = sum(p[j:j+k])
    if goukei > max:
        max = goukei
        index = j

ans = 0
for i in range(index, index+k):
    ans += ((p[i]+1)*0.5)

print(ans)

Fixed submission:
import numpy as np

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

p = np.array(list(map(int, input().split())))


index = 0
goukei = sum(p[0:k])
max = goukei
for j in range(n-k):
    goukei = (goukei - p[j] + p[j+k])
    if goukei > max:
        max = goukei
        index = j+1

ans = 0
for i in range(index, index+k):
    ans += ((p[i]+1)*0.5)

print(ans)

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

p = list(map(int, input().split()))
hope_list = []

for i in p:
    hope_list.append((i+1)*0.5)

max = 0
for j in range(n-k+1):
    b = hope_list[j:j+k]
    goukei = sum(hope_list[j:j+k])
    if goukei > max:
        max = goukei

print(max)

Fixed submission:
import numpy as np

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

p = np.array(list(map(int, input().split())))


index = 0
goukei = sum(p[0:k])
max = goukei
for j in range(n-k):
    goukei = (goukei - p[j] + p[j+k])
    if goukei > max:
        max = goukei
        index = j+1

ans = 0
for i in range(index, index+k):
    ans += ((p[i]+1)*0.5)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce
MOD = 10**9 + 7
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)

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

num = lcm_list(a)
ans = 0
for i in a:
    ans += num // i
    ans %= MOD
    
print(ans)




Fixed submission:
import fractions
from functools import reduce
MOD = 10**9 + 7
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)

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

num = lcm_list(a)
ans = 0
for i in a:
    ans += num // i

ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

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

arm_list.sort(key=lambda x:x[1])


count = 1
a = arm_list[0][1]
b = arm_list[1][0]
for i in range(1, n-1):
    if a < b:
        count += 1
        a = arm_list[i][1]
        b = arm_list[i+1][0]
    else:
        b = arm_list[i+1][0]

if a < b:
    count += 1



print(count)

Fixed submission:
n = int(input())

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

arm_list.sort(key=lambda x:x[1])

if n == 1:
    print(1)
    exit()
count = 1
a = arm_list[0][1]
b = arm_list[1][0]
for i in range(1, n-1):
    if a < b:
        count += 1
        a = arm_list[i][1]
        b = arm_list[i+1][0]
    else:
        b = arm_list[i+1][0]

if a < b:
    count += 1



print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
MOD = 10**9 + 7
if k == 1:
    print(0)
    exit()


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


for min_index in range(n-k+1):
    for max_index in range(min_index+k-1, n):
        comb_num = combinations_count(max_index-min_index-1, k-2)
        ans += (a[max_index] - a[min_index]) * comb_num
    ans %= MOD

print(ans)


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
MOD = 10**9 + 7
if k == 1:
    print(0)
    exit()

mod = 10 ** 9 + 7
fact = [1]
fact_inv = [1]
for i in range(10 ** 5):
    new_fact = fact[-1] * (i + 1) % mod
    fact.append(new_fact)
    fact_inv.append(pow(new_fact, mod - 2, mod))


def cmb(n, k, mod=MOD):
    return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod


for max_index in range(k-1, n):
    ans += a[max_index] * cmb(max_index, k-1)
    ans %= MOD

for min_index in range(0, n-k+1):
    ans -= a[min_index] * cmb(n-(min_index+1), k-1)
    ans %= MOD

print(ans)

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

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
MOD = 10**9 + 7
if k == 1:
    print(0)
    exit()

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for min_index in range(n-k+1):
    for max_index in range(min_index+k-1, n):
        comb_num = combinations_count(max_index-min_index-1, k-2)
        ans += (a[max_index] - a[min_index]) * comb_num
        ans %= MOD

print(ans)


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
MOD = 10**9 + 7
if k == 1:
    print(0)
    exit()

mod = 10 ** 9 + 7
fact = [1]
fact_inv = [1]
for i in range(10 ** 5):
    new_fact = fact[-1] * (i + 1) % mod
    fact.append(new_fact)
    fact_inv.append(pow(new_fact, mod - 2, mod))


def cmb(n, k, mod=MOD):
    return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod


for max_index in range(k-1, n):
    ans += a[max_index] * cmb(max_index, k-1)
    ans %= MOD

for min_index in range(0, n-k+1):
    ans -= a[min_index] * cmb(n-(min_index+1), k-1)
    ans %= MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
import fractions
from functools import reduce

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

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)

b = lcm_list(a)

m -= int((b/2))
if m < 0:
    print(0)
    exit()

ans = (m//b) + 1
print(int(ans))

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

from fractions import gcd
from functools import reduce

a = [i >> 1 for i in a]

def applied_lcm(x, y):
    g = gcd(x, y)
    x //= g
    y //= g
    if x %2 == 0:
        return 0
    if y %2 == 0:
        return 0
    n = x * y * g
    if n >> 10**9:
        return 0

    return n

p = reduce(applied_lcm, a)
if p == 0:
    ans = 0
else:
    ans = (m//p) - (m//(p+p))
print(ans)

Buggy python submission (verdict: Runtime Error):
import fractions
from functools import reduce

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

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)

b = lcm_list(a)

m -= int((b/2))
if m < 0:
    print(0)
    exit()

ans = (m//b) + 1
print(int(ans))

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

from fractions import gcd
from functools import reduce

a = [i >> 1 for i in a]

def applied_lcm(x, y):
    g = gcd(x, y)
    x //= g
    y //= g
    if x %2 == 0:
        return 0
    if y %2 == 0:
        return 0
    n = x * y * g
    if n >> 10**9:
        return 0

    return n

p = reduce(applied_lcm, a)
if p == 0:
    ans = 0
else:
    ans = (m//p) - (m//(p+p))
print(ans)

Buggy python submission (verdict: Runtime Error):
import fractions
from functools import reduce

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

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)

b = lcm_list(a)

m -= (b/2)

ans = (m//b) + 1
print(int(ans))

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

from fractions import gcd
from functools import reduce

a = [i >> 1 for i in a]

def applied_lcm(x, y):
    g = gcd(x, y)
    x //= g
    y //= g
    if x %2 == 0:
        return 0
    if y %2 == 0:
        return 0
    n = x * y * g
    if n >> 10**9:
        return 0

    return n

p = reduce(applied_lcm, a)
if p == 0:
    ans = 0
else:
    ans = (m//p) - (m//(p+p))
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

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


a, b = map(int, input().split())
c = lcm(a, b)
print(c)

Fixed submission:
import fractions

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


a, b = map(int, input().split())
c = lcm(a, b)
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7


def cal_xor(max_num, cnt, exp):
    return cnt * (max_num - cnt) * (2 ** exp)


dig = len(format(max(a), 'b'))
bi_digit_cnt = [0] * dig
for i in a:
    bi_i = format(i, 'b').zfill(dig)
    for j in range(len(bi_i)):
        if bi_i[-1-j] == '1':
            bi_digit_cnt[j] += 1

ans = 0

for i in range(dig):
    ans += cal_xor(n, bi_digit_cnt[i], i)
    ans %= MOD

print(ans)

Fixed submission:
import numpy as np

MOD = 10**9 + 7
n = int(input())
a = np.array(input().split(), np.int64)
max_num = np.max(a)
digit_num = len(format(max_num, 'b'))
ans = 0
for digit in range(digit_num):
    b = (a >> digit) & 1
    one = np.count_nonzero(b)
    zero = n - one
    ans += 2 ** digit * (one * zero)
    ans %= MOD

print(ans)

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


final_ans = 0
num = 1000000007
a.sort()

for i in range(n-1):
    if i != 0:
        if a[i] == a[i-1]:
            final_ans += ans
            final_ans %= num
            continue
        else:
            ans = 0
            for j in range(i+1, n):
                ans += (a[i] ^ a[j])
                ans %= num
            final_ans += ans
            final_ans %= num
    else:
        ans = 0
        for j in range(i+1, n):
            ans += (a[i] ^ a[j])
            ans %= num
        final_ans += ans
        final_ans %= num

print(final_ans)

Fixed submission:
import numpy as np

MOD = 10**9 + 7
n = int(input())
a = np.array(input().split(), np.int64)
max_num = np.max(a)
digit_num = len(format(max_num, 'b'))
ans = 0
for digit in range(digit_num):
    b = (a >> digit) & 1
    one = np.count_nonzero(b)
    zero = n - one
    ans += 2 ** digit * (one * zero)
    ans %= MOD

print(ans)

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

ans = 0
num = 1000000007

for i in range(n-1):
    for j in range(i, n):
        ans += (a[i] ^ a[j])
        ans %= num

print(ans)

Fixed submission:
import numpy as np

MOD = 10**9 + 7
n = int(input())
a = np.array(input().split(), np.int64)
max_num = np.max(a)
digit_num = len(format(max_num, 'b'))
ans = 0
for digit in range(digit_num):
    b = (a >> digit) & 1
    one = np.count_nonzero(b)
    zero = n - one
    ans += 2 ** digit * (one * zero)
    ans %= MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

num = 1000000007
x, y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
    exit()

grad = y / x
if grad < 0.5 or grad > 2:
    print(0)
    exit()

turns = int((x + y) / 3)

total = 0
t = (x + y) // 2
u = t - min(x, y)
o = t // 3 - u

total = combinations_count(turns, o)
total %= num
print(total)

Fixed submission:
import math


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result



num = 1000000007
x, y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
    exit()

grad = y / x
if grad < 0.5 or grad > 2:
    print(0)
    exit()

turns = int((x + y) / 3)

total = 0
t = (x + y) // 2
u = t - min(x, y)
o = t // 3 - u

total = cmb(turns, o)
total %= num
print(total)