Problem:
 Score : 400 points    Problem Statement We have N integers. The i -th integer is A_i .  Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j) , modulo (10^9+7) .   What is \mbox{ XOR } ?  The XOR of integers A and B , A \mbox{ XOR } B , is defined as follows:  When A \mbox{ XOR } B is written in base two, the digit in the 2^k 's place ( k \geq 0 ) is 1 if either A or B , but not both, has 1 in the 2^k 's place, and 0 otherwise.  For example, 3 \mbox{ XOR } 5 = 6 . (In base two: 011 \mbox{ XOR } 101 = 110 .)       Constraints  2 \leq N \leq 3 \times 10^5  0 \leq A_i < 2^{60}  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N       Output Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j) , modulo (10^9+7) .        Sample Input 1 3
1 2 3      Sample Output 1 6  We have (1\mbox{ XOR } 2)+(1\mbox{ XOR } 3)+(2\mbox{ XOR } 3)=3+2+1=6 .       Sample Input 2 10
3 1 4 1 5 9 2 6 5 3      Sample Output 2 237       Sample Input 3 10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820      Sample Output 3 103715602  Print the sum modulo (10^9+7) .

Solution (Python):
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'
    
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase

read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
input=lambda: sys.stdin.readline().rstrip()

class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=1):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.node_size=len(ls)+1
                self.edges,_=GI(self.node_size,self.node_size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.node_size=int(input())
        else:
            self.node_size=inp_size
        self.edges,_=GI(self.node_size,self.node_size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.node_size=len(ls)+1
        self.edges,_=GI(self.node_size,self.node_size-1,ls,index=index)
        return
 
    def dfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.node_size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def bfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.node_size
        v[x]=root_v
        while q:
            c=q.popleft()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def parent(self,x):
        return self.dfs(0,func=lambda pr,prv,nx,dist:pr,root_v=-1)
 
    def topological_sort(self,x):  
        tps=[]
        q=deque([x])
        v=[None]*self.node_size
        v[x]=0
        while q:
            c=q.popleft()
            tps.append(c)
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=0
        return tps
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.node_size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.node_size
        self.ETout=[-1]*self.node_size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]
 
    def __str__(self):
        return  str(self.edges)
 
    def show(self):
        if all([all([d==1 for nd,d in e]) for e in self.edges]):
            print( [[nd for nd,d in e] for e in self.edges] )
        else:
            print(self)

class SparseTable: 
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    
    def query(self,l,r):
        if r>self.size:r=self.size
        
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    
    def query_id(self,l,r):
        if r>self.size:r=self.size
        
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    
    def right_bound(self,pos,x):
        k=(self.size-pos).bit_length()
        for j in range(k)[::-1]:
            nx=pos+(1<<j)
            if nx<n and self.query(pos,nx+1)<=x:
                pos+=(1<<j)
        return pos
    
    
    def left_bound(self,pos,x):
        k=pos.bit_length()
        for j in range(k)[::-1]:
            nx=pos-(1<<j)
            if 0<=nx and self.query(nx,pos+1)<=x:
                pos-=(1<<j)
        return pos
 
    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)


show_flg=False
show_flg=True


ans=0
n=I()
a=LI()
for j in rep(61):
    b=[(i>>j)&1 for i in a]
    one=sum(b)
    zero=n-one
    ans+=(1<<j)*one*zero
    ans%=mo
    
print(ans)

Solution (Python):
import sys
from io import StringIO
import unittest
import os
from operator import ixor


sys.setrecursionlimit(999999999)



def resolve(test_def_name=""):
    
    
    
    
    
    

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

    one_counts = [0 for i in range(61)]
    zero_counts = [0 for i in range(61)]

    
    
    
    max_num = max(a_s)
    max_loop = 0
    for i in range(0, 61):
        if max_num < 1 << i:
            break
        max_loop += 1

    
    
    for a in a_s:
        for i in range(0, max_loop):
            if a & 1 << i:
                one_counts[i] += 1
            else:
                zero_counts[i] += 1
    
    

    
    ans = 0
    for i in range(0, max_loop):
        
        ans += (one_counts[i] * zero_counts[i] * pow(2, i)) % (pow(10, 9) + 7)
        ans = ans % (pow(10, 9) + 7)

    
    print(ans)



class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
1 2 3"""
        output = """6"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """10
3 1 4 1 5 9 2 6 5 3"""
        output = """237"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820"""
        output = """103715602"""
        self.assertIO(test_input, output)

    
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)



if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        
        resolve()

    else:
        
        unittest.main()

Solution (Python):
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()

n=ii()
a=lmi()
INF=10**9+7
ans=0
for i in range(60):
  x=0
  for j in range(n):

    if (a[j]>>i)&1:
      x+=1

  num=x*(n-x)*2**i
  ans+=num

print(ans%INF)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

m = 1000000007

result = 0
for i in range(60):
    j = 1 << i
    c = sum((a & j) >> i for a in A)
    result += (c * (N - c)) << i
    result %= m
print(result)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

m = 1000000007

result = 0
for i in range(60):
    j = 1 << i
    c = sum(a & j for a in A) >> i
    result += (c * (N - c)) << i
    result %= m
print(result)

Solution (Python):
import numpy as np

N = int(input())
A = np.fromiter(map(int, input().split()), np.int64)

m = 1000000007

result = 0
for bit in range(60):
    c = int((A & 1).sum())
    A >>= 1
    result = (result + c * (N - c) * (1 << bit)) % m
print(result)

Solution (Python):
def main():
  N=int(input())
  A=list(map(int,input().split()))
  mod=10**9+7
  ans=0
  for i in range(60):
    c=0
    for j in A:
      if j>>i&1:
        c+=1
    ans+=pow(2,i,mod)*c*(N-c)
    ans%=mod
  print(ans)
if __name__=='__main__':
  main()

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

n = ir()
a = lr()

dp = [0 for i in range(60)]

for num in a:
    for j in range(60):
        if ((num >> j) & 1):
            dp[j]+=1
ans = 0
for i in range(60):
    k = dp[i]
    tmp = k*(n-k)*power(2,i,mod)%mod
    ans = (ans+tmp)%mod
print(ans)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))

ans = 0
for bit in range(60):
    m = 1 << bit
    c = sum(a & m for a in A) >> bit
    ans += (c * (n - c)) << bit
    ans %= (10**9+7)
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))

mod=10**9+7
ans=0

for i in range(60):
    a=0
    for x in A:
        if x>>i&1:
            a+=1
    ans+=a*(N-a)*pow(2,i,mod)
    ans%=mod

    
print(ans)

Solution (Python):
def main():
  N=int(input())
  A=list(map(int,input().split()))

  mod=10**9+7
  ans=0

  for i in range(60):
      a=0
      for x in A:
          if x>>i&1:
              a+=1
      ans+=a*(N-a)*pow(2,i,mod)
      ans%=mod
  print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

MOD = 10**9+7
ans = 0

for i in range(60):
    cnt = 0
    for a in A:
        cnt += a>>i&1
    ans += cnt*(n-cnt)*2**i
    ans %= MOD

print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

MOD = 10**9+7
ans = 0

for i in range(60):
    cnt = 0
    for a in A:
        cnt += a>>i&1
    ans += cnt*(n-cnt)*2**i
    ans %= MOD

print(ans)

Solution (Python):
mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
keta = [[0,0] for _ in range(60)]
for i in a:
    for j in range(60):
        if (i >> j) & 1:
            keta[j][1] += 1
        else:
            keta[j][0] += 1
ans = 0
for i in range(len(keta)):
    lis = keta[i]
    ans += lis[0] * lis[1] * pow(2, i, mod)
    ans %= mod
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(60):
  X=1<<i
  n=len([1 for a in A if a&X])
  ans+=X*n*(N-n)%mod
  ans%=mod
print(ans)

Solution (Python):
def solve():
    MOD = 10**9 + 7

    N = int(input())
    As = list(map(int, input().split()))

    ans = 0
    for d in range(60):
        mask = 1<<d
        num1 = len([1 for A in As if A & mask])
        ans += num1 * (N-num1) * mask
        ans %= MOD

    print(ans)


solve()

Solution (Python):
def solve():
    MOD = 10**9 + 7

    N = int(input())
    As = list(map(int, input().split()))

    ans = 0
    for d in range(60):
        nums = [0, 0]
        for A in As:
            b = (A>>d) & 1
            nums[b] += 1
        v = nums[0]*nums[1]
        v *= pow(2, d, MOD)
        ans += v
        ans %= MOD

    print(ans)


solve()

Solution (Python):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)
    dig = len(bin(M)) - 2
    MOD = 10 ** 9 + 7
    ans = 0
    d = {i: 0 for i in range(dig)}
    for a in A:
        a = bin(a)[2:]
        for i in range(len(a)):
            if a[-(i+1)] == '1':
                d[i] += 1
    for i in range(dig):
        ans += d[i] * (n - d[i]) * pow(2, i, MOD)
        ans %= MOD
    print(ans)
main()

Solution (Python):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)
    dig = len(bin(M)) - 2
    MOD = 10 ** 9 + 7
    ans = 0
    d = {i: [0, 0] for i in range(dig)}
    for a in A:
        a = bin(a)[2:].zfill(dig)
        for i in range(len(a)):
            if a[-(i+1)] == '0':
                d[i][0] += 1
            else:
                d[i][1] += 1
    for i in range(dig):
        ans += d[i][0] * d[i][1] * pow(2, i, MOD)
        ans %= MOD
    print(ans)
main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7

ans = 0

for i in range(60):
    cnt = 0
    for a in A:
        cnt += a>>i&1
    ans += cnt*(N-cnt)*2**i
    ans %= mod
    
print(ans)

Solution (Python):
import numpy as np
def main():
    mod = 1000000007
    n = int(input())
    A = np.array(list(map(int, input().split())), dtype = np.int)
    ans = 0
    for i in range(61):
        n1 = np.sum((A >> i) & 1)
        tmp = (n - n1) * n1
        for _ in range(i):
            tmp = (tmp * 2) % mod
        ans += tmp
    print(ans % mod)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9+7
    
    
    ans = 0
    for d in range(60):
        p,q = 0,0
        for i in range(N):
            if A[i]%2==0: p+=1
            else: q+=1
            A[i] //= 2
        ans += ((2**d)*p*q)%MOD
        ans %= MOD
    print(ans)

main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

bitlist = [0] * 60

for i in A:
    for index, num in enumerate(reversed(bin(i)[2:])):
        if num == "1":
            bitlist[index] += 1
ans = 0
for bit, num in enumerate(bitlist):
    ans += num * (N-num) * (2 ** bit)
    ans %= (10**9+7)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007

sum_all = 0
p = 1
for i in range(60):
    ones = 0
    zeros = 0

    x = 1 << i
    for a in A:
        if a & x:
            ones += 1
        else:
            zeros += 1

    sum_all += p * ones * zeros % MOD
    p *= 2 % MOD


print(sum_all % MOD)

Solution (Python):
import sys
input = sys.stdin.readline
def main():

    N = int(input())
    A = list(map(int, input().split()))
    p = 10**9 + 7
    total = 0
    for i in range(60):
        cnt_1, cnt_0 = 0, 0
        for j in range(N):
            if (A[j]>>i)&1:
                cnt_1 += 1
            else:
                cnt_0 += 1
        total += pow(2, i, p) * cnt_0 * cnt_1 %p
    print(total%p)
main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
num_list = [0] * 100
P = 10 ** 9 + 7
for i in A:
    tmp = i
    for j in range(len(bin(i)) - 2):
        num_list[j] += (tmp & 1)
        tmp = tmp >> 1
ans = 0


def func(N, n):
    return (N - n) * n


for i in range(100):
    ans = (ans + func(N, num_list[i]) * 2 ** i) % P
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

M = 61
D1 = [0] * M

for a in A:
    k = 0
    while a > 0:
        if a & 1:
            D1[k] += 1
        a >>= 1
        k += 1

MOD = 10 ** 9 + 7
ans = 0
for k in range(M):
    d = D1[k]
    ans += d * (N - d) * pow(2, k, MOD)
    ans %= MOD

print(ans)

Solution (Python):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))
    d_0 = [N for _ in range(61)]
    d_1 = [0 for _ in range(61)]
    max_d = 0
    for a in A:
        d = 0
        while a > 0:
            keta = a % 2
            a //= 2
            if keta == 1:
                d_0[d] -= 1
                d_1[d] += 1
            d += 1
        if d > max_d:
            max_d = d
    
    
    answer = 0
    for i in range(max_d):
        answer += d_0[i] * d_1[i] * 2 ** i
        answer %= MOD
    print(answer)


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

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

ans = 0
MOD = 10**9+7

k = max(a)
j = 0
while k:
    bits = (a>>j)&1
    one = np.count_nonzero(bits)
    ans += (one%MOD)*((n-one)%MOD)*pow(2,j,MOD)
    ans %= MOD
    j += 1
    k >>= 1

print(ans)

Solution (Python):
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
ans=0
for i in range(60):
    ichi=0
    for j in range(n):
        if (a[j]>>i)&1:
            ichi+=1
    zero=n-ichi
    s=ichi*zero*pow(2,i,mod)%mod
    ans+=s
    ans%=mod
print(ans)

Solution (Python):
import numpy as np
N = 10**9+7
n = int(input())
a = np.array(input().split(), np.int64)

ans = 0

po = 1
for i in range(61):
    bit = (a>>i) & 1
    s=np.count_nonzero(bit)
    ans+=s*(n-s)%N*po
    ans%=N
    po*=2
    po%=N
print(ans)

Solution (Python):

import numpy as np











N = int(input())
A = np.fromstring(input(),dtype = np.int64, sep = ' ')
Large = 10**9 + 7
ans = 0
for i in range(60):
    sum1 = int((A&1).sum())
    ans += sum1*(N-sum1) * 2**i
    
    A>>=1 
print(ans%Large)

Solution (Python):
from sys import stdin
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

if __name__=='__main__':
    mod = 10**9 + 7
    n = I()
    a = LI()
    ans = 0
    for i in range(60):
        c1 = 0
        for rep in a:
            if (rep>>i)&1:
                c1 += 1
        ans += ((n-c1)*c1*(2**i)%mod)%mod
    print(ans%mod)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    for i in range(60):
        cnt = 0
        for a in A:
            cnt += (a >> i) & 1
        res += (cnt * (n - cnt) % mod) * (1 << i) % mod
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction


def ternary (n, k, length):
    if n == 0:
        nums = ['0' for i in range(length)]
        nums = ''.join(nums)
        return nums
    nums = ''
    while n:
        n, r = divmod(n, k)
        nums += str(r)
    nums = nums[::-1]
    nums = nums.zfill(length)
    return nums


def main():
    num = int(input())
    data = list(map(int, input().split()))
    mod = 10 ** 9 + 7

    max_length = len(bin(max(data))) - 2
    bit_count = [0 for i in range(max_length)]

    for i in range(num):
        now_bin = bin(data[i])[2:]
        now_bin = now_bin.zfill(max_length)
        for j in range(max_length):
            if now_bin[j] == "1":
                bit_count[j] += 1

    flg_data = [0 for i in range(max_length)]


    for i in range(max_length):
        flg_data[i] += bit_count[i] * (num - bit_count[i])

    ans = 0
    for j in range(max_length):
        pow_num = max_length - 1 - j
        bbb = pow(2, pow_num, mod)

        ans += bbb * flg_data[j]
        ans %= mod

    print(ans)




if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = tuple(map(int, input().split()))
MOD = 10**9+7

arr = [0] * 60
for a in A:
    for i in range(60):
        if a>>i & 1:
            arr[59-i] += 1

ans = 0
for i, a in enumerate(arr):
    b = N - a
    ans += (a*b) * (2**(59-i))
    ans %= MOD
print(ans)

Solution (Python):
import numpy as np
n = int(input())
s = np.array(input().split(), np.int64)
mod = 10 ** 9 + 7

res = 0
po2 = 1
for i in range(61):
    bit = (s >> i) & 1
    x = np.count_nonzero(bit)
    y = n - x
    res += x * y % mod * po2
    res %= mod
    po2 *= 2 % mod
print(res)

Solution (Python):
n = int(input())
s = list(map(int, input().split()))
mod = 10**9 + 7
m = len(bin(max(s))) - 2
p = [0] * m
q = [0] * m

for i in s:
    for j in range(m):
        if (i >> j) & 1 == 1:
            p[j] += 1
        else:
            q[j] += 1

res = 0
r = 1
for k in range(m):
    res += p[k] * q[k] % mod * r
    res %= mod
    r = r * 2 % mod
print(res)

Solution (Python):
import sys
import itertools

import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

MOD = 10 ** 9 + 7

x = 1
ans = 0
for i in range(60):
    ones = 0
    zeros = 0
    for a in A:
        if a & (1 << i) > 0:
            ones += 1
        else:
            zeros += 1
    ans += (ones * zeros * x) % MOD
    x *= 2

print(ans % MOD)

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

mod = 10 ** 9 + 7

res = 0
two_factor = 1
for i in range(60):
    cnt_1 = 0
    cnt_0 = 0
    for v in a:
        if (v >> i) & 1:
            cnt_1 += 1
        else:
            cnt_0 += 1
    res = (res + cnt_1 * cnt_0 % mod * two_factor % mod) % mod
    two_factor = two_factor * 2 % mod

print(res)

Solution (Python):
def mod_pow(a, n):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


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

mod = 10 ** 9 + 7

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

pow_2 = [1]
for i in range(60):
    pow_2.append(pow_2[-1] * 2 % mod)

res = 0
for v in a:
    for i in range(60):
        if (v >> i) & 1:
            res = (res + (n - cnt[i]) * pow_2[i] % mod) % mod
        else:
            res = (res + cnt[i] * pow_2[i] % mod) % mod

print(res * mod_pow(2, mod - 2) % mod)

Solution (Python):
import numpy as np
MOD = 10 ** 9 + 7
N = int(input())
A = np.array(input().split(), dtype=np.int64)
total = 0
for shamt in range(65):
    bits = np.count_nonzero(A & 1)
    total += (bits * (N - bits)) << shamt
    A >>= 1
    if not A.any():
        break
print(total % MOD)

Solution (Python):
def str2bitstr(chs):
    val = int(chs)
    tmp = bin(val)[2:]
    tmp2 = '0' * (60 - len(tmp))
    return tmp2 + tmp


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

cnts = [0] * 60

for item in a:
    for i, ch in enumerate(item):
        if ch == '1':
            cnts[i] += 1

ret = 0
now = 1

for i in range(1, 61):
    kumi = cnts[-i] * (n - cnts[-i]) % (10 ** 9 + 7)
    ret += kumi * now % (10 ** 9 + 7)
    now *= 2 % (10 ** 9 + 7)
    ret = ret % (10 ** 9 + 7)

print(ret % (10 ** 9 + 7))

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
mod=10**9+7

bins_zero=[0]*61
bins_one=[0]*61
for a_i in a:
    a_i_bin=list(str(bin(a_i))[2:].zfill(61))
    for i in range(len(a_i_bin)):
        if a_i_bin[i]=='0':
            bins_zero[i]+=1
        else:
            bins_one[i]+=1

ans=0
for i in range(61):
    ans+=(bins_one[i]*bins_zero[i]*(2**(60-i)))
print(ans%mod)

Solution (Python):
import sys
readline = sys.stdin.readline
import numpy as np

N = int(readline())
A = np.array(readline().split(),dtype=int)
DIV = 10 ** 9 + 7



K = max(A)
  
j = 0
ans = 0
while K:
  bits = (A >> j) & 1
  one = np.count_nonzero(bits)
  ans += (one % DIV) * ((N - one) % DIV) * pow(2,j,DIV)
  ans %= DIV
  j += 1
  K >>= 1

print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))
DIV = 10 ** 9 + 7



K = max(A) 
ans = 0
j = 0
while K:
  one = 0
  for i in range(len(A)):
    if (A[i] >> j) & 1:
      one += 1
  ans += (one % DIV) * ((N - one) % DIV) * pow(2,j,DIV)
  ans %= DIV
  j += 1
  K >>= 1
  
print(ans)

Solution (Python):
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
    cnt = 0
    for x in a:
        if (x >> i) & 1:
            cnt += 1
    ans += cnt * (n - cnt) * (1 << i)
print(ans % MOD)

Solution (Python):
def main():
    MOD = 10**9+7
    n = int(input())
    al = list(map(int, input().split()))

    base_2_cnt = [0]*60 
    for a in al:
        for i in range(60):
            if ((a >> i) & 1): base_2_cnt[i] += 1

    ans = 0
    curr_2 = 1
    for i in range(60):
        base_01_comb = base_2_cnt[i] * (n-base_2_cnt[i])
        ans += base_01_comb * curr_2
        ans %= MOD
        curr_2*=2
        curr_2%=MOD

    print(ans%MOD)

if __name__ == "__main__":
    main()

Solution (Python):

"""
D - Xor Sum 4
https://atcoder.jp/contests/abc147/tasks/abc147_d

"""
import sys


def solve(N, A):
    MOD = 10**9 + 7
    bit_len = max(map(int.bit_length, A))
    ans = 0
    for i in range(bit_len):
        zeros, ones = 0, 0
        for a in A:
            if (a & 1<<i):
                ones += 1
            else:
                zeros += 1
        ans = (ans + (ones * zeros * 2**i)) % MOD
    return ans % MOD


def main(args):
    N = int(input())
    A = list(map(int, input().split()))
    ans = solve(N, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    cnt1 = 0
    for j in range(N):
        cnt1 += (A[j]>>i)&1
    ans += cnt1 * (N-cnt1) * 2**i
    ans %= 10**9+7

print(ans)

Solution (Python):
from sys import stdin
import numpy as np
def main():
    
    readline=stdin.readline
    mod=10**9+7
    n=int(readline())
    a=list(map(int,readline().split()))
    a=np.array(a,dtype=np.int64)

    b=np.array([((a>>i)&1).sum() for i in range(61)],dtype=np.int64)
    c=np.full(61,n,dtype=np.int64)-b
    d=b*c
    d%=mod

    ans=0
    now=1
    for i in range(60):
        ans+=d[i]*now
        ans%=mod
        now*=2
        now%=mod

    print(ans)

if __name__=="__main__":
    main()