qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
max_digit = 60


result = 0
base = 1
for _ in range(max_digit + 1):
  c0 = 0
  for i in range(N):
    a = A[i]
    A[i] >>= 1
    c0 += (a==0)
  
  result = (result + (base*(N - c0)*c0) % MOD) % MOD
  base = base*2 % MOD

print(result)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
max_digit = 60


result = 0
base = 1
for _ in range(max_digit + 1):
  c0 = 0
  for i in range(N):
    a = A[i] % 2
    A[i] >>= 1
    c0 += (a==0)
  
  result = (result + (base*(N - c0)*c0) % MOD) % MOD
  base = base*2 % MOD

print(result)
Buggy code:
a=int(input())
n=list(map(int,input().split()))
mod=10**9+7
import numpy as np
a=np.array(a)
md = len(bin(max(a)))
ans = 0
for d in range(md):
    cnt1 = np.count_nonzero((a>>d)&1)
    ans += cnt1 * (n-cnt1) * (1<<d)
    ans %= mod

print(ans%mod)


Fixed code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
import numpy as np
a=np.array(a)
md = len(bin(max(a)))
ans = 0
for d in range(md):
    cnt1 = np.count_nonzero((a>>d)&1)
    ans += cnt1 * (n-cnt1) * (1<<d)
    ans %= mod

print(ans%mod)
Buggy code:
import numpy as np
import copy
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
A = np.array(A, dtype = np.int64)
tmp = 0
for i in range(61):
    tmp_1 = sum(A & 1)
    tmp += ((tmp_1)*(N - tmp_1)*(2**i)) % mod
    A >> 1
print(tmp % mod)

Fixed code:
import numpy as np
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
A = np.array(A, dtype = np.int64)
tmp = 0
for i in range(61):
    tmp_1 = np.count_nonzero(A & 1)
    tmp += ((tmp_1)*(N - tmp_1)*(2**i)) % mod
    A = A >> 1
print(tmp % mod)
Buggy code:
n = int(input())
A = list(map(int, input().split()))

mod = 10**9+7

array = [0] * 60

for a in A:
    for j in range(len(bin(a))-2):
        print(a, j, a >> j, (a >> j) & 1)
        array[j] += (a >> j) & 1
ans = 0
for i in range(60):
    ans += array[i] * (n-array[i]) * 2**i
print(ans % mod)


Fixed code:
n = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
array = [0] * 60
for a in A:
    for j in range(len(bin(a))-2):
        array[j] += (a >> j) & 1
ans = 0
for i in range(60):
    ans += array[i] * (n-array[i]) * 2**i
print(ans % mod)
Buggy code:
MOD = (10**9) + 7
n = int(input())
a = list(map(int,intput().split()))

cnt = [0] * 60

for num in a:
  for j in range(60):
    cnt[j] += num >> j
ans = 0
for b in range(60):
  ans += cnt[b] * (n-cnt[b]) << b
  
ans %= MOD
print(ans)

Fixed code:
MOD = (10**9) + 7
n = int(input())
a = list(map(int,input().split()))

cnt = [0] * 60

for num in a:
  for j in range(60):
    cnt[j] += (num >> j) % 2
ans = 0
for b in range(60):
  ans += cnt[b] * (n-cnt[b]) << b
  
ans %= MOD
print(ans)
Buggy code:
N = int(input())

lis = [0]*60

for a in input().split():
    a = int(a)
    for i,j in range(60):
        lis[i] += a % 2
        a = a//2
ans = 0
for i, j in enumerate(lis):
    ans += j * (N-j) *(2**i)
    ans = ans % (10**9 + 7)

print(ans)


Fixed code:
N = int(input())
 
lis = [0]*60
 
for a in input().split():
    a = int(a)
    for i in range(60):
        lis[i] += a % 2
        a = a//2
ans = 0
for i, j in enumerate(lis):
    ans += j * (N-j) *(2**i)
    ans = ans % (10**9 + 7)
 
print(ans)
Buggy code:

MOD = 10 ** 9 + 7
n = int(input())
a = list(map(lambda x: format(int(x), '060b')[::-1], input().split()))

ans = 0
onecount = [0 for i in range(60)]
zerocount = [0 for i in range(60)]
for i in range(n):
    for j in range(60):
        if a[i][j] == '1':
            onecount[j] += 1
        else:
            zerocount[j] += 1

for i in range(60):
    ans += (2 ** i) * onecount[i] * zerocount[i]
print(ans)


Fixed code:

MOD = 10 ** 9 + 7
n = int(input())
a = list(map(lambda x: format(int(x), '060b')[::-1], input().split()))

ans = 0
onecount = [0 for i in range(60)]
zerocount = [0 for i in range(60)]
for i in range(n):
    for j in range(60):
        if a[i][j] == '1':
            onecount[j] += 1
        else:
            zerocount[j] += 1

for i in range(60):
    ans += ((2 ** i) * onecount[i] * zerocount[i] % MOD)
    ans %= MOD
print(ans)
Buggy code:
# -*- coding: utf-8 -*-
import numpy as np
def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    A = np.array(A, np.int64)
    ans = 0
    for i in range(60):
        bit = np.count_nonzero(A | 0)
        ans += bit * (N - bit) * (2 ** i)
        ans %= mod
        A >>= 1
        print(ans)

if __name__ == '__main__':
    main()

Fixed code:
# -*- coding: utf-8 -*-
import numpy as np
def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    A = np.array(A, np.int64)
    ans = 0
    for i in range(60):
        bit = np.count_nonzero(A & 1)
        ans += bit * (N - bit) * (2 ** i)
        ans %= mod
        A >>= 1
    print(ans)

if __name__ == '__main__':
    main()
Buggy code:
import bisect
N = int(input())
An = list(map(int,input().split(' '))) 

bit_list = [1]
for i in range(100000):
    bit_list.append(bit_list[i]*2)
    if bit_list[i+1] > 10**12:
        break
start_point = bisect.bisect_right(bit_list,An[-1])
keta_list = [0] * start_point

for A in An:
    abin = format(A, 'b')
    for i in range(len(abin)):
        if abin[i] == '1':
            keta_list[len(abin)-1-i] += 1
count = 0
for idx,keta_count in enumerate(keta_list):
    count += (start_point-keta_count) * bit_list[idx] % (1000000000+7)
print(count)

Fixed code:
import bisect
N = int(input())
An = list(map(int,input().split(' '))) 

bit_list = [1]
for i in range(100000):
    bit_list.append(bit_list[i]*2)
    if bit_list[i+1] > 2**60:
        break
start_point = bisect.bisect_right(bit_list,max(An))
keta_list = [0] *  start_point

for A in An:
    abin = format(A, 'b')
    for i in range(len(abin)):
        if abin[i] == '1':
            keta_list[len(abin)-1-i] += 1
count = 0
for idx,keta_count in enumerate(keta_list):
    count += (N-keta_count) * bit_list[idx] * keta_count
    count = count % (1000000000+7)
print(count)
Buggy code:
MOD = 10 ** 9 + 7
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [0] * 60
    for i in A:
        for j in range(60):
            if i & (1 << j):
                B[j] += 1
    print(B[:5])
    r = 0
    for ii, i in enumerate(A[:-1]):
        for j in range(60):
            if i & (1 << j):
                B[j] -= 1
            if i & (1 << j):
                r += (1 << j) * (N - ii - 1 - B[j])
            else:
                r += (1 << j) * B[j]
            r = r % MOD
    print(r)

main()


Fixed code:
MOD = 10 ** 9 + 7
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [0] * 60
    for i in A:
        for j in range(60):
            if i & (1 << j):
                B[j] += 1
    r = 0
    for ii, i in enumerate(A[:-1]):
        for j in range(60):
            if i & (1 << j):
                B[j] -= 1
                r = (r + (1 << j) * (N - ii - 1 - B[j])) % MOD
            else:
                r = (r + (1 << j) * B[j]) % MOD
    print(r)

main()
Buggy code:
import numpy as np

N=int(input())
A=np.array([int(x) for x in input().split()])

ans=0
M=pow(10,9)+7
for i in range(100):
  one=np.sum((A>>i)&1)
  zero=N-one
  ans+=(one*zero)*pow(2,i)
  ans%=M
  #print(one,zero)
print(ans)

Fixed code:
import numpy as np

N=int(input())
A=np.array([int(x) for x in input().split()])

ans=0
M=pow(10,9)+7
for i in range(100):
  one=np.sum((A>>i)&1)
  zero=N-one
  ans+=(one*zero)%M*pow(2,i,M)%M
  ans%=M
  #print(one,zero)
print(ans)
Buggy code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()])

k = [0] * 60

for j in range(60):
    l = a & 1
    k[j] = np.count_nonzero(l)
    a >>= 1

ans = 0
c = 0
for d in k:
    ans += (d * (n - d) * 2**c)  % (10**9 + 7)
    c += 1
    

Fixed code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()])

k = [0] * 60

for j in range(60):
    l = a & 1
    k[j] = np.count_nonzero(l)
    a >>= 1

ans = 0
c = 0
for d in k:
    ans += (d * (n - d) * 2**c)  % (10**9 + 7)
    c += 1
    
print(ans % (10**9 + 7))
Buggy code:
N = int(input())
A = list(map(int, input().split()))

ans = 0
M = 10**9+7
for i in range(60):
    for j in range(N):
        x = 0
        if A[j]>>i & 1:
            x += 1
    now = x * (N - x) % M
    for j in range(i):
        now = now * 2 % M
    ans += now
    ans %= M
print(ans)


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

ans = 0
M = 10**9+7
for i in range(60):
    x = 0
    for j in range(N):     
        if A[j]>>i & 1:
            x += 1
    now = x * (N - x) % M
    for j in range(i):
        now = now * 2 % M
    ans += now
    ans %= M
print(ans)
Buggy code:
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
mx = max(A)
d = {i:0 for i in range(len(str(bin(mx))))}
for a in A:
  for i in range(len(str(bin(a)))-2):
    if (a>>i)&1:
      d[i] += 1

ans = 0
for k, v in d.items():
  ans += v*(10-v) * (2**k)
  ans %= mod
print(ans)

Fixed code:
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
mx = max(A)
d = {i:0 for i in range(len(str(bin(mx)))-2)}
for a in A:
  for i in range(len(str(bin(a)))-2):
    if (a>>i)&1:
      d[i] += 1

ans = 0
for k, v in d.items():
  ans += v*(N-v) * (2**k)
  ans %= mod
print(ans)
Buggy code:
n = int(input())
*A, = map(int, input().split())
p = 10**9+7
A = [list(format(a, '060b')) for a in A]
s = 0
for i in range(60):
    Ai = [int(a[i]) for a in A]
    print(Ai)
    c0 = Ai.count(0)
    c1 = Ai.count(1)
    c = c0*c1
    s = (s+c*(2**(59-i))) % p
print(s)


Fixed code:
n = int(input())
*A, = map(int, input().split())
p = 10**9+7
A = [format(a, '060b') for a in A]
s = 0
for i in range(60):
    Ai = [a[i] for a in A]
    c0 = Ai.count('0')
    c1 = n-c0
    c = c0*c1
    s = (s+c*(2**(59-i))) % p
print(s)
Buggy code:
import numpy as np
mod=10**9+7
N=int(input())
A=np.array(list(map(int, input().split())))
ans=0
for　i in range(60):
  b=np.count_nonzero(A>>i&1)
  ans+=(2**i)*b*(N-b)
  ans%=mod
  
print(ans)



Fixed code:
import numpy as np
mod=10**9+7
N=int(input())
A=np.array(list(map(int, input().split())))
ans=0
for i in range(60):
  b=np.count_nonzero(A>>i&1)
  ans+=(2**i)*b*(N-b)
  ans%=mod
  
print(ans)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0

for i in range(60):
    zeroCnt = 0
    oneCnt = 1
    
    for j in range(n):
        if (a[j] >> i) & 1 == 1:
            oneCnt += 1
        else:
            zeroCnt += 0
    ans += zeroCnt * oneCnt * pow(2, i, mod)
    ans %= mod

pirnt(ans)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0

for i in range(60):
    zeroCnt = 0
    oneCnt = 0

    for j in range(n):
        if (a[j] >> i) & 1 == 1:
            oneCnt += 1
        else:
            zeroCnt += 1
    ans += zeroCnt * oneCnt * pow(2, i, mod)
    ans %= mod

print(ans)
Buggy code:
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    *s, = map(lambda x: x.count("1"), zip(*a))
    return str(sum(s * (n - _s) * pow(2, 59 - i, m) for i, _s in enumerate(s)) % m)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Fixed code:
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    *s, = map(lambda x: x.count("1"), zip(*a))
    for i, _s in enumerate(s):
        ans += _s * (n - _s) * pow(2, 59 - i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
Buggy code:
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m = 10**9 + 7
    ans = 0
    for s in map(str.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Fixed code:
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for d in zip(*a):
        ans <<= 1
        s = "".join(d).count("1")
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
Buggy code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(61):
    count0=0
    count1=0
    for j in a:
        if not (j>>i & 1):
            count0+=1
        if j>>i & 1:
            count1+=1
    ans+=((count0*count1)*(2**i))%mod
    print(count0,count1)
print(ans%mod)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
k=1
for i in range(61):
    count0=0
    count1=0
    for j in a:
        if not (j>>i & 1):
            count0+=1
        if j>>i & 1:
            count1+=1
    ans+=((count0*count1)*(k))%mod
    k=(2*k)%mod
    
    
print(ans%mod)
Buggy code:
import numpy as np
 
mod = 10**9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   
    n_1 = np.count_nonzero((A >> n)&1)   
    n_0 = N - num_1                       
    ans += ((2 ** n)*n_1*n_0) % mod

print(ans%mod)

Fixed code:
import numpy as np
 
mod = 10**9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   
    n_1 = np.count_nonzero((A >> n)&1)   
    n_0 = N - n_1                       
    ans += ((2 ** n)*n_1*n_0) % mod

print(ans%mod)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
s=0
for j in range(len(bin(max(a)))-2):
    cnt1=0
    cnt0=0
    for i in range(n):
      if (a[i]>>j)&1:
        cnt1+=1
      else:
        cnt0+=1
    s+=(cnt1*cnt0*2**j)%(10**9+7)
print(s)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
s=0
for j in range(len(bin(max(a)))-2):
    cnt1=0
    cnt0=0
    for i in range(n):
      if (a[i]>>j)&1:
        cnt1+=1
      else:
        cnt0+=1
    s+=(cnt1*cnt0*2**j)%(10**9+7)
print(s%(10**9+7))
Buggy code:
n=int(input())
a=list(map(int,input().split()))
ans=0
mod=10**9+7
for j in range(60):
    cnt1=sum([1 for i in a if i>>j&1])
    cnt0=len(bin(j))-2-cnt1
    ans+=(cnt1*cnt0*2**j)
print(ans%(10**9+7))


Fixed code:
n=int(input())
a=list(map(int,input().split()))
ans=0
mod=10**9+7
for j in range(60):
    cnt1=sum([1 for i in a if i>>j&1])
    cnt0=n-cnt1
    ans+=(cnt1*cnt0*2**j)
print(ans%(10**9+7))
Buggy code:
MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))

ans = 0
m = 1
for _ in range(60):
    bits = sum((a & m for a in A))
    print(bits)
    bits //= m
    ans += (bits * (N - bits) * m)
    ans %= MOD
    m <<= 1
print(ans % MOD)


Fixed code:
MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))

ans = 0
m = 1
for i in range(60):
    bits = sum((a & m for a in A))
    bits //= m
    ans += (bits * (N - bits) * m)
    ans %= MOD
    m <<= 1
print(ans % MOD)
Buggy code:
import queue
import numpy as np
import math

n = int(input())
A = list(map(int, input().split()))
A = np.array(A,np.int64)
ans = 0

for i in range(60 + 1):
    count1 = (A >> i) & 1

    count0 = len(A) - count1
    ans += count1*count0 * pow(2, i)
    ans%=1000000007

print(ans)

Fixed code:
import queue
import numpy as np
import math

n = int(input())
A = list(map(int, input().split()))
A = np.array(A,np.int64)
ans = 0

for i in range(60 + 1):
    a = (A >> i) & 1
    count1 = np.count_nonzero(a)
    count0 = len(A) - count1
    ans += count1*count0 * pow(2, i)
    ans%=1000000007

print(ans)
Buggy code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

max_digist = 60
MOD = 10**9 + 7

ans = 0
for i in range(max_digits):
    one_num = np.count_nonzero((a >> i) & 1)
    radix_mod = 2**i % MOD
    ans += (radix_mod * one_num * (n - one_num)) % MOD
print(ans%MOD)

Fixed code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

max_digits = 60
MOD = 10**9 + 7

ans = 0
for i in range(max_digits):
    one_num = np.count_nonzero((a >> i) & 1)
    radix_mod = 2**i % MOD
    ans += (radix_mod * one_num * (n - one_num)) % MOD
print(ans%MOD)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
digit = 60
o=[0]*digit
z=[0]*digit

for i in a:
  for j in range(digit):
    if (i >> j) & 1:
      o[j] += 1
    else:
      z[j] += 1
ans = 0
for j in range(digit):
  ans += (o[j]*z[j]*2**j
print(ans % MOD)

Fixed code:
n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
digit = 60
o=[0]*digit
z=[0]*digit

for i in a:
  for j in range(digit):
    if (i >> j) & 1:
      o[j] += 1
    else:
      z[j] += 1
ans = 0    
for j in range(digit):
  ans += (o[j]*z[j]*pow(2,j,MOD))
print(ans % MOD)
Buggy code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
a = np.array(a)
ans = 0
# for bin_a in map(bin, a):
d = 1
num_of_one_per_keta = []
while d < (1 << 61):
    cnt = np.count_nonzero(a & d)
    num_of_one_per_keta.append(cnt)
    # ans += (N - cnt) * cnt * d
    # ans %= MOD
    d <<= 1
print(num_of_one_per_keta)
ans = 0
for i, num_of_one in enumerate(num_of_one_per_keta):
    ans += (n-num_of_one)*num_of_one*pow(2, i, mod) % mod
print(ans % mod)


Fixed code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
a = np.array(a)
ans = 0
# for bin_a in map(bin, a):
d = 1
num_of_one_per_keta = []
while d < (1 << 61):
    cnt = np.count_nonzero(a & d)
    num_of_one_per_keta.append(cnt)
    d <<= 1
ans = 0
for i, num_of_one in enumerate(num_of_one_per_keta):
    ans += (n-num_of_one)*num_of_one*pow(2, i, mod) % mod
print(ans % mod)
Buggy code:
K = 1000000009
N = int(input())
A = [int(a) for a in input().split()]
li = [0] * 60
for n in range(N):
    for i in range(60):
        li[i] += A[n] >> i & 1
ans = 0
for i in range(60):
    ans += (1 << i) * li[i] * (N - li[i])
    ans %= K
print(ans)

Fixed code:
K = 1000000007
N = int(input())
A = [int(a) for a in input().split()]
li = [0] * 60
for n in range(N):
    li = [li[i] + (A[n] >> i & 1) for i in range(60)]
ans = 0
for i in range(60):
    ans += (1 << i) * li[i] * (N - li[i])
    ans %= K
print(ans)
Buggy code:
n = int(input())
aaa = list(map(int, input().split()))

MOD = 10 ** 9 + 7
ans = 0
m = 1
ans = 0
for _ in range(60):
    one_count = 0
    for a in aaa:
        one_count += (a & m) // m
    zero_count = n - one_count
    ans += (one_count * zero_count * m)
    m *= 2
        
print(ans)


Fixed code:
n = int(input())
aaa = list(map(int, input().split()))

MOD = 10 ** 9 + 7
ans = 0
m = 1
ans = 0
for _ in range(60):
    one_count = sum(a & m for a in aaa)
    one_count //= m
    zero_count = n - one_count
    ans = (ans + one_count * zero_count * m) % MOD
    m *= 2
        
print(ans)
Buggy code:
import numpy as np

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

ans=0

for i in range(60):
    cnt=np.count_nonzero(A&1)
    ans +=2**i*cnt*(n-cnt)
    A >>=1

print(ans%10**9+7)

Fixed code:
import numpy as np
mod=10**9+7
n=int(input())
A=np.array(list(map(int,input().split())))

ans=0

for i in range(60):
    cnt=np.count_nonzero(A&1)
    ans +=2**i*cnt*(n-cnt)
    A >>=1

print(ans%mod)
Buggy code:
import numpy as np

n=int(input())
a=np.array(list(map(int,input().split())))
mod=10**9+7

s=0
for i in range(60):
    bit = np.count_nonzero(a & 1)
    print(bit)
    s += bit*(n-bit)*(2**i)
    a >>= 1
print(s % mod)

Fixed code:
import numpy as np

n=int(input())
a=np.array(list(map(int,input().split())))
mod=10**9+7

s=0
for i in range(60):
    bit = np.count_nonzero(a & 1)
    s += bit*(n-bit)*(2**i)
    a >>= 1
print(s % mod)
Buggy code:
import sys
input = sys.stdin.readline()
N = int(input())
A = [int(i) for i in input().split()]
count0 = [0 for i in range(60)]
count1 = [0 for i in range(60)]
for a in A:
    a_tmp = bin(a).replace("0b","")
    a_tmp = a_tmp.zfill(60)
    for i,b in enumerate(a_tmp):
        if b == "1":
            count1[i] += 1
        else:
            count0[i] += 1
cnt = 0
ans = 0
for c0,c1 in zip(count0[::-1],count1[::-1]):
    ans += c0*c1*(2**cnt)
    cnt += 1
print(ans%(10**9+7))


Fixed code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(i) for i in input().split()]
count0 = [0 for i in range(60)]
count1 = [0 for i in range(60)]
for a in A:
    a_tmp = bin(a).replace("0b","")
    a_tmp = a_tmp.zfill(60)
    for i,b in enumerate(a_tmp):
        if b == "1":
            count1[i] += 1
        else:
            count0[i] += 1
cnt = 0
ans = 0
for c0,c1 in zip(count0[::-1],count1[::-1]):
    ans += c0*c1*(2**cnt)
    cnt += 1
print(ans%(10**9+7))
Buggy code:
n=int(input())
a=list(map(int,input().split()))

for b in a:
    for i in range(60):
        counts[i]+=b%2
        b//=2

ans=0
mod = 10**9+7
for i in range(60):
    c=counts[i]
    comb=c*(n-c)
    ans=(ans+(1<<i)*comb)%mod
print(ans)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
counts=[0]*60
for b in a:
    for i in range(60):
        counts[i]+=b%2
        b//=2
ans=0
mod = 10**9+7
for i in range(60):
    c=counts[i]
    comb=c*(n-c)
    ans=(ans+(1<<i)*comb)%mod
print(ans)
Buggy code:
n = int(input())
A = [int(i) for i in input().split()]

s = [0]*60
for a in A:
    cnt = 0
    while a != 0:
        # print(cnt,a)
        if(a&1)==1:
            s[cnt+1] += 1
        cnt+=1
        a = a >> 1
ans = 0
for i in range(60):
    # print("a",2**(i-1)*s.get(i,0)*(n-s.get(i,0)))
    # print("b",s.get(i,0))
    # print("c",(n-s.get(i,0)))
    ans += (2**(i-1)*s.get(i,0)*(n-s.get(i,0))) % (10**9+7)
ans = ans % (10**9+7)
print(int(ans))
# print(s)


Fixed code:
n = int(input())
A = [int(i) for i in input().split()]

s = [0]*61
for a in range(n):
    for i in range(61):
        if(A[a]>>i&1)==1:
            s[i+1] += 1
ans = 0
for i in range(60):
    # print("a",2**(i-1)*s.get(i,0)*(n-s.get(i,0)))
    # print("b",s.get(i,0))
    # print("c",(n-s.get(i,0)))
    ans += 2**(i)*s[i+1]*(n-s[i+1])
ans = ans % (10**9+7)
print(int(ans))
# print(s)
Buggy code:
MOD = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<=1
    print(ans)
    c = sum(a[i]>>b & 1 for i in range(n))
    ans = (ans + c*(n-c))%MOD
print(ans)

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

n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<=1
    c = sum(a[i]>>b & 1 for i in range(n))
    ans = (ans + c*(n-c))%MOD
print(ans)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
count = [0] * 60
m = 1000000007
def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = (K * x) % 1000000007
        x = (x * x) % 1000000007
        n //= 2
    return (K * x) % 1000000007
mul = [pow_k(2,59-i) for i in range(60)]
for a in A:
    b = bin(a)
    for i in range(1,len(b)-1):
        if b[-i] == '1':
            count[-i] += 1
print(sum([count[i]*(N-count[i])*mul[i]%m for i in range(60)]))

Fixed code:
N = int(input())
A = list(map(int, input().split()))
count = [0] * 60
m = 1000000007
def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = (K * x) % 1000000007
        x = (x * x) % 1000000007
        n //= 2
    return (K * x) % 1000000007
mul = [pow_k(2,59-i) for i in range(60)]
for a in A:
    b = bin(a)
    for i in range(1,len(b)-1):
        if b[-i] == '1':
            count[-i] += 1
print(sum([count[i]*(N-count[i])*mul[i]%m for i in range(60)])%m)