Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
a_i = [i - aa for i, aa in enumerate(a)]
a_j = [j + aa for j, aa in enumerate(a)]
ans = 0
for i in a_i:
    ans += a_j.count(i)    
print(ans)

Fixed submission:
import collections

n = int(input())
a = [int(i) for i in input().split()]
a_i = [i - aa for i, aa in enumerate(a)]
a_j = [j + aa for j, aa in enumerate(a)]

ci = collections.Counter(a_i)
cj = collections.Counter(a_j)
ans = 0
for item, value in ci.items():
    if item in cj.keys():
        ans += cj[item] * ci[item]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    for j in range(i, n):
        if a[i] + a[j] == abs(i - j):
            ans += 1
print(ans)

Fixed submission:
import collections

n = int(input())
a = [int(i) for i in input().split()]
a_i = [i - aa for i, aa in enumerate(a)]
a_j = [j + aa for j, aa in enumerate(a)]

ci = collections.Counter(a_i)
cj = collections.Counter(a_j)
ans = 0
for item, value in ci.items():
    if item in cj.keys():
        ans += cj[item] * ci[item]
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
value = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    value.append([a - 1, b - 1, c, d])
value.sort()
ans_list = []
for i in range(2 **q):
    t = '0' * (q - len(bin(i)[2:])) + bin(i)[2:]
    dp = [1] * m
    dp_k = [0] * m
    ans = 0
    for j, tt in enumerate(t):
        if tt == '1':
            if dp_k[value[j][1]] == 0:
                dp[value[j][1]] = dp[value[j][0]] + value[j][2]
                dp_k[value[j][1]] = 1
                if dp[value[j][1]] <= m:
                    ans += value[j][3]
                else:
                    ans = 0
                    break
            elif dp_k[value[j][1]] == 1:
                if dp[value[j][1]] == dp[value[j][0]] + value[j][2]:
                    ans += value[j][3]
                else:
                    ans = 0
                    break
            else:
                ans = 0
                break
    ans_list.append(ans)
print(max(ans_list))        

Fixed submission:
import itertools

n, m, q = map(int, input().split())
value = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    value.append([a - 1, b - 1, c, d])
ans = 0
for comb in itertools.combinations_with_replacement(range(1, m + 1), n):
    temp = 0
    for v in value:
        if comb[v[1]] == comb[v[0]] + v[2]:
            temp += v[3]
    ans = max(ans, temp)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
value = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    value.append([a - 1, b - 1, c, d])
value.sort()
ans_list = []
for i in range(2 **q):
    t = '0' * (q - len(bin(i)[2:])) + bin(i)[2:]
    dp = [1] * m
    dp_k = [0] * m
    ans = 0
    for j, tt in enumerate(t):
        if tt == '1':
            if dp_k[value[j][1]] == 0:
                dp[value[j][1]] = dp[value[j][0]] + value[j][2]
                dp_k[value[j][1]] = 1
                if dp[value[j][1]] <= m:
                    ans += value[j][3]
                else:
                    ans = 0
                    break
            elif dp_k[value[j][1]] == 1:
                if dp[value[j][1]] == dp[value[j][0]] + value[j][2]:
                    ans += value[j][3]
                else:
                    ans = 0
                    break
            else:
                ans = 0
                break
    ans_list.append(ans)
print(max(ans_list))        

Fixed submission:
import itertools

n, m, q = map(int, input().split())
value = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    value.append([a - 1, b - 1, c, d])
ans = 0
for comb in itertools.combinations_with_replacement(range(1, m + 1), n):
    temp = 0
    for v in value:
        if comb[v[1]] == comb[v[0]] + v[2]:
            temp += v[3]
    ans = max(ans, temp)
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, n = map(int, input().split())
print(math.floor(a * min((b - 1), n) / b))

Fixed submission:
import math
a, b, n = map(int, input().split())
print(math.floor(a * min((b - 1), n) / b))
Buggy python submission (verdict: Time Limit Exceeded):
import math
x = int(input())
ans = 0
for i in range(1, x + 1):
    for j in range(1, x + 1):
        for k in range(1, x + 1):
            ans += math.gcd(math.gcd(i, j), k)
print(ans)

Fixed submission:
import math
x = int(input())
ans = 0
for i in range(1, x + 1):
    for j in range(1, x + 1):
        for k in range(1, x + 1):
            ans += math.gcd(math.gcd(i, j), k)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r * g * b
for i in range(1, (n // 2) + 1):
    for j in range(0, n - (2 * i) + 1):
        if j + (2 * i) >= n:
            break
        if ((s[j] != s[j + i]) & (s[j] != s[j + (2 * i)]) & (s[i + j] != s[j + (2 * i)])):
            ans -= 1
        
print(ans)

Fixed submission:
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = n - r - g

ans = r * g * b
for i in range(1, (n // 2) + 1):
    for j in range(0, n - (2 * i) + 1):
        if j + (2 * i) >= n:
            break
        if ((s[j] != s[j + i]) & (s[j] != s[j + (2 * i)]) & (s[i + j] != s[j + (2 * i)])):
            ans -= 1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r_list = set([])
b_list = set([])
g_list = set([])

for i in range(n):
    if s[i] == 'R':
        r_list.add(i)
    elif s[i] == 'B':
        b_list.add(i)
    else:
        g_list.add(i)
        
ans = 0
for r in r_list:
    for b in b_list:
        ans += len(g_list - {2 * b - r, 2 * r - b, (b + r) / 2})
print(ans)

Fixed submission:
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = n - r - g

ans = r * g * b
for i in range(1, (n // 2) + 1):
    for j in range(0, n - (2 * i) + 1):
        if j + (2 * i) >= n:
            break
        if ((s[j] != s[j + i]) & (s[j] != s[j + (2 * i)]) & (s[i + j] != s[j + (2 * i)])):
            ans -= 1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r_list = set([])
b_list = set([])
g_list = set([])

for i in range(n):
    if s[i] == 'R':
        r_list.add(i)
    elif s[i] == 'B':
        b_list.add(i)
    else:
        g_list.add(i)
        
ans = 0
for r in r_list:
    for b in b_list:
        ans += len(g_list - {2 * b - r, 2 * r - b, (b + r) / 2})
print(ans)

Fixed submission:
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = n - r - g

ans = r * g * b
for i in range(1, (n // 2) + 1):
    for j in range(0, n - (2 * i) + 1):
        if j + (2 * i) >= n:
            break
        if ((s[j] != s[j + i]) & (s[j] != s[j + (2 * i)]) & (s[i + j] != s[j + (2 * i)])):
            ans -= 1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            if (j - i) != (k - j):
                if ((s[i] != s[j]) & (s[i] != s[k]) & (s[j] != s[k])):
                    ans += 1
print(ans)

Fixed submission:
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = n - r - g

ans = r * g * b
for i in range(1, (n // 2) + 1):
    for j in range(0, n - (2 * i) + 1):
        if j + (2 * i) >= n:
            break
        if ((s[j] != s[j + i]) & (s[j] != s[j + (2 * i)]) & (s[i + j] != s[j + (2 * i)])):
            ans -= 1
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x, y, a, b, c = map(int, input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]

p = list(reversed(sorted(p)))
q = list(reversed(sorted(q)))
r = list(reversed(sorted(r)))
p_cum = [0]
q_cum = [0]
r_cum = [0]
for i in range(a):
    p_cum.append(p_cum[i] + p[i])
for i in range(b):
    q_cum.append(q_cum[i] + q[i])
for i in range(c):
    r_cum.append(r_cum[i] + r[i])
ans = 0
for i in range(0, min(c, x) + 1):
    for j in range(0, min(c - i, y) + 1):
        ans = max(ans, p_cum[x - i] + q_cum[y - j] + r_cum[i + j])
print(ans)

Fixed submission:
x, y, a, b, c = map(int, input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]

p = list(reversed(sorted(p)))
q = list(reversed(sorted(q)))
r = list(reversed(sorted(r)))
apple = p[:x] + q[:y] + r
apple = list(reversed(sorted(apple)))
print(sum(apple[:x+y]))

Buggy python submission (verdict: Time Limit Exceeded):
x, y, a, b, c = map(int, input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]

p = list(reversed(sorted(p)))
q = list(reversed(sorted(q)))
r = list(reversed(sorted(r)))
p_cum = [0]
q_cum = [0]
r_cum = [0]
for i in range(a):
    p_cum.append(p_cum[i] + p[i])
for i in range(b):
    q_cum.append(q_cum[i] + q[i])
for i in range(c):
    r_cum.append(r_cum[i] + r[i])
ans = 0
for i in range(0, min(c, x) + 1):
    for j in range(0, min(c - i, y) + 1):
        ans = max(ans, p_cum[x - i] + q_cum[y - j] + r_cum[i + j])
print(ans)

Fixed submission:
x, y, a, b, c = map(int, input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]

p = list(reversed(sorted(p)))
q = list(reversed(sorted(q)))
r = list(reversed(sorted(r)))
apple = p[:x] + q[:y] + r
apple = list(reversed(sorted(apple)))
print(sum(apple[:x+y]))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h, w = map(int, input().split())
s_list = []
for _ in range(h):
    s = input()
    s_list.append(s)
d = deque()
count = 0
if s_list[0][0] == '#':
    count += 1
d.append([0, 0, count])

ans = 101
while d:
    x, y, count = d.pop()
    for xx, yy in [[1, 0], [0, 1]]:
        if (0 <= x + xx < h) & (0 <= y + yy < w):
            if (s_list[x + xx][y + yy] == '#') & (s_list[x][y] == '.'):
                d.append([x + xx, y + yy, count + 1])
            else:
                d.append([x + xx, y + yy, count])
        if (x + xx == h - 1) & (y + yy == w - 1):
            if s_list[x + xx][y + yy] == '#':
	            ans = min(ans, count + 1)
            else:
                ans = min(ans, count)
print(ans)

Fixed submission:
from collections import deque
h, w = map(int, input().split())
s_list = []
for _ in range(h):
    s = input()
    s_list.append(s)
d = deque()
count = 0
if s_list[0][0] == '#':
    count += 1
d.append([0, 0, count])

vis = [[101 for i in range(w)] for j in range(h)]
if s_list[0][0] == '.':
    vis[0][0] = 0
else:
    vis[0][0] = 1
for x in range(h):
    for y in range(w):
        for xx, yy in [[1, 0], [0, 1]]:
            if (0 <= x + xx < h) & (0 <= y + yy < w):
                if (s_list[x][y] == '.') & (s_list[x + xx][y + yy] == '#'):
                    vis[x + xx][y + yy] = min(vis[x][y] + 1, vis[x + xx][y + yy])
                else:
                    vis[x + xx][y + yy] = min(vis[x][y], vis[x + xx][y + yy])          
print(vis[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h, w = map(int, input().split())
s_list = []
for _ in range(h):
    s = input()
    s_list.append(s)
d = deque()
count = 0
if s_list[0][0] == '#':
    count += 1
d.append([0, 0, count])

ans = 101
while d:
    x, y, count = d.pop()
    for xx, yy in [[1, 0], [0, 1]]:
        if (0 <= x + xx < h) & (0 <= y + yy < w):
            if (s_list[x + xx][y + yy] == '#') & (s_list[x][y] == '.'):
                d.append([x + xx, y + yy, count + 1])
            else:
                d.append([x + xx, y + yy, count])
        if (x + xx == h - 1) & (y + yy == w - 1):
            if s_list[x + xx][y + yy] == '#':
	            ans = min(ans, count + 1)
            else:
                ans = min(ans, count)
print(ans)

Fixed submission:
from collections import deque
h, w = map(int, input().split())
s_list = []
for _ in range(h):
    s = input()
    s_list.append(s)
d = deque()
count = 0
if s_list[0][0] == '#':
    count += 1
d.append([0, 0, count])

vis = [[101 for i in range(w)] for j in range(h)]
if s_list[0][0] == '.':
    vis[0][0] = 0
else:
    vis[0][0] = 1
for x in range(h):
    for y in range(w):
        for xx, yy in [[1, 0], [0, 1]]:
            if (0 <= x + xx < h) & (0 <= y + yy < w):
                if (s_list[x][y] == '.') & (s_list[x + xx][y + yy] == '#'):
                    vis[x + xx][y + yy] = min(vis[x][y] + 1, vis[x + xx][y + yy])
                else:
                    vis[x + xx][y + yy] = min(vis[x][y], vis[x + xx][y + yy])          
print(vis[-1][-1])
Buggy python submission (verdict: Runtime Error):
def calc(a):
    y = 0
    for xx in x:
        y += (a - xx) ** 2
    return y


n = int(input())
x = [int(i) for i in input().split()]
left = min(x)
right = max(x)
while (right - left > 1):
    l = calc(left)
    r = calc(right)
    if (l < r):
        right = (right + left) // 2
    else:
        left = (right + left) // 2
print(min(r, l))

Fixed submission:
def calc(a):
    y = 0
    for xx in x:
        y += (a - xx) ** 2
    return y


n = int(input())
x = [int(i) for i in input().split()]
left = min(x)
right = max(x)
while (right - left > 1):
    l = calc(left)
    r = calc(right)
    if (l < r):
        right = (right + left) // 2
    else:
        left = (right + left) // 2
print(min(calc(left), calc(right)))

Buggy python submission (verdict: Runtime Error):
def calc(a):
    y = 0
    for xx in x:
        y += (a - xx) ** 2
    return y


n = int(input())
x = [int(i) for i in input().split()]
left = min(x)
right = max(x)
while (right - left > 1):
    l = calc(left)
    r = calc(right)
    if (l < r):
        right = (right + left) // 2
    else:
        left = (right + left) // 2
print(r)

Fixed submission:
def calc(a):
    y = 0
    for xx in x:
        y += (a - xx) ** 2
    return y


n = int(input())
x = [int(i) for i in input().split()]
left = min(x)
right = max(x)
while (right - left > 1):
    l = calc(left)
    r = calc(right)
    if (l < r):
        right = (right + left) // 2
    else:
        left = (right + left) // 2
print(min(calc(left), calc(right)))
Buggy python submission (verdict: Time Limit Exceeded):
import math

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

t = (10 ** 9) + 7
n = n % t
A = (math.factorial(n) / (math.factorial(a) * math.factorial(n - a))) % t
B = (math.factorial(n) / (math.factorial(b) * math.factorial(n - b))) % t
ans = ((2 ** n) - 1 - A - B) % t
print(int(ans))

Fixed submission:
def calc(n, x):
    up = 1
    bottom = 1
    for i in range(x):
        up *= (n - i)
        up = up % mod
        bottom *= (i + 1)
        bottom = bottom % mod
    return (up * pow(bottom, mod - 2, mod)) % mod

mod = (10 ** 9) + 7

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

ans = pow(2, n, mod) - 1
for i in [a, b]:
    ans -= calc(n, i)
print(ans % mod)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
n, k = map(int, input().split())
p = list(map(int, input().split()))
pp = list(accumulate(p))
ppp = [pp[i + k] - pp[i] + k for i in range(len(p) - k)]
print((max(ppp)) / 2)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
p = list(map(int, input().split()))
if (n != k):
    pp = list(accumulate(p))
    ppp = [pp[i + k] - pp[i] + k for i in range(len(p) - k)]
    print((max(ppp)) / 2)
else:
    print((sum(p) + n) / 2)
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
a_list = []
b_list = []

for _ in range(n):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

max_a = max(a_list)    
dp = [float('inf')] * (h + max_a + 1)

dp[0] = 0
cost = float('inf')
for i in range(h):
    for j in range(n):
        dp[i + a_list[j]] = min(dp[i] + b_list[j], dp[i + a_list[j]])
        if i + a_list[j] >= h:
            cost = min(cost, dp[i + a_list[j]])
print(cost)

Fixed submission:
h, n = map(int, input().split())
a_list = []
b_list = []

for _ in range(n):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

max_a = max(a_list)    
dp = [float('inf')] * (h + max_a + 1)

dp[0] = 0
for i in range(h):
    for j in range(n):
        dp[i + a_list[j]] = min(dp[i] + b_list[j], dp[i + a_list[j]])
print(min(dp[h:]))

Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
a_list = []
b_list = []

for _ in range(n):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

max_a = max(a_list)    
dp = [float('inf')] * (h + max_a + 1)

dp[0] = 0
for i in range(h):
    for j in range(n):
        dp[i + a_list[j]] = min(dp[i] + b_list[j], dp[i + a_list[j]])
print(min(dp[h:]))

Fixed submission:
h, n = map(int, input().split())
a_list = []
b_list = []

for _ in range(n):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

max_a = max(a_list)    
dp = [float('inf')] * (h + max_a + 1)

dp[0] = 0
for i in range(h):
    for j in range(n):
        dp[i + a_list[j]] = min(dp[i] + b_list[j], dp[i + a_list[j]])
print(min(dp[h:]))
Buggy python submission (verdict: Runtime Error):
import math
from bisect import bisect_left

n, d, a = map(int, input().split())
x_list = []
max_x = 0
for _ in range(n):
    x, h = map(int, input().split())
    x -= 1
    x_list.append([x, h])
    max_x = max(max_x, x)
x_list.sort()
xx = [x[0] for x in x_list]
ans = 0
for index_left, [x, h] in enumerate(c):
    if h > 0:
        ans += math.ceil(h / a)
        index_right = bisect_left(xx, x + (d * 2))
        for i in range(index_left, min(index_right + 1, n)):
            x_list[i][1] -= math.ceil(h / a) * a
print(ans)

Fixed submission:
import math
from bisect import bisect_right

n, d, a = map(int, input().split())
x_list = []
max_x = 0
for _ in range(n):
    x, h = map(int, input().split())
    x -= 1
    x_list.append([x, h])
    max_x = max(max_x, x)
x_list.sort()
xx = [x[0] for x in x_list]
hh = [x[1] for x in x_list]
ans = 0
accum = [0 for _ in range(n)]
for index, [x, h] in enumerate(x_list):
    if index != 0:
        accum[index] += accum[index - 1]
    cnt = max(math.ceil((hh[index] - accum[index]) / a),  0)
    ans += cnt
    index_right = bisect_right(xx, xx[index] + (2 * d))
    accum[index] += cnt * a
    if index_right < n:
        accum[index_right] -= cnt * a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def prime(x):
    if x == 2:
        return 2
    num_list = list(range(3, (10 ** 5) * 2, 2))
    n = 3
    while (n < x):        
        num_list = [num for num in num_list if ((num % n) != 0)]
        n = num_list.pop(0)
    return n

x = int(input())
print(prime(x))

Fixed submission:
import math


def is_prime(x):
    for i in range(3, math.ceil((x ** 0.5) + 1), 2):
        if x % i == 0:
            return False
    return True

x = int(input())

if x == 2:
    print(2)
else:
    if x % 2 == 0:
        x += 1
    while (not is_prime(x)):
        x += 2
    print(x)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

ans = 0
point_dict = {'r': p, 's': r, 'p': s }
for i in range(k):
    t_x = t[i::k]
    point_0 = 0
    point_1 = 0
    for j in range(len(t_x)):        
        if (j % 2) == 0:
            if (t_x[j] != t_x[j - 1 if j - 1 >= 0 else 1]) & (t_x[j] != t_x[j + 1 if j + 1 < len(t_x) else len(t_x) - 1]):
                point_0 += point_dict[t_x[j]]
            point_1 += point_dict[t_x[j]]
        else:
            if (t_x[j] != t_x[j - 1 if j - 1 >= 0 else 1]) & (t_x[j] != t_x[j + 1 if j + 1 < len(t_x) else len(t_x) - 1]):
                point_1 += point_dict[t_x[j]]
            point_0 += point_dict[t_x[j]]
    ans += max(point_0, point_1)
print(ans)

Fixed submission:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
dp = [3] * k
point = 0
choice = (r, s, p)
t = t.replace('r', '2').replace('s', '0').replace('p', '1')
for j, i in enumerate(t):
    if dp[j % k] != int(i):
        point += choice[int(i)]
        dp[j % k] = int(i)
    else:
        dp[j % k] = 3
print(point)
Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
print(int(a * b / (math.gcd(a, b))))

Fixed submission:
import fractions
a, b = map(int, input().split())
print(int(a * b / (fractions.gcd(a, b))))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
mod = (10 ** 9) + 7
max_a = max(a)
ans = 0
for j in range(len(bin(max(a))) - 2):
    t = sum([1 & i for i in a]) 
    ans += (2 ** j) * t * (n - t)
    a = [i >> 1 for i in a]
    ans = ans % mod
print(ans)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
mod = (10 ** 9) + 7
max_a = max(a)
ans = 0
for j in range(len(bin(max(a))) - 2):
    t = sum([1 & i for i in a]) 
    ans += (2 ** j) * t * (n - t)
    a = [i >> 1 for i in a]
    ans = ans % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
t = []
mod = (10 ** 9) + 7
count = 0
max_a = max(a)
for _ in range(len(bin(max(a))) - 2):
    t.append(sum([1 & i for i in a]))
    a = [i >> 1 for i in a]
    count += 1
ans = 0
for i, j in zip(t, range(count)):
    ans += i * (n - i) * (2 ** j)
    ans = ans % mod
print(ans)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
mod = (10 ** 9) + 7
max_a = max(a)
ans = 0
for j in range(len(bin(max(a))) - 2):
    t = sum([1 & i for i in a]) 
    ans += (2 ** j) * t * (n - t)
    a = [i >> 1 for i in a]
    ans = ans % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
t = []
mod = (10 ** 9) + 7
count = 0
while sum(a) > 0:
    t.append(sum([1 & i for i in a]))
    a = [i >> 1 for i in a]
    count += 1
ans = 0
for i, j in zip(t, range(count)):
    ans += i * (n - i) * (2 ** j)
    ans = ans % mod
print(ans)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
mod = (10 ** 9) + 7
max_a = max(a)
ans = 0
for j in range(len(bin(max(a))) - 2):
    t = sum([1 & i for i in a]) 
    ans += (2 ** j) * t * (n - t)
    a = [i >> 1 for i in a]
    ans = ans % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
for i in a:
    for j in a:
        ans += i ^ j
print(ans // 2 % mod)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
mod = (10 ** 9) + 7
max_a = max(a)
ans = 0
for j in range(len(bin(max(a))) - 2):
    t = sum([1 & i for i in a]) 
    ans += (2 ** j) * t * (n - t)
    a = [i >> 1 for i in a]
    ans = ans % mod
print(ans)