qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import collections
import itertools

n = int(input())

per_dict = collections.defaultdict(list)
for i in range(n):
  a = int(input())
  for j in range(a):
    x, y = map(int, input().split())
    per_dict[i].append([x,y]) 

for i in range(n, -1, -1):
  flag = True
  for honests in itertools.combinations(range(n), i):
    for h in honests:
      for x, y in per_dict[h]:
        if y == 1 and x not in honests:
          flag = False 
        if y == 0 and x in honests:
          flag = False
    if flag == True:
      break
  if flag == True:
    break
print(i)



Fixed code:
import collections
import itertools

n = int(input())

per_dict = collections.defaultdict(list)
for i in range(n):
  a = int(input())
  for j in range(a):
    x, y = map(int, input().split())
    per_dict[i + 1].append([x,y]) 

for i in range(n, -1, -1):
  flag = True
  for honests in itertools.combinations(range(1, n + 1), i):
    flag = True
    for h in honests:
      for x, y in per_dict[h]:
        if y == 1 and x not in honests:
          flag = False 
        if y == 0 and x in honests:
          flag = False
    if flag == True:
      break
  if flag == True:
    break
print(i)
Buggy code:
def get_switch(n):
    allswitch = []
    for i in range(0,2**n):
        bin_str = format(i,'0'+str(n)+'b')
        swt = list(map(int,list(bin_str)))
        allswitch.append(swt)
    return allswitch

def test(patarn,a,x,y,n):
    ans_sub=sum(patarn)
    for i in range(n):
        if patarn[i]==1:
            for j in range(a[i]):
                if y[i][j]==1:
                    if patarn[x[i][j]]==0:
                        return 0
                else:
                    if patarn[x[i][j]]==1:
                        return 0
        #else:
            #f.append(i)
            #if i in t:
                #return 0
    #print(patarn)
    return ans_sub
    
def main():
    n=int(input())
    a=[]
    x=[]
    y=[]
    for i in range(n):
        a_sub=int(input())
        a.append(a_sub)
        x_sub=[]
        y_sub=[]
        for j in range(a_sub):
            tmp=list(map(int,input().split()))
            x_sub.append(tmp[0]-1)
            y_sub.append(tmp[1])
        x.append(x_sub)
        y.append(y_sub)
    print(x)
    print(y)
    ans=0
    for patarn in get_switch(n):
        ans=max(ans,test(patarn,a,x,y,n))
    print(ans)

if __name__=='__main__':
    main()

Fixed code:
def get_switch(n):
    allswitch = []
    for i in range(0,2**n):
        bin_str = format(i,'0'+str(n)+'b')
        swt = list(map(int,list(bin_str)))
        allswitch.append(swt)
    return allswitch

def test(patarn,a,x,y,n):
    ans_sub=sum(patarn)
    for i in range(n):
        if patarn[i]==1:
            for j in range(a[i]):
                if y[i][j]==1:
                    if patarn[x[i][j]]==0:
                        return 0
                else:
                    if patarn[x[i][j]]==1:
                        return 0
        #else:
            #f.append(i)
            #if i in t:
                #return 0
    #print(patarn)
    return ans_sub
    
def main():
    n=int(input())
    a=[]
    x=[]
    y=[]
    for i in range(n):
        a_sub=int(input())
        a.append(a_sub)
        x_sub=[]
        y_sub=[]
        for j in range(a_sub):
            tmp=list(map(int,input().split()))
            x_sub.append(tmp[0]-1)
            y_sub.append(tmp[1])
        x.append(x_sub)
        y.append(y_sub)
    #print(x)
    #print(y)
    ans=0
    for patarn in get_switch(n):
        ans=max(ans,test(patarn,a,x,y,n))
    print(ans)

if __name__=='__main__':
    main()
Buggy code:
n = int(input())

a_list = []
for _ in range(n):
  mini_list = []
  a = int(input())
  for _ in range(a):
    mini_list.append(list(map(int, input().split())))
  a_list.append(mini_list)

ans = 0
for i in range(n**2):
  ans_list = [0]*n
  while i!=0:
    ans_list[i%2] = 1
    i//=2
  flg = True
  for j, syogens in enumerate(a_list):
    if ans_list[j]!=0:
      pass
    else:
      for syogen in syogens:
        person = syogen[0]-1
        status = syogen[1]
        if ans_list[person] != status:
          flg=False
  if flg:
    ans = max(ans,sum(ans_list))
print(ans)


Fixed code:
n = int(input())

a_list = []
for _ in range(n):
  mini_list = []
  a = int(input())
  for _ in range(a):
    mini_list.append(list(map(int, input().split())))
  a_list.append(mini_list)

ans = 0
for i in range(2**n):
  ans_list = [0]*n
  cnt=0
  while i!=0:
    ans_list[cnt] = i%2
    cnt+=1
    i//=2
  
  flg = True
  for j, syogens in enumerate(a_list):
    if ans_list[j]==0:
      pass
    else:
      for syogen in syogens:
        person = syogen[0]-1
        status = syogen[1]
        if ans_list[person] != status:
          flg=False
  if flg:
    ans = max(ans,sum(ans_list))
print(ans)
Buggy code:
def inputlist():
	n=int(input())
	A=list()
	for i in range(n):
		Ai = int(input())
		s=list()
		for i in range(Ai):
			s += input().split()
		s = [int(i) for i in s]
		A.append(s)
	return A

A=inputlist()
n=len(A)
ans=0
for i in range(2**n):
	bit_str = str(format(i,'015b'))
	count=0
	for j in range(n):
		if ((i >> j) & 1):
			for k in range(0,len(A[j]),2):
				if (int(bit_str[(-1*A[j][k])-1]) == A[j][k+1]):
					count+=1
	ans = max(ans,count)
print(ans)

Fixed code:
def inputlist():
	n=int(input())
	A=list()
	for i in range(n):
		Ai = int(input())
		s=list()
		for i in range(Ai):
			s += input().split()
		s = [int(i) for i in s]
		A.append(s)
	return A
A=inputlist()
n=len(A)
ans=0
for i in range(2**n):
	p = 1
	bit_str = str(format(i,'015b'))
	for j in range(n):
		if ((i >> j) & 1):
			for k in range(0,len(A[j]),2):
				if not(A[j][k+1] == int(bit_str[-1*A[j][k]])):
					p = 0
	if (p):
		ans = max(ans,bit_str.count('1'))
print(ans)
Buggy code:
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  8 21:12:35 2019

@author: over-
"""

N=int(input())
A=dict()
x=dict()
y=dict()
for i in range(1,N+1):
    A[i]=int(input())
    x[i]=dict()
    y[i]=dict()
    for j in range(A[i]):
        a1,a2=map(int,input().split())
        x[i][j+1]=a1
        y[i][j+1]=a2

C=2**N
ans=0
for c in range(C):
    honest=[]
    unkind=[]
    B='{:0b}'.format(c)
    B='0'*(N-len(B))+B
    bool=True
    for i in range(N):
        if B[i]==0:
            honest.append(i+1)
        else:   
            unkind.append(i+1)
        
    for k in range(1,N+1):
        if k in honest:
            for j in range(A[k]):
                if y[k][j+1]==1:
                    if x[k][j+1] in unkind:
                        bool=False
                else:
                    if x[k][j+1] in honest:
                        bool=False
    if bool: 
        count=0
        for i in range(N):
            count+=int(B[i])
        if count > ans:
            ans= count
                        
print(count)        
                        


Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  8 21:12:35 2019

@author: over-
"""

N=int(input())
A=dict()
x=dict()
y=dict()
for i in range(1,N+1):
    A[i]=int(input())
    x[i]=dict()
    y[i]=dict()
    for j in range(A[i]):
        a1,a2=map(int,input().split())
        x[i][j+1]=a1
        y[i][j+1]=a2

C=2**N
ans=0
for c in range(C):
    honest=[]
    unkind=[]
    B='{:0b}'.format(c)
    B='0'*(N-len(B))+B
    bool=True
    for i in range(N):
        if int(B[i])==0:
            honest.append(i+1)
        else:   
            unkind.append(i+1)
        
    for k in range(1,N+1):
        if k in honest:
            for j in range(A[k]):
                if y[k][j+1]==1:
                    if x[k][j+1] in unkind:
                        bool=False
                else:
                    if x[k][j+1] in honest:
                        bool=False
    if bool: 
        if len(honest) > ans:
            ans= len(honest)
                        
print(ans)
Buggy code:
N = int(input())
A = list(map(int,input().split()))

n = len(bin(N))-2
D = [0]*n

for i in range(N):
    s = list(bin(A[i])[2:])[::-1]
    for j in range(len(s)):
        D[j] += int(s[j])
ans = 0
for i in range(n):
    ans += D[i]*(N-D[i])*2**i
    ans %= 10**9+7
print(ans)


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

n = 62
D = [0]*n

for i in range(N):
    s = list(bin(A[i])[2:])[::-1]
    s = [i for i in range(len(s)) if s[i]=='1']
    for j in s:
        D[j] += 1
ans = 0
for i in range(n):
    ans += D[i]*(N-D[i])*2**i
    ans %= 10**9+7
print(ans)
Buggy code:
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    b = sum(map(lambda x: (x >> i)&1, a))
    c = n - b
    ans += b * c * i % mod
print(ans%mod)


Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    b = sum(map(lambda x: (x >> i)&1, a))
    c = n - b
    ans += b * c * (1<<i) % mod
print(ans%mod)
Buggy code:
import numpy as np

mod = 10 ** 9 + 7
ans = 0
if __name__ == '__main__':
    n = int(input())
    A = np.array(list(map(int, input().split())))

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

    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 i in range(60):
    cnt=np.count_nonzero(A&1)
    ans +=2**i*cnt*(n-cnt)
    A >>=1
 
print(ans%mod)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
ans=0
p=10**9 + 7 
l=[0]*60
ans=0
for i in range(60):
    for j in a:
        l[i]+=(j>>i)&1
    ans+=(2**i*l[i]*(n-l[i]))%p
print(ans)  

Fixed code:
n=int(input())
a=list(map(int,input().split()))
ans=0
p=10**9 + 7 
l=[0]*60
for i in range(60):
    for j in a:
        l[i]+=(j>>i)&1
    ans=(ans + (2**i) * l[i] * (n-l[i]))%p
print(ans)
Buggy code:
n = int(input())
a = [int(_) for _ in input().split()]
M = max(a)
p = len(format(M, 'b'))
l = [[0 for _ in range(n)] for _ in range(p)]
ans = 0
for i in range(n):
    a_s = format(a[i], '0' + str(p) + 'b')
    for c in range(p):
        l[c][i] = int(a_s[c])
for i in range(p):
    c1 = sum(l)
    ans += (2**(p - i - 1)) * c1 * (n - c1)
    ans %= (10**9 + 7)
print(ans)


Fixed code:
n = int(input())
a = [int(_) for _ in input().split()]
M = max(a)
p = len(format(M, 'b'))
l = [0 for _ in range(p)]
ans = 0
for i in range(n):
    a_s = format(a[i], '0' + str(p) + 'b')
    for c in range(p):
        if a_s[c] == '1':
            l[c] += 1
for i in range(p):
    c1 = l[i]
    ans += (2**(p - i - 1)) * c1 * (n - c1)
    ans %= (10**9 + 7)
print(ans)
Buggy code:
def readinput():
    n=int(input())
    l=list(map(int,input().split()))
    return n,l

def main(n,a):
    MOD=10**9+7
    hist=[0]*61
    bs=[]
    for i in range(n):
        # s=list(reversed(bin(a[i])[2:]))
        # for j in range(len(s)):
        #     if s[j]=='1':
        #         hist[j]+=1
        # bs.append(s)

        s=bin(a[i])[2:]
        for j in range(len(s)):
            if s[j]=='1':
                hist[len(s)-j-1]+=1
        # j=0
        # ai=a[i]
        # while ai>0:
        #     if ai&1==1:
        #         hist[j]+=1
        #     ai = ai >> 1
        #     j+=1


    #print(bs)
    #print(hist)
    sum=0
    for i in range(n-1):
        s=bs[i]
        b=1
        for j in range(len(s)):
            if s[j]=='0':
                sum=(sum+hist[j]*b)%MOD
            else:
                sum=(sum+( n-i-hist[j] )*b)%MOD
                hist[j]-=1
            b*=2
        for j in range(len(s),61):
            sum=(sum+hist[j]*b)%MOD
            b*=2
    # b=1
    # for j in range(61):
    #     sum=(sum+( hist[j]*(n-hist[j])*b )%MOD )%MOD
    #     b*=2

    return sum

if __name__=='__main__':
    n,l=readinput()
    ans=main(n,l)
    print(ans)


Fixed code:
def readinput():
    n=int(input())
    l=list(map(int,input().split()))
    return n,l

def main(n,a):
    MOD=10**9+7
    hist=[0]*61
    bs=[]
    for i in range(n):
        # s=list(reversed(bin(a[i])[2:]))
        # for j in range(len(s)):
        #     if s[j]=='1':
        #         hist[j]+=1
        # bs.append(s)
        s=bin(a[i])[2:]
        for j in range(len(s)):
            if s[j]=='1':
                hist[len(s)-j-1]+=1

    #print(bs)
    #print(hist)
    sum=0
    # for i in range(n-1):
    #     s=bs[i]
    #     b=1
    #     for j in range(len(s)):
    #         if s[j]=='0':
    #             sum=(sum+hist[j]*b)%MOD
    #         else:
    #             sum=(sum+( n-i-hist[j] )*b)%MOD
    #             hist[j]-=1
    #         b*=2
    #     for j in range(len(s),61):
    #         sum=(sum+hist[j]*b)%MOD
    #         b*=2
    b=1
    for j in range(61):
        sum=(sum+( hist[j]*(n-hist[j])*b )%MOD )%MOD
        b*=2

    return sum

if __name__=='__main__':
    n,l=readinput()
    ans=main(n,l)
    print(ans)
Buggy code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
B = [0]*60
C = [0]*60

for i in range(60):
    for j in range(N):
        if (A[j]>>i)&1 == 0:
            C[i] += 1
        else:
            B[i] += 1

ans = 0
for i in range(60):
    ans += B[i]*C[i]*2**i%MOD
print(ans)

Fixed code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
B = [0]*60
C = [0]*60

for i in range(60):
    for j in range(N):
        if (A[j]>>i)&1 == 0:
            C[i] += 1
        else:
            B[i] += 1

ans = 0
for i in range(60):
    ans += B[i]*C[i]*2**i%MOD
print(ans%MOD)
Buggy code:
#!/usr/bin/env python3

# mod = 10**9+7

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

# max_digit = 61

# count_0 = [0 for _ in range(max_digit)]
# count_1 = [0 for _ in range(max_digit)]

# for i in range(len(a)):
#     num_str = bin(a[i])[2:]
#     # print(num_str)
#     for j in range(len(num_str)):
#         # print(num_str[-j-1])
#         if num_str[-j-1] == "1":
#             count_1[-j-1] += 1

# # for i in range(max_digit):
# #     count_0[i] = n-count_1[i]

# ans = 0
# count = 1
# for i in range(61):
#     # tmp = count_0[-i-1]*count_1[-i-1]
#     tmp = count_1[-i-1]*(n-count_1[-i-1])
#     ans += tmp*count
#     count = (count*2) % mod
# print(ans % mod)


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

mod = 10**9+7
max_digit = 61

ans = 0
m = 1
for _ in range(max_digit):
    bit = sum(x&m x in a)
    bit //= m
    non_bit = n - bit
    ans = (ans+bit*nonbit*m)%mod
    m <<= 1
print(ans)

Fixed code:
#!/usr/bin/env python3

# mod = 10**9+7

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

# max_digit = 61

# count_0 = [0 for _ in range(max_digit)]
# count_1 = [0 for _ in range(max_digit)]

# for i in range(len(a)):
#     num_str = bin(a[i])[2:]
#     # print(num_str)
#     for j in range(len(num_str)):
#         # print(num_str[-j-1])
#         if num_str[-j-1] == "1":
#             count_1[-j-1] += 1

# # for i in range(max_digit):
# #     count_0[i] = n-count_1[i]

# ans = 0
# count = 1
# for i in range(61):
#     # tmp = count_0[-i-1]*count_1[-i-1]
#     tmp = count_1[-i-1]*(n-count_1[-i-1])
#     ans += tmp*count
#     count = (count*2) % mod
# print(ans % mod)


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

mod = 10**9+7
max_digit = 61

ans = 0
m = 1
for _ in range(max_digit):
    bit = sum(x&m for x in a)
    bit //= m
    non_bit = n - bit
    ans = (ans+bit*non_bit*m)%mod
    m <<= 1
print(ans)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
bo=[0]*61
bz=[0]*61
for i in a:
  t=format(i,'061b')
  for j in range(61):
    if t[j]=='0':
      bz[j]+=1
    else:
      bo[j]+=1
bo=bo[::-1]
bz=bz[::-1]
x=0
for i in range(61):
  x+=bo[i]*bz[i]*(2**i)
print(x)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
bo=[0]*61
bz=[0]*61
for i in a:
  t=format(i,'061b')
  for j in range(61):
    if t[j]=='0':
      bz[j]+=1
    else:
      bo[j]+=1
bo=bo[::-1]
bz=bz[::-1]
x=0
for i in range(61):
  x+=bo[i]*bz[i]*(2**i)
  x%=m
print(x%m)
Buggy code:
def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

n = iip()
al = iip()

mod = 10**9 + 7
num1 = [0 for i in range(60)]

for a in al:
    b = bin(a)[2:].zfill(60)
    print(b)
    for i in range(60):
        if b[i] == "1":
            num1[i] += 1

result = 0
for i, a in enumerate(num1):
    result += ((a * (n-a)) * 2**(59-i)) % mod
    result = result % mod

#print(num1)
#print(result)

Fixed code:
def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

n = iip()
al = iip()
#al = [2**60 - 114514 - i for i in range(1000)]

mod = 10**9 + 7
num1 = [0 for i in range(60)]

for a in al:
    b = bin(a)[2:].zfill(60)
    #print(b)
    for i in range(60):
        if b[i] == "1":
            num1[i] += 1

result = 0
for i, a in enumerate(num1):
    a1 = 2**(59-i) % mod
    a2 = (a * (n-a)) % mod
    result += a1*a2 % mod
    result = result % mod


#print(num1)
print(result)
Buggy code:
# -*- coding: utf-8 -*-
#https://atcoder.jp/contests/abc141/tasks/abc147_d
import sys
#import collections

n= int(input())

tmp = input().split()
s = list(map(lambda a: int(a), tmp))

total=0
a=[]
b=[]
c=[]
for i in range(0,60):
	a.append(0)
	b.append(0)
	c.append(0)

tmp = s[0]
for j in range(0,60):
	if(tmp==0):
		break
	if(tmp%2==1):
		a[j]+=1
	tmp=tmp//2

tmp = s[n-1]
for j in range(0,60):
	if(tmp==0):
		break
	if(tmp%2==1):
		c[j]+=1
	tmp=tmp//2

for i in range(1,n-1):
	tmp = s[i]
	for j in range(0,60):
		if(tmp==0):
			break
		if(tmp%2==1):
			b[j]+=1
		tmp=tmp//2

#print(s)
#print(a)
#print(b)
#print(c)

total=0
for j in range(60,0,-1):
	total*=2
	total=total+(a[j-1]+b[j-1]+c[j-1])*(n-a[j-1]-b[j-1]-c[j-1])
#	print(total)
print(total)





Fixed code:
# -*- coding: utf-8 -*-
#https://atcoder.jp/contests/abc141/tasks/abc147_d
import sys
#import collections

n= int(input())

tmp = input().split()
s = list(map(lambda a: int(a), tmp))

total=0
a=[]
for i in range(0,60):
	a.append(0)

for i in range(0,n):
	tmp = s[i]
	for j in range(0,60):
		if(tmp==0):
			break
		if(tmp%2==1):
			a[j]+=1
		tmp=tmp//2

total=0
for j in range(60,0,-1):
	total*=2
	if(a[j-1]>0):
		total=total+(a[j-1])*(n-a[j-1])
	if(total>1000000007):
		total=total%1000000007
total=total%1000000007

print(total)
Buggy code:
n, *A = map(int, open(0).read().split())
A = [a%mod for a in A]
mod = 10**9 + 7
ans = 0
d = 1
while any(A):
  c = 0
  for i in range(n):
    q, r = divmod(A[i], 2)
    A[i] = q
    c += r
  ans += c*(n-c) * d
  ans %= mod
  d *= 2
print(ans % mod)

Fixed code:
n, *A = map(int, open(0).read().split())
mod = 10**9 + 7
ans = 0
d = 1
while any(A):
  c = 0
  for i in range(n):
    q, r = divmod(A[i], 2)
    A[i] = q
    c += r
  ans += c*(n-c) * d
  ans %= mod
  d *= 2
print(ans % mod)
Buggy code:
n=int(input())
*a=map(int,input().split())
g=[[0] for i in range(n)]*60
mod=10**9+7
for i in range(n):
    for j in range(60):
        if (a[i]>>j)&1:
            g[j][i]=1

cnt=0
for i in range(60):
    now=g[i].count(1)
    cnt+=now*(n-now)*(2**i)
    cnt%=mod

print(cnt)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
g=[0]*60
mod=10**9+7
for i in range(n):
    for j in range(60):
        if (a[i]>>j)&1==1:
            g[j]+=1

cnt=0
for i in range(60):
    now=g[i]
    cnt+=now*(n-now)*(2**i)
    cnt%=mod

print(cnt)
Buggy code:
n = int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
s = 0

for i in range(60):
    c1 = np.count_nonzero(arr & 1)
    s += 2 ** i * c1 * (n - c1)
    arr = arr >> 1

print(s % mod)

Fixed code:
import numpy as np

n = int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
s = 0

for i in range(60):
    c1 = np.count_nonzero(arr & 1)
    s += 2 ** i * c1 * (n - c1)
    arr = arr >> 1

print(s % mod)
Buggy code:
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])
mod=1e9+7
ans=0
for k in range(60):
  b=(a>>k)&1
  m=np.count_nonzero(b)
  ans+=m*(n-m)*(2**k)
  ans%=mod
print(ans)

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

Fixed code:
n=int(input())
A=list(map(int,input().split()))
ans=0
for d in range(61):
    n_1 = 0
    for a in A:
        if (a>>d)&1 == 1:
            n_1 += 1
    n_0 = n - n_1
        
    ans += n_0*n_1 * 2**d
    ans %= 10**9+7
print(ans)
Buggy code:
mod=10**9 + 7

N=int(input())
A=list(map(int,input().split()))
A=[bin(i)[2:] for i in A]
nowdata=[0 for i in range(60)]
data=[0 for i in range(60)]



for i in range(N-1):
    S=A[i]
    for a in range(len(S)):
        nowdata[a]+=int(S[-a-1])
    S=A[i+1]
    for a in range(len(S)):
        if not int(S[-a-1]):
            data[a]+=nowdata[a]
        else:
            data[a]+=i+1-nowdata[a]


num=0
#print(data)
for i in range(60):
    num+=data[i]* (2**i)
    num%=mod

print(num)


Fixed code:
mod=10**9 + 7
#print(bin(9))
N=int(input())
A=list(map(int,input().split()))
A=[bin(i)[2:] for i in A]
A=[(60-len(i)) * "0" + i for i in A]
#print(A)
nowdata=[0 for i in range(60)]
data=[0 for i in range(60)]

#print(A)

for i in range(N-1):
    S=A[i]
    #print(nowdata)
    for a in range(len(S)):
        if S[a]=="1":
            nowdata[a]+=1
    S=A[i+1]
    for a in range(len(S)):
        if S[a]=="0":
            data[a]+=nowdata[a]
        else:
            data[a]+=i+1-nowdata[a]


num=0
#print(data)
for i in range(60):
    num+=data[-i-1]* (2**i)
    num%=mod

print(num)
Buggy code:
n=int(input())
l=[int(c) for c in input().splt()]
ans=0
mod=10**9+7
for i in range(60):
  s=sum(a>>i&1 for a in l)
  ans+=s*(n-s)<<i%mod
  ans%=mod
print(ans)

Fixed code:
n=int(input())
l=[int(c) for c in input().split()]
ans=0
mod=10**9+7
for i in range(60):
  s=sum(a>>i&1 for a in l)
  ans+=s*(n-s)<<i%mod
  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):
  x=1<<(i+1)
  z=o=0
  for j in range(n):
    if a[j]&x:o+=1
    else:z+=1
  ans=(ans+((x%mod)*o*z)%mod)%mod
print(ans)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
x=1
for i in range(60):
  z=o=0
  for j in range(n):
    if a[j]%2:o+=1
    else:z+=1
    a[j]//=2
  ans+=(x*o*z)%mod
  ans%=mod
  x=(x*2)%mod
print(ans)
Buggy code:
n,*a=map(int,open(0).read().split());c=i=0
for _ in[0]*61:i**=2;t=sum(i&b and 1for b in a);c+=t*(n-t)*i;c%=10**9+7
print(c)

Fixed code:
n,*a=map(int,open(0).read().split());c=0;i=1
for _ in[0]*61:t=sum(i&b and 1for b in a);c+=t*(n-t)*i;c%=10**9+7;i*=2
print(c)
Buggy code:
n=int(input())
a=list(map(int,input().split()))

b=max(a)
k=0

while b!=0:
    b=b//2
    k+=1

ans=0

for i in range(k):
    x=0
    y=0
    for j in range(n):
        if (a[j]>>i)%2==1:
            x+=1
        else:
            y+=1
    ans+=(2**i)*(x*y)
print(ans)

Fixed code:
m=10**9+7

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

b=max(a)
k=0

while b!=0:
    b=b//2
    k+=1

ans=0

for i in range(k):
    x=0
    y=0
    for j in range(n):
        if (a[j]>>i)%2==1:
            x+=1
        else:
            y+=1
    ans+=((2**i)%m) * ((x*y)%m)
print(ans%m)
Buggy code:
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()] , dtype=np.int64)
a_ = list(map(int, input().split()))
m = 10**9+7
ans = 0
for k in range(60):
    b = (a>>k) & 1
    res = np.count_nonzero(b)
    ans += res*(n-res)*2**k
print(ans%m)

Fixed code:
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()] , dtype=np.int64)
m = 10**9+7
ans = 0
for k in range(60):
    b = (a>>k) & 1
    res = np.count_nonzero(b)
    ans += res*(n-res)*2**k
print(ans%m)