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):
def main():
    N = int(input())
    A = list(map(int, input().split()))

    MOD = 10 ** 9 + 7

    lst = [0] * 65
    for a in A:
        tmp = a
        for i in range(61):
            lst[i] += tmp % 2
            tmp //= 2
            if tmp == 0:
                break

    calc = [1]
    for i in range(65):
        calc.append((calc[-1] * 2) % MOD)

    ans = 0
    for a in A:
        tmp = a
        for i in range(61):
            n = tmp % 2
            tmp //= 2
            if n == 1:
                ans += (calc[i] * (N - lst[i])) % MOD
            else:
                ans += (calc[i] * lst[i]) % MOD
        ans %= MOD

    def modinv(a, m): 
        b = m
        u = 1
        v = 0
        while b:
            t = a//b
            a -= t * b
            a, b = b, a
            u -= t * v
            u, v = v, u
        
        u %= m
        if u < 0:
            u += m
        return u

    
    ans *= modinv(2, MOD)
    print (ans % MOD)

if __name__ == '__main__':
    main()

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

MOD = 10 ** 9 + 7

lst = [0] * 65
for a in A:
    tmp = a
    for i in range(61):
        lst[i] += tmp % 2
        tmp //= 2
        if tmp == 0:
            break

calc = [1]
for i in range(65):
    calc.append((calc[-1] * 2) % MOD)

ans = 0
for a in A:
    tmp = a
    for i in range(61):
        n = tmp % 2
        tmp //= 2
        if n == 1:
            ans += calc[i] * (N - lst[i])
        else:
            ans += calc[i] * lst[i]
    ans %= MOD

def modinv(a, m): 
    b = m
    u = 1
    v = 0
    while b:
        t = a//b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    
    u %= m
    if u < 0:
        u += m
    return u


ans *= modinv(2, MOD)
print (ans % MOD)

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

DIGIT = 61
MOD = (10**9) +7
count = 0
for i in range(DIGIT):
    one_count = 0
    for num in a_list:
        if (num >> i) % 2 == 1:
            one_count += 1
    comb_1_1 = one_count * (n - one_count)
    count += comb_1_1 * (2**i)
    count = count % MOD
    
print(count)

Solution (Python):
n = int(input())
ar = list(map(int, input().split()))
res = 0
mod = 10 ** 9 + 7
for i in range(60):
    zero = 0
    one = 0
    for j in range(len(ar)):
        if ar[j] % 2 == 0:
            zero += 1
        else:
            one += 1
        ar[j] = ar[j] // 2
    curr = (zero * one * (1 << i)) % mod
    res = (res + curr) % mod
print(res)

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

ans = 0
for i in range(61):
  ones=sum([1 for a in A if (a>>i)&1])
  ans += (1<<i)*ones*(N-ones)
  ans %= M

print(ans)

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


class modint():
    def __init__(self, value):
        self.value = value % MOD

    def __int__(self):
        return int(self.value)

    def __float__(self):
        return float(self.value)

    def __str__(self):
        return str(self.value)

    def __repr__(self):
        return str(self.value)

    def __add__(self, other):
        return (modint(self.value + other.value) if isinstance(other, modint)
                else modint(self.value + other))

    def __sub__(self, other):
        return (modint(self.value - other.value) if isinstance(other, modint)
                else modint(self.value - other))

    def __mul__(self, other):
        return (modint(self.value * other.value) if isinstance(other, modint)
                else modint(self.value * other))

    def __truediv__(self, other):
        return (modint(self.value * pow(other.value, MOD - 2, MOD))
                if isinstance(other, modint)
                else modint(self.value * pow(other, MOD - 2, MOD)))

    def __pow__(self, other):
        return (modint(pow(self.value, other.value, MOD))
                if isinstance(other, modint)
                else modint(pow(self.value, other, MOD)))

    def __eq__(self, other):
        return (self.value == other.value if isinstance(other, modint)
                else self.value == (other % MOD))

    def __ne__(self, other):
        return (self.value == other.value if isinstance(other, modint)
                else self.value == (other % MOD))

    def __radd__(self, other):
        return (modint(other.value + self.value) if isinstance(other, modint)
                else modint(other + self.value))

    def __rsub__(self, other):
        return (modint(other.value - self.value) if isinstance(other, modint)
                else modint(other - self.value))

    def __rmul__(self, other):
        return (modint(other.value * self.value) if isinstance(other, modint)
                else modint(other * self.value))

    def __rtruediv__(self, other):
        return (modint(other.value * pow(self.value, MOD - 2, MOD))
                if isinstance(other, modint)
                else modint(other * pow(self.value, MOD - 2, MOD)))

    def __rpow__(self, other):
        return (modint(pow(other.value, self.value, MOD))
                if isinstance(other, modint)
                else modint(pow(other, self.value, MOD)))

    def modinv(self):
        """
        self.valueのmod MOD上での乗法逆元を返す
        >>> MOD
        13
        >>> x = modint(4)
        >>> x.modinv
        <bound method modint.modinv of 4>
        >>> x.modinv()
        10
        """
        return modint(pow(self.value, MOD - 2, MOD))


def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    A = ["{:0>60b}".format(int(i)) for i in input().split()]
    ans = modint(0)
    for i in range(60):
        num_one = 0
        for a in A:
            if a[-(i+1)] == "1":
                num_one += 1
        ans += ((N-num_one)*num_one)*(2**i)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(62):
    c=0
    for ai in a:
        if ai&(1<<i):
            c+=1
    r=c*(n-c)
    ans+=(1<<i)*r
    ans%=(10**9+7)
print(ans)

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


class modint():
    def __init__(self, value):
        self.value = value % MOD

    def __int__(self):
        return int(self.value)

    def __float__(self):
        return float(self.value)

    def __str__(self):
        return str(self.value)

    def __repr__(self):
        return str(self.value)

    def __add__(self, other):
        return (modint(self.value + other.value) if isinstance(other, modint)
                else modint(self.value + other))

    def __sub__(self, other):
        return (modint(self.value - other.value) if isinstance(other, modint)
                else modint(self.value - other))

    def __mul__(self, other):
        return (modint(self.value * other.value) if isinstance(other, modint)
                else modint(self.value * other))

    def __truediv__(self, other):
        return (modint(self.value * pow(other.value, MOD - 2, MOD))
                if isinstance(other, modint)
                else modint(self.value * pow(other, MOD - 2, MOD)))

    def __pow__(self, other):
        return (modint(pow(self.value, other.value, MOD))
                if isinstance(other, modint)
                else modint(pow(self.value, other, MOD)))

    def __eq__(self, other):
        return (self.value == other.value if isinstance(other, modint)
                else self.value == (other % MOD))

    def __ne__(self, other):
        return (self.value == other.value if isinstance(other, modint)
                else self.value == (other % MOD))

    def __radd__(self, other):
        return (modint(other.value + self.value) if isinstance(other, modint)
                else modint(other + self.value))

    def __rsub__(self, other):
        return (modint(other.value - self.value) if isinstance(other, modint)
                else modint(other - self.value))

    def __rmul__(self, other):
        return (modint(other.value * self.value) if isinstance(other, modint)
                else modint(other * self.value))

    def __rtruediv__(self, other):
        return (modint(other.value * pow(self.value, MOD - 2, MOD))
                if isinstance(other, modint)
                else modint(other * pow(self.value, MOD - 2, MOD)))

    def __rpow__(self, other):
        return (modint(pow(other.value, self.value, MOD))
                if isinstance(other, modint)
                else modint(pow(other, self.value, MOD)))

    def modinv(self):
        """
        self.valueのmod MOD上での乗法逆元を返す
        >>> MOD
        13
        >>> x = modint(4)
        >>> x.modinv
        <bound method modint.modinv of 4>
        >>> x.modinv()
        10
        """
        return modint(pow(self.value, MOD - 2, MOD))


def main():
    N = int(input())
    A = ["{:0>60b}".format(int(i)) for i in input().split()]
    ans = modint(0)
    for i in range(60):
        num_one = 0
        for a in A:
            if a[-(i+1)] == "1":
                num_one += 1
        ans += ((N-num_one)*num_one)*(2**i)
    print(ans)


if __name__ == '__main__':
    main()

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

ans = 0
for i in range(60):
  p = 1 << i
  num_one = len([1 for x in A if x & p])
  ans += p * num_one * (N - num_one)
print(ans % 1000000007)

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

ans = 0
for i in range(60):
  p = 1 << i
  num_one = len([1 for x in A if x & p])
  ans = ans + p * num_one * (N - num_one)
print(ans % 1000000007)

Solution (Python):
import numpy as np

N=int(input())
A=np.array(input().split(),dtype=int)

DIV=10**9+7

ans=0
for i in range(60):
  bits=(A>>i)&1
  nonzero=np.count_nonzero(bits)
  zeros=N-nonzero
  pat=nonzero*zeros
  for p in range(i):
    pat*=2
  ans+=pat
  ans%=DIV
  
print(ans)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
  
keta=[0]*60
for i in range(n):
  tar=A[i]
  ind=0
  while tar>0:
    if tar&1==1:
      keta[ind]+=1
    tar>>=1
    ind+=1

pair=[0]*60
for i in range(len(keta)):
  pair[i]=keta[i]*(len(A)-keta[i])
  
ans=0
mul=1
DIV=10**9+7
for i in range(len(pair)):
  ans+=pair[i]*mul
  ans%=DIV
  mul*=2
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
src = list(map(lambda x: str(bin(int(x)))[2:], input().split()))
c = Counter()
mod = 10**9 + 7
for num in src:
    l = len(num)
    num = num[::-1]
    for i in range(l):
        if num[i] == '1':
            c[2**i] += 1
ans = 0
for i in c:
    ans += i*(N-c[i])*c[i]
    ans %= mod
print(ans)

Solution (Python):
import sys
import numpy as np

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())
a = np.array(a, dtype=np.int64)

def main():
    ans = 0
    for i in range(60):
        b = (a >> i) & 1
        x = np.count_nonzero(b)
        y = n - x
        x *= y
        x *= pow(2, i, MOD)
        ans += x
    ans %= MOD
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

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

import numpy as np

mod = 10**9+7

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

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

Solution (Python):
import numpy as np

N = int(input())
arr = np.array([int(i) for i in input().split()])

ans = 0

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


print(ans%1000000007)

Solution (Python):
import sys
import numpy as np

MOD = 10 ** 9 + 7

N, *A = map(int, sys.stdin.read().split())
A = np.array(A, dtype=np.int64)

def main():
    answer = 0
    for n in range(60):
        B = (A >> n) & 1
        x = np.count_nonzero(B)
        y = N - x
        x *= y
        x *= pow(2, n, MOD)
        answer += x
    answer %= MOD
    return answer

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
n = int(input())
x0 = [0] * 60
x1 = [0] * 60
for i in map(int,input().split()):
  i = bin(i)[2:]
  i = '0'*(60-len(i)) + i
  for j in range(60):
    if i[-j-1] == '0':
      x0[j] += 1
    else:
      x1[j] += 1
ans = 0
for i in range(60):
  ans += (x0[i]*x1[i]*pow(2,i,10**9+7)) % (10**9+7)
print(ans%(10**9+7))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
l = len(bin(a_max)) - 2
bits = [[0, 0] for _ in range(l)]
for num in a:
    for i, bit in enumerate(format(num, 'b').zfill(l)):
        if bit == '0':
            bits[i][0] += 1
        else:
            bits[i][1] += 1

sumation = 0
div = (10**9+7)
for i in range(l):
    sumation += (bits[i][0]) * (bits[i][1]) * (2**(l-i-1) % div)
print(int(sumation % (10**9+7)))

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
binA=[None]*n
for i in range(n):
  binA[i]=bin(A[i])[2:]
  
keta=[0]*60
for i in range(n):
  tar=binA[i]
  for j in range(len(tar)-1,-1,-1):
    if tar[j]=="1":
      keta[len(tar)-1-j]+=1

pair=[0]*60
for i in range(len(keta)):
  pair[i]=keta[i]*(len(A)-keta[i])
  
ans=0
mul=1
DIV=10**9+7
for i in range(len(pair)):
  ans+=pair[i]*mul
  ans%=DIV
  mul*=2
print(ans)

Solution (Python):


import sys


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)

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

mod = 10**9 + 7

ans = 0
for i in range(61):
    zero = 0
    one = 0
    for ai in a:
        if ai>>i & 1:
            one += 1
        else:
            zero += 1
    ans += zero * one * 2**i
    ans %= mod

print(ans)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
cnt=[[0]*60 for i in range(2)]
for a in A:
    for i in range(60):
        if(a&(1<<i)):
            cnt[1][i]+=1
        else:
            cnt[0][i]+=1
res=0
for i in range(60):
    x = pow(2,i)
    x%=1000000007
    res+=cnt[1][i]*cnt[0][i]*x
    res%=1000000007
print(res)

Solution (Python):

import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1






def sumXOR(arr,n):
    ans=0
    for i in range(61):
        zero=0
        one=0
        for ai in arr:
            if ai>>i & 1:
                one+=1
            else:
                zero+=1
        ans+=zero*one*2**i
        ans%=mod
    return ans
        



n = int(input()) 
arr = list(map(int,input().split()))
ans = sumXOR(arr, n); 
print (ans)

Solution (Python):

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

MOD = 10**9+7
tmp = max(A)
ans = 0
base = 1

while True:
    num1 = 0
    num0 = 0
    for i,a in enumerate(A):
        if (a%2 == 1):
            num1 += 1
        A[i] = a//2
    num0 = N-num1
    ans += num0 * num1 * base
    ans %= MOD
    
    base *= 2
    tmp //= 2
    if (tmp==0):break

print(ans)

Solution (Python):
mod = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
loop_count = len(format(max(A), "b"))

for i in range(loop_count):
    tmp = 0
    for ai in A:
        if ((1 << i) & ai) > 0:
            tmp += 1
    ans += (1 << i) * tmp * (N - tmp) % mod
print(ans % mod)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
ans=0
for i in range(64):
    x,y=0,0
    for j in a:
        if j>>i&1:
            y+=1
        else:
            x+=1
    ans+=x*y*(1<<i)
    ans%=10**9+7
print(ans)

Solution (Python):
N = int(input())
binary = [0]*60
for inp in input().split():
    inp = bin(int(inp))[2:][::-1]
    for j, _inp in enumerate(inp):
        if _inp == '1':
            binary[j] += 1
    
ret = 0
pow2 = 1
for elem in binary:
    if elem == 0 or elem == N:
        pass
    else: 
        mn = elem * (N - elem) % (10**9 + 7)
        ret += pow2 * mn 
        ret = ret % (10**9 + 7)
    pow2 = pow2 * 2 % (10**9 + 7)
print(ret)

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

mod = 10 ** 9 + 7
s = [0] * 60

for i in range(N):
    for j in range(60):
        if (A[i] >> j) & 1 == 1:
            s[j] += 1

ans = 0            
for i in range(60):
    ans += (((N - s[i]) * s[i]) << i) % mod
    ans %= mod
    
print(ans)

Solution (Python):
import numpy as np

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

ans = 0
for k in range(60):
  x = int(np.sum(A >> k & 1))
  ans += x * (N - x) * 2**k

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

Solution (Python):
import numpy as np

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

ans = 0
for k in range(60):
  x = int(np.count_nonzero(A >> k & 1))
  ans += x * (N - x) * 2**k

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

Solution (Python):
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split()))).reshape(n, 1)
mod = 10**9 + 7
bit = np.arange(64).reshape(1, 64)
b = np.sum((a >> bit) & 1, axis=0)
b *= n - b
b %= mod
b *= (1 << np.arange(64)) % mod
b %= mod
ans = 0
for x in b:
    ans += x
    ans %= mod

print(ans)

Solution (Python):
def bi(x):
    x = int(x)
    i = 0
    o = [0]*61
    while x > 0:
        o[i] = x % 2
        x //= 2
        i += 1
    return o

N = int(input())
A = list(map(bi,input().split()))


ruijoo = 1
bbb = 0
B = [0]*N
h = 0
while h < 61:
    i = 0
    isOne = 0
    while i < N:
        aaaa = A[i][h]
        isOne += aaaa
        B[i] = aaaa
        i += 1
    isZero = N - isOne
    bbb += ruijoo * isZero * isOne
    bbb %= 1000000007
    ruijoo *= 2
    ruijoo %= 1000000007
    h += 1

bbb %= 1000000007
print(bbb)

Solution (Python):
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)

Solution (Python):
n=int(input())
a=[int(j) for j in input().split()]
mod=10**9+7
m=len(bin(max(a)))-2
l=[[0,0] for i in range(m)]
for i in a:
    b=bin(i)[2:].rjust(m,"0")[::-1]
    for j in range(m):
        if b[j]=="0":
            l[j][0]+=1
        else:
            l[j][1]+=1

ans=0
for i in range(m):
    ans+=l[i][0]*l[i][1]*pow(2,i,mod)
    ans=ans%mod
print(ans)

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


def main():
    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)

if __name__ == '__main__':
    main()

Solution (Python):
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):
    
    
    
    ans += 2**(i)*s[i+1]*(n-s[i+1])
ans = ans % (10**9+7)
print(int(ans))

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

MOD = 10 ** 9 + 7

ans = 0
d = 1
for _ in range(60):
    x = 0
    for i in range(n):
        x += a[i] % 2
        a[i] //= 2
    ans = (((x * (n-x)) % MOD) * d % MOD + ans) % MOD
    d = d * 2 % MOD

print(ans)

Solution (Python):
from functools import reduce

words = lambda t : list(map(t, input().split()))
n = int(input())
xs = words(int)

def func(y, x):
    for i in range(60):
        if x == 0:
            continue
        y[i] += x & 1
        x = x >> 1
    return y

ys = reduce(func, xs, [0]*60)
ans = 0

for i,yi in enumerate(ys):
    ans += 2**(i) * yi * (n-yi)
    ans %= 10**9 + 7
print(ans)

Solution (Python):
words = lambda t : list(map(t, input().split()))
n = int(input())
xs = words(int)

ys = [0]*60
for x in xs:
    for i in range(60):
        if x == 0:
            continue
        ys[i] += x & 1
        x = x >> 1

ans = 0

for i,yi in enumerate(ys):
    ans += 2**(i) * yi * (n-yi)
    ans %= 10**9 + 7
print(ans)

Solution (Python):

"""
AtCoder Beginner Contest 147 D

https://atcoder.jp/contests/abc147/submissions/8876207
https://qiita.com/ZhangChaoran/items/0d59eb5c95cd9414801d


"""

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



bits = [0] * 60
for num in A:
    
    for i in range(60):
        
        if num & (1<<i):
            bits[i] += 1

"""
pは0からスタート
A_iについて、pビット目に1が立っていたら、i<jを満たすA_jのpビット目に0が立っている個数分2**pをプラスする
また、pビット目に0が立っていたら、i<jを満たすA_jのpビット目に1が立っている個数分2**pをプラスする
i,jのペアを見ていく時に、pビット目の1と0が何回出会うかを考えるとわかりやすいか
配列全体をみて、pビット目に1がa個ある場合、0はN-a個ある。これがΣΣのループで出会うので、
p桁目についてはa*(N-a)回2**pを答えに加えることになる
（a*(N-a)についてはあんまり腑に落ちてないが、例2とかで手を動かしてみるとそうなるので。）

これを全pに対して実施すると良い。
最後にmodを取ると値が大きすぎてあれなので、つどmodを取る
"""



ans = 0
for i, a in enumerate(bits):
    ans += a*(N-a) * 2**i
    ans %= MOD

print(ans)

Solution (Python):
import numpy as np

N = int(input())
arr = np.array([int(i) for i in input().split()])

ans = 0

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


print(ans%1000000007)

Solution (Python):
N=int(input())
A=list(map(int, input().split())) 
k =  len(bin(max(A))[2:])
A = [bin(i)[2:].zfill(k) for i in A]
mod = 10**9+7
ans = 0
for i in range(k):
  cnt = sum([1 for j in A if j[i]=='1'])
  ans += cnt*(N-cnt)*(2**(k-i-1))
  ans %= mod 
print(ans)

Solution (Python):
N=int(input())
A=list(map(int, input().split())) 
k =  len(bin(max(A))[2:])
A = [bin(i)[2:].zfill(k) for i in A]
mod = 10**9+7
ans = 0
for i in range(k):
  cnt = sum([1 for j in A if j[i]=='1'])
  ans += cnt*(N-cnt)*(2**(k-i-1))
  ans %= mod 
print(ans)

Solution (Python):
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)

Solution (Python):
N=int(input())
A=list(map(int, input().split())) 
k =  len(bin(max(A))[2:])
bit = [bin(i)[2:].zfill(k) for i in A]
mod = 10**9+7
ans = 0
for i in range(k):
  cnt = sum([1 for j in bit if j[i]=='1'])
  ans += cnt*(N-cnt)*(2**(k-i-1))
  ans %= mod  

print(ans)

Solution (Python):
N=int(input())
A=list(map(int, input().split())) 
k =  len(bin(max(A))[2:])
bit = [bin(i)[2:].zfill(k) for i in A]
mod = 10**9+7
c = [0]*k
ans = 0
for i in range(k):
  cnt = sum([1 for j in bit if j[i]=='1'])
  ans += cnt*(N-cnt)*(2**(k-i-1))
  ans %= mod  

print(ans)

Solution (Python):
def d_xor_sum_4(MOD=10**9 + 7):
    N = int(input())
    A = [int(i) for i in input().split()]

    ans = 0
    for d in range((len(bin(max(A))) - 2) + 1):
        nonzero = len([1 for a in A if (a >> d) & 1])
        ans += (2**d) * (nonzero) * (N - nonzero)
        ans %= MOD
    return ans

print(d_xor_sum_4())

Solution (Python):
MOD = 10**9+7
N = int(input())
A = [int(i) for i in input().split()]
max_length = len(bin(max(A)))-2
ans = 0
for n in range(max_length):
    c0 = 0
    c1 = 0
    for i, a in enumerate(A):
        if a & 1:
            c1 += 1
        else:
            c0 += 1
        A[i] >>= 1
    ans += c0*c1*(2**n)
    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):
  Po=sum([1 for j in A if j>>i & 1])
  Ans += Po*(N-Po)*(2**i)
  Ans = 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):
    ones = 0
    for j in range(N):
        if ((A[j] >> i) & 1):
            ones += 1
    ans += 2**i * ones * (N - ones) % MOD
    ans %= MOD

print(ans)

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

bit_count = [0] * 60
ans = 0
for a in A:
    for bit in range(60):
        if (a >> bit) & 1:
            count = bit_count[bit]
            ans += (2 ** bit) * (n-1-count*2)
            bit_count[bit] += 1
            ans %= mod
        else:
            continue

print(ans)

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

b = [0] * 60
for i in a:
    for j in range(60):
        b[j] += bool(i & (1 << j))

ans = 0
inf = int(1e9 + 7)
for i in range(60):
    ans += b[i] * (n - b[i]) * (1 << i) % inf
    ans %= inf
print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = [int(x) for x in readline().rstrip().split()]
B = [0] * 60
ans = 0
for i in range(N):
    i_bin = list(bin(A[i]))
    i_bin = i_bin[2:]
    i_bin = i_bin[::-1]
    k = 0
    for j in i_bin:
        if j == "1":
            B[k] += 1
        k += 1

for q in range(60):
    temp = B[q] * (N - B[q])
    ans += (temp % (7 + 10 ** 9)) * ((2 ** q) % (7 + 10 ** 9))
    ans %= 7 + 10 ** 9
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  one = [0]*62
  zero = [0]*62
  for number in a:
    for i in range(62):
      if number >> i &1 == 1:
        one[i] +=1
      else:
        zero[i] += 1
  ans = 0
  mod = 10**9+7
  for i in range(62):
    ans += one[i]*zero[i]*int(2**i)
    ans %= mod
  print(ans)
        
solve()

Solution (Python):
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  

N = ri()
A = np.array(rl())
answer = 0
MOD = 10 ** 9 + 7

for n in range(63):
    B = (A >> n) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    for _ in range(n):
        x *= 2
        x %= MOD
    answer += x

print(answer%MOD)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
md = 60
ans = 0
for d in range(md):
    cnt1 = sum([1 for i in a if ((i>>d)&1)]) 
    ans += cnt1 * (n-cnt1) * (1<<d)          
    ans %= mod                               

print(ans%mod)

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

for i in range(61):
    tmp_1 = 0
    tmp_0 = 0
    for k in range(N):
        if (A[k] >> i) & 1:
            tmp_1 += 1
        else:
            tmp_0 += 1
    
    ans += (tmp_1 * tmp_0) * (2 ** i)
print(ans%mod)