Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
input()
ans = 'ABC' if s == 'ARC' else 'ARC'
print(ans)


Fixed submission:
s = input()
ans = 'ABC' if s == 'ARC' else 'ARC'
print(ans)
Buggy python submission (verdict: Runtime Error):
X = int(input())
for i in range(1, 10**9):
    if pow(i, 5, X-1) == 0:
        a = i

print(a, -1)


Fixed submission:
X = int(input())
for a in range(-200, 200):
    for b in range(-200, 200):
        if a**5 - b**5 == X:
            print(a, b)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

s = list(map(int, list(input())))[::-1]
N = len(s)
cusum = [0]*(N+1)
cusum[0] = s[0] % 2019
power = 1
for i in range(1, N):
    power = 10**i % 2019
    cusum[i] = (cusum[i-1] + power * s[i]) % 2019
counter = Counter(cusum)
print(sum(x*(x-1)//2 for x in counter.values()))


Fixed submission:
from collections import Counter

s = list(map(int, list(input())))[::-1]
N = len(s)
cusum = [0]*(N+1)
cusum[0] = s[0] % 2019
for i in range(1, N):
    power = pow(10, i, 2019)
    cusum[i] = (cusum[i-1] + power * s[i]) % 2019
counter = Counter(cusum)
print(sum(x*(x-1)//2 for x in counter.values()))
Buggy python submission (verdict: Time Limit Exceeded):
# from pprint import pprint
n = int(input())
a = map(int, input().split())
a = sorted(((ax, x) for x, ax in enumerate(a)), reverse=True)
dp = [[-1] * (n+1) for _ in range(n+1)]
dp[0][0] = 0
for i, (ax, x) in enumerate(a):
    for j in range(i+1):
        dp[j+1][i-j] = max(dp[j+1][i-j], dp[j][i-j] + ax*abs(x-j))
        dp[j][i-j+1] = max(dp[j][i-j+1], dp[j][i-j] + ax*abs(n-1-x-i+j))
# pprint(dp)
print(max(dp[i][n-i] for i in range(n+1)))


Fixed submission:
#  from pprint import pprint
n = int(input())
a = map(int, input().split())
a = sorted(((ax, x) for x, ax in enumerate(a)), reverse=True)
dp = [[-1] * (n+1) for _ in range(n+1)]
dp[0][0] = 0
for i, (ax, x) in enumerate(a):
    for j in range(i+1):
        dp[j+1][i-j] = max(dp[j+1][i-j], dp[j][i-j] + ax*abs(x-j))
        dp[j][i-j+1] = max(dp[j][i-j+1], dp[j][i-j] + ax*abs(n-1-x-i+j))
# pprint(dp)
print(max(dp[i][n-i] for i in range(n+1)))

Buggy python submission (verdict: Time Limit Exceeded):
from pprint import pprint
n = int(input())
a = map(int, input().split())
a = sorted(((ax, x) for x, ax in enumerate(a)), reverse=True)
dp = [[-1] * (n+1) for _ in range(n+1)]
dp[0][0] = 0
for i, (ax, x) in enumerate(a):
    for j in range(i+1):
        dp[j+1][i-j] = max(dp[j+1][i-j], dp[j][i-j] + ax*abs(x-j))
        dp[j][i-j+1] = max(dp[j][i-j+1], dp[j][i-j] + ax*abs(n-1-x-i+j))
# pprint(dp)
print(max(dp[i][n-i] for i in range(n+1)))


Fixed submission:
#  from pprint import pprint
n = int(input())
a = map(int, input().split())
a = sorted(((ax, x) for x, ax in enumerate(a)), reverse=True)
dp = [[-1] * (n+1) for _ in range(n+1)]
dp[0][0] = 0
for i, (ax, x) in enumerate(a):
    for j in range(i+1):
        dp[j+1][i-j] = max(dp[j+1][i-j], dp[j][i-j] + ax*abs(x-j))
        dp[j][i-j+1] = max(dp[j][i-j+1], dp[j][i-j] + ax*abs(n-1-x-i+j))
# pprint(dp)
print(max(dp[i][n-i] for i in range(n+1)))
Buggy python submission (verdict: Runtime Error):
import sys
from functools import lru_cache
sys.setrecursionlimit(10**9)
k = int(input())
lunlun = []


@lru_cache(maxsize=100000000)
def func(i):
    if int(i) > 3234566667 + 10 or len(i) > 6:
        return
    lunlun.append(int(i))
    f = int(i[0])
    b = int(i[-1])
    if f != 0:
        func(f'{f-1}{i}')
    if f != 9:
        func(f'{f+1}{i}')
    func(f'{f}{i}')
    if b != 0:
        func(f'{i}{b-1}')
    if b != 9:
        func(f'{i}{b+1}')
    func(f'i}{b}')


for i in range(10):
    func(str(i))
lunlun = sorted(set(lunlun))
print(len(lunlun))
print(lunlun[k])


Fixed submission:
from collections import deque

k = int(input())
q = deque(range(1, 10))
for _ in range(k):
    x = q.popleft()
    r = x % 10
    if r != 0:
        q.append(10*x + (r - 1))
    q.append(10*x+r)
    if r != 9:
        q.append(10*x + (r + 1))
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int, input().split())
ans = [0] * (n - 1)
x -= 1
y -= 1
for i in range(n-1):
    for j in range(i+1, n):
        d = min(abs(y-i)+abs(y-j), abs(x-i)+abs(x-j), abs(i-j),
                abs(y-i)+abs(x-j)+1, abs(x-i)+abs(y-j)+1) - 1
        if i == x and j == y:
            d = 0
        # print(i, j, d)
        ans[d] += 1
print(*ans, sep='\n')


Fixed submission:
n, x, y = map(int, input().split())
ans = [0] * (n - 1)
x -= 1
y -= 1
for i in range(n-1):
    for j in range(i+1, n):
        d = min(abs(y-i)+abs(y-j), abs(x-i)+abs(x-j), abs(i-j),
                abs(y-i)+abs(x-j)+1, abs(x-i)+abs(y-j)+1) - 1
        if i == x and j == y:
            d = 0
        # print(i, j, d)
        ans[d] += 1
print(*ans, sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import accumulate

readline = sys.stdin.readline
INF = 10 ** 9
h, w, k = map(int, readline().split())
s = [readline() for _ in range(h)]

ans = INF
for bit in range(2**h-1):
    cut = bin(bit).count('1')
    group = 0
    peace = [[0] * (bin(bit).count('1') + 1) for _ in range(w)]

    for i in range(w):
        group = 0
        for j in range(h):
            if s[j][i] == '1':
                peace[i][group] += 1
            if bit >> j & 1:
                group += 1

    if any(max(col) > k for col in peace):
        continue
    current = [0] * (bin(bit).count('1') + 1)
    for i in range(w):
        current = list(map(sum, zip(current, peace[i])))
        if max(current) > k:
            cut += 1
            current = peace[i]
    if ans > cut:
        ans = cut

print(ans)


Fixed submission:
import sys
from itertools import accumulate

readline = sys.stdin.readline
INF = 10 ** 9
h, w, k = map(int, readline().split())
s = [readline() for _ in range(h)]

ans = INF
for bit in range(2**h-1):
    cut = bin(bit).count('1')
    group = 0
    peace = [[0] * (bin(bit).count('1') + 1) for _ in range(w)]

    for i in range(w):
        group = 0
        for j in range(h):
            if s[j][i] == '1':
                peace[i][group] += 1
            if bit >> j & 1:
                group += 1

    if any(max(col) > k for col in peace):
        continue
    current = [0] * (bin(bit).count('1') + 1)
    for i in range(w):
        current = list(map(sum, zip(current, peace[i])))
        if max(current) > k:
            cut += 1
            current = peace[i]
    if ans > cut:
        ans = cut

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

readline = sys.stdin.readline
s = list(readline().strip())
n = int(readline())
q = sys.stdin.readlines()
reverse = False
for qi in q:
    if qi[0] == '1':
        reverse = not reverse
    else:
        c = qi[4]
        if qi[2] == '2':
            if reverse:
                s = [c] + s
            else:
                s.append(c)
        else:
            if reverse:
                s.append(c)
            else:
                s = [c] + s
if reverse:
    s = reversed(s)
print(''.join(s))


Fixed submission:
import sys
from collections import deque

readline = sys.stdin.readline
s = deque(readline().strip())
n = int(readline())
q = sys.stdin.readlines()
reverse = False
for qi in q:
    if qi[0] == '1':
        reverse = not reverse
    else:
        c = qi[4]
        if qi[2] == '2':
            if reverse:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if reverse:
                s.append(c)
            else:
                s.appendleft(c)
if reverse:
    s = reversed(list(s))
print(''.join(s))

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

readline = sys.stdin.readline
s = list(readline().strip())
n = int(readline())
q = sys.stdin.readlines()
reverse = False
for qi in q:
    if qi[0] == '1':
        reverse = not reverse
    else:
        c = qi[4]
        if qi[2] == '2':
            if reverse:
                s = [c] + s
            else:
                s.append(c)
        else:
            if reverse:
                s.append(c)
            else:
                s = [c] + s
if reverse:
    s = reversed(s)
print(''.join(s))


Fixed submission:
import sys
from collections import deque

readline = sys.stdin.readline
s = deque(readline().strip())
n = int(readline())
q = sys.stdin.readlines()
reverse = False
for qi in q:
    if qi[0] == '1':
        reverse = not reverse
    else:
        c = qi[4]
        if qi[2] == '2':
            if reverse:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if reverse:
                s.append(c)
            else:
                s.appendleft(c)
if reverse:
    s = reversed(list(s))
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    x = 10 ** 20
    for i in range(N):
        if x >= P[i]:
            x = P[i]
            n += 1
	print(n)
resolve()

Fixed submission:
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    x = 10 ** 20
    for i in range(N):
        if x >= P[i]:
            x = P[i]
            n += 1
    print(n)

resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    x = 10 ** 20
    for i in range(N):
      if x < P[i]:
        continue
      else:
        x = P[i]
        for j in range(i):
            if P[i] > P[j]:
                break
        else:
            n += 1
    print(n)

resolve()

Fixed submission:
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    x = 10 ** 20
    for i in range(N):
        if x >= P[i]:
            x = P[i]
            n += 1
    print(n)

resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    for idx, i in enumerate(P):
        for j in P[:idx]:
            if i > j:
                break
        else:
            n += 1
    print(n)

resolve()

Fixed submission:
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    x = 10 ** 20
    for i in range(N):
        if x >= P[i]:
            x = P[i]
            n += 1
    print(n)

resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    for i in range(N):
        for j in range(i):
            if P[i] > P[j]:
                break
        else:
            n += 1
    print(n)
    
resolve()


Fixed submission:
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    x = 10 ** 20
    for i in range(N):
        if x >= P[i]:
            x = P[i]
            n += 1
    print(n)

resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    for i in range(N):
        for j in range(i):
            if P[i] > P[j]:
                break
        else:
            n += 1
    print(n)
    
resolve()

Fixed submission:
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    x = 10 ** 20
    for i in range(N):
        if x >= P[i]:
            x = P[i]
            n += 1
    print(n)

resolve()
Buggy python submission (verdict: Runtime Error):
N, K, S = map(int, input().split())
print(*([S]*K + [S+1]*(N-K)))


Fixed submission:
def resolve():
    H = int(input())
    W = int(input())
    N = int(input())
    m = max(H, W)
    print(N // m if N / m == N//m else N // m + 1)
resolve()

Buggy python submission (verdict: Runtime Error):
import sys
import math
read = sys.stdin.buffer.read
H, W, N = map(int, read().split('\n'))
m = max(H, W)
print(math.ceil(N / m))


Fixed submission:
def resolve():
    H = int(input())
    W = int(input())
    N = int(input())
    m = max(H, W)
    print(N // m if N / m == N//m else N // m + 1)
resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    import sys
    import math
    H, W, N = map(int, sys.stdin.read().split('\n'))
    m = max(H, W)
    print(math.ceil(N / m))

resolve()


Fixed submission:
def resolve():
    H = int(input())
    W = int(input())
    N = int(input())
    m = max(H, W)
    print(N // m if N / m == N//m else N // m + 1)
resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    import sys
    import math
    H, W, N = map(int, sys.stdin.read().split('\n'))
    m = max(H, W)
    print(math.ceil(N / m))
resolve()

Fixed submission:
def resolve():
    H = int(input())
    W = int(input())
    N = int(input())
    m = max(H, W)
    print(N // m if N / m == N//m else N // m + 1)
resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    import sys
    import math
    H, W, N = map(int, sys.stdin.read().split('\n'))
    m = max(H, W)
    print(math.ceil(N / m))
resolve()

Fixed submission:
def resolve():
    H = int(input())
    W = int(input())
    N = int(input())
    m = max(H, W)
    print(N // m if N / m == N//m else N // m + 1)
resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    import sys
    import math
    H, W, N = map(int, sys.stdin.read().split('\n'))
    m = max(H, W)
    print(math.ceil(N / m))

resolve()

Fixed submission:
def resolve():
    H = int(input())
    W = int(input())
    N = int(input())
    m = max(H, W)
    print(N // m if N / m == N//m else N // m + 1)
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    import sys
    readline = sys.stdin.readline
    N = int(readline())
    info = [None] * N
    for i in range(N):
        p, l = map(int, input().split())
        info[i] = [p-l, p+l]
    info.sort(key=lambda x: x[0])

    def is_obstacle(i):
        count = 0
        for j in info[i+1:]:
            if info[i][1] > j[0]:
                count += 1
        for j in info[:i]:
            if info[i][0] < j[1]:
                count += 1
        return count

    obs_list = [1] * N
    while sum(obs_list) > 0:
        obs_list = [0] * N
        m = 0
        idx = 0
        for i in range(N):
            obs_list[i] = is_obstacle(i)
            if m < obs_list[i]:
                m = obs_list[i]
                idx = i
        if sum(obs_list) == 0:
            break
        info = info[:idx] + info[idx+1:]
        N -= 1

    print(N)

resolve()


Fixed submission:
def resolve():
    import sys
    from operator import itemgetter
    readline = sys.stdin.readline
    N = int(readline())
    LR = [None] * N
    for i in range(N):
        p, l = map(int, input().split())
        LR[i] = [p-l, p+l]
    LR.sort(key=itemgetter(1))

    pre_r = -(10**18)
    count = 0
    for l, r in LR:
        if pre_r <= l:
            count += 1
            pre_r = r
    print(count)

resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    import sys
    readline = sys.stdin.readline
    N = int(readline())
    info = [None] * N
    for i in range(N):
        p, l = map(int, input().split())
        info[i] = [p-l, p+l]
    info.sort(key=lambda x: x[0])

    def is_obstacle(i):
        count = 0
        for j in info[i+1:]:
            if info[i][1] > j[0]:
                count += 1
        for j in info[:i]:
            if info[i][0] < j[1]:
                count += 1
        return count

    obs_list = [1] * N
    while sum(obs_list) > 0:
        obs_list = [0] * N
        m = 0
        idx = 0
        for i in range(N):
            obs_list[i] = is_obstacle(i)
            if m < obs_list[i]:
                m = obs_list[i]
                idx = i
        if sum(obs_list) == 0:
            break
        info = info[:idx] + info[idx+1:]
        N -= 1

    print(N)

resolve()

Fixed submission:
def resolve():
    import sys
    from operator import itemgetter
    readline = sys.stdin.readline
    N = int(readline())
    LR = [None] * N
    for i in range(N):
        p, l = map(int, input().split())
        LR[i] = [p-l, p+l]
    LR.sort(key=itemgetter(1))

    pre_r = -(10**18)
    count = 0
    for l, r in LR:
        if pre_r <= l:
            count += 1
            pre_r = r
    print(count)

resolve()
Buggy python submission (verdict: Runtime Error):
N, K, S = map(int, input())
print(*([S]*K + [S+1]*(N-K)))

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

ans = [S] * K + [10 ** 9 if S != 10 ** 9 else 1] * (N - K)
print(*ans)
Buggy python submission (verdict: Runtime Error):
import fractions
def resolve():

    N = int(input())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))

    print(abs(dict_num(P) - dict_num(Q)))


def dict_num(a):
    rank = 0
    for i in range(len(a)-1, 0, -1):
        rank += a[i] - 1 * fractions.factorial(i) 
resolve()

Fixed submission:
from itertools import permutations

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

dict_order = permutations(range(1, N + 1))

for n, i in enumerate(dict_order):
    if P == i:
        a = n
    if Q == i:
        b = n

print(abs(a - b))
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
for i in range(k):
    if a > 0:
        a -= 1
    elif b > 0:
        b -= 1
print(a, b, sep=' ')

Fixed submission:
a, b, k = map(int, input().split())
b = b if a - k > 0 else b - (k - a) if b - (k - a) > 0 else 0
a = a - k if a - k > 0 else 0
print(a, b, sep=' ')
Buggy python submission (verdict: Runtime Error):
x = int(input())
n = 10 ** 5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes = list(primes)
import bisect
b = bisect.bisect_right(primes, x)
if x == primes[b - 1]:
    print(x)
else:
    print(primes[b])

Fixed submission:
x = int(input())
n = 2 *(10 ** 5)
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes = list(primes)
import bisect
b = bisect.bisect_right(primes, x)
if x == primes[b - 1]:
    print(x)
else:
    print(primes[b])

Buggy python submission (verdict: Runtime Error):
x = int(input())
n = 10 ** 5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes = list(primes)
import bisect
b = bisect.bisect_right(primes, x)
print(primes[b])

Fixed submission:
x = int(input())
n = 2 *(10 ** 5)
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes = list(primes)
import bisect
b = bisect.bisect_right(primes, x)
if x == primes[b - 1]:
    print(x)
else:
    print(primes[b])
Buggy python submission (verdict: Runtime Error):
import fractions
a, b = map(int, input().split(' '))

print(int(a * b / fractions.gcd(a, b)))


Fixed submission:
a = int(input())
b = int(input())
for i in range(3):
    if a != i+1 and b != i+1:
        print(i+1)
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: Runtime Error):
import numpy as np
num = int(input())
n = int(np.log10(num))
a =  n * (num // 10 ** n)
print(a)
for i in range(int(n - 2), 1, -1):
    a += i * 9
print(a)


Fixed submission:
N = int(input())

if N % 2 != 0:
    print(0)
    exit()
ans = 0
d = 10
while d <= N:
    ans += N // d
    d *= 5
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def f(n):
    fn =1
    if n < 2:
        return 1
    else:
        while n >= 2:
            fn *= n
            n -= 2
        return fn
        


n = int(input())
fn = str(f(n))
if int(fn) % 2 == 1:
    print(0)
    exit()
n = 0
for i in range(len(fn)):
    if fn[-i-1] == '0':
        n += 1
    else:
        break
print(n)


Fixed submission:
N = int(input())

if N % 2 != 0:
    print(0)
    exit()
ans = 0
d = 10
while d <= N:
    ans += N // d
    d *= 5
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque

n, s, t = map(int, input().split(' '))
s -= 1
t -= 1

v = [[] for i in range(n)]
f = [0]*n

for i in range(n-1):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
    f[a] += 1
    f[b] += 1
for i in range(n):
    if f[i] == 0:
        l.append(i)
depth = [-1]*n
depth[t] = 0
q = deque([t])
while q:
    x = q.popleft()
    for y in v[x]:
        if depth[y] < 0:
            depth[y] = depth[x]+1
            q.append(y)
l = depth[:]
d = [-1]*n
d[s] = 0
q = deque([s])
while q:
    x = popleft()
    for y in v[x]:
        if d[y] < 0:
            d[y] = d[x]+1
            q.append(y)
l = sorted(range(n), key=lambda x:-depth[x])
for i in l:
    if d[i] < depth[i]:
        break
print(depth[i] - 1)



Fixed submission:
from collections import deque

n, s, t = map(int, input().split(' '))
s -= 1
t -= 1

v = [[] for i in range(n)]
f = [0]*n

for i in range(n-1):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
    f[a] += 1
    f[b] += 1
for i in range(n):
    if f[i] == 0:
        l.append(i)
depth = [-1]*n
depth[t] = 0
q = deque([t])
while q:
    x = q.popleft()
    for y in v[x]:
        if depth[y] < 0:
            depth[y] = depth[x]+1
            q.append(y)
l = depth[:]
d = [-1]*n
d[s] = 0
q = deque([s])
while q:
    x = q.popleft()
    for y in v[x]:
        if d[y] < 0:
            d[y] = d[x]+1
            q.append(y)
l = sorted(range(n), key=lambda x:-depth[x])
for i in l:
    if d[i] < depth[i]:
        break
print(depth[i] - 1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(sys.stdin.readline())
A = map(int, sys.stdin.readline().split())

mod = 10**9 + 7

cnt = [0] * 61
for a in A:
    for i in range(61):
        if a >> i & 1:
            cnt[i] += 1

ans = 0
p = 1
for i in cnt:
    ans = (ans + (p * i * (N - i)) % mod) % mod
    # ans %= mod
    p = p * 2 % mod
    # p %= mod

print(ans % mod)


Fixed submission:
import sys

N = int(sys.stdin.readline())
A = map(int, sys.stdin.readline().split())

mod = 10**9 + 7

cnt = [0] * 61
for a in A:
    for i in range(61):
        if a >> i & 1:
            cnt[i] += 1

ans = 0
p = 1
for i in cnt:
    ans = (ans + (p * i * (N - i)) % mod) % mod
    # ans %= mod
    p = p * 2 % mod
    # p %= mod

print(ans % mod)

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

N, *A = map(int, sys.stdin.read().split())

mod = 10**9 + 7
ans = 0
for n, i in enumerate(A[:-1]):
    for j in A[n + 1:]:
        ans += i ^ j
print(ans % mod)


Fixed submission:
import sys

N = int(sys.stdin.readline())
A = map(int, sys.stdin.readline().split())

mod = 10**9 + 7

cnt = [0] * 61
for a in A:
    for i in range(61):
        if a >> i & 1:
            cnt[i] += 1

ans = 0
p = 1
for i in cnt:
    ans = (ans + (p * i * (N - i)) % mod) % mod
    # ans %= mod
    p = p * 2 % mod
    # p %= mod

print(ans % mod)
Buggy python submission (verdict: Runtime Error):
import sys

readline = sys.stdin.buffer.readline
n = int(readline())
A = map(int, readline().split())
mod = 1000000007

caps = [0] * 3
ans = 1
for a in A:
    ans *= caps.count(a)
    caps[caps.index(a)] += 1
    ans %= mod
print(ans)


Fixed submission:
import sys

readline = sys.stdin.buffer.readline
n = int(readline())
A = map(int, readline().split())
mod = 1000000007

caps = [0] * 3
ans = 1
for a in A:
    ans *= caps.count(a)
    # caps[caps.index(a)] += 1
    for i in range(3):
        if caps[i] == a:
            caps[i] += 1
            break
    ans %= mod
print(ans)