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).



Sample input:
3
1 2 3


Sample output:
6

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))

def main():
    N=I()
    A=LI()
    max_bit = 60
    BITs_1 = [0]*max_bit
    BITs_0 = [0]*max_bit
    ans = ModInt(0)
    for i,a in enumerate(A):
        for j in range(max_bit):
            if (1<<j)&a:
                ans += (1<<j)*BITs_0[j]
                BITs_1[j]+=1
            else:
                ans += (1<<j)*(BITs_1[j])
                BITs_0[j]+=1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    ones = [0 for _ in range(60)]
    for a in A:
        for i in range(60):
            if (a >> i) & 1:
                ones[i] += 1

    res_l = [0 for _ in range(60)]
    for a in A:
        for i in range(60):
            if (a >> i) & 1:
                res_l[i] += (N-ones[i])
            else:
                res_l[i] += ones[i]
    res = 0
    for i in range(60):
        res += res_l[i] << i
        res %= MOD
    if res % 2 == 1:
        res += MOD
    print(res // 2)
        
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
b = 2 ** 60
ret = 0
while b > 0:
    c0, c1 = 0, 0
    for ai in a:
        if ai & b != 0:
            c1 += 1
        else:
            c0 += 1
    ret = (ret + c1 * c0 * b) % mod
    b //= 2
print(ret)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
l=[format(i,"b").zfill(61) for i in l]
ans=0
MOD=10**9+7
la=[0 for i in range(61)]
for i in l:
    for num,j in enumerate(str(i)):
        if j=="1":
            la[60-num]+=1
for num,i in enumerate(la):
    ans+=2**num*i*(n-i)
    ans%=MOD
print(ans)

Submission status: Accepted

Solution code:
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
input = sys.stdin.readline
N  = int(input())
A = [int(i) for i in input().split()]
keta = [0] * 60
for i in range(N):
    a = 0
    while A[i] != 0:
        if A[i]%2 == 1:
            keta[a] += 1
        A[i] = A[i]//2
        a +=1
ans = 0
for i in range(60):
    ans += (N-keta[i])*keta[i]*(2**i)
    ans = ans%1000000007
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
MOD = 10**9 + 7

def sumXOR(arr, n): 
    sumation = 0
    for i in range(0, 64): 
        zc = 0
        oc = 0
        idsum = 0
        for j in range(0, n): 
            if (arr[j] % 2 == 0): 
                zc = zc + 1
            else: 
                oc = oc + 1
            arr[j] = arr[j] // 2
        idsum = oc * zc * (1 << i) 
        sumation = sumation + idsum
        sumation %= MOD
      
    return sumation
  
n = int(input())
a = [int(item) for item in input().split()]
  
print(sumXOR(a, n))

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
cnt=[0 for i in range(64)]
mask=1
for i in range(64):
    for j in a:
        if j|mask==j: #立っている
            cnt[i]+=1
    mask*=2
x=1
res=0
for i in range(64):
    res+=cnt[i]*(n-cnt[i])*x
    res%=1000000007
    x*=2
print(res)

Submission status: Accepted

Solution code:
def main():
    def accumulate(array):
        for i in range(len(array) - 1):
            array[i + 1] += array[i]
        return array

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

    X = [[0] * N for i in range(61)]
    for i, a in enumerate(A):
        for j in range(61):
            if (1 << j) & a:
                X[j][i] = 1

    for i in range(61):
        X[i] = accumulate(X[i])


    ans = 0
    for i, a in enumerate(A):
        for j in range(61):
            x = X[j][-1] - X[j][i]
            if (1 << j) & a:
                ans += ((1 << j) % MOD) * ((N - i - 1) - x)
                ans %= MOD

            else:
                ans += ((1 << j) % MOD) * x
                ans %= MOD


    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
bit = [[0,0] for i in range(60)]
b = []
ans = 0
mod = 10 ** 9 + 7
for i in a:
  for j in range(60):
    bit[j][i % 2] += 1
    i //= 2
for k,(z,o) in enumerate(bit):
  ans = (ans + (z * o) * (pow(2,k,mod))) % mod
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
d=[[0]*N for i in range(60)]
for i,a in enumerate(A):
    for j in range(60):
        d[j][i]=a%2
        a>>=1
m=10**9+7
r=0
for i in range(60):
    s=sum(d[i])
    r=(r+(N-s)*s*pow(2,i,m))%m
print(r%m)

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
Q = 10**9 + 7
def main():
    N = int( input())
    A = list( map( int, input().split()))
    T = [[0]*60 for _ in range(N)]
    P = [0]*60
    for i in range(N):
        a = A[i]
        for j in range(60):
            T[i][j] = a%2
            P[j] += a%2
            a //= 2
    ans = 0
    for i in range(60):
        plus = P[i]
        minus = N - plus
        ans = (ans + plus*minus%Q*pow(2,i,Q))%Q
    print(ans)
        
if __name__ == '__main__':
    main()

Submission status: Accepted

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

# p[n]: 最下位ビットからnビット目が1になっている数字の個数
p=[0] * 60
for a in A:
  for i in range(60):
    p[i] += (a>>i)&1

#print(p)
ans = 0
for i in range(60):
  # nビット目同士を足したときの合計
  sn = (N-p[i]) * p[i]
  ans = (ans + (sn << i)) % MOD

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

cnt = [0]*65

for e in a:
    for i in range(65):
        if (e>>i)&1 == 1:
            cnt[i] += 1

res = 0
p = 1

for e in cnt:
    res = (res+p*e*(n-e)%mod)%mod
    p = p*2%mod

print(res)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
Abi = ["0" * 60 + bin(a)[2:] for a in A]

ans = 0
for i in range(60):
    N1 = sum([1 for a in Abi if a[-(i + 1)] == '1'])
    ans = (ans + (2 ** i) * N1 * (N - N1)) % MOD

print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
INF=10**9+7
ans=0
for i in range(60):
    o=0
    for j in range(n):
        if a_list[j]%2==0:
            o+=1
        a_list[j]=a_list[j]>>1
    t=o*(n-o)
    ans=(ans+t*2**i)%INF
print(ans)

Submission status: Accepted

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

mod = 10**9+7
resl = [0] * 60
for i in a:
    for j in range(60):
        if i & 1 > 0:
            resl[j]+=1
        i = i >> 1
        if i == 0:
            break

result = 0
for i in range(60):
    result = (result + 2**i * resl[i] * (n-resl[i])) % mod
print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[1]:


N = int(input())
A = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7


# In[2]:


count = [0] * 60
for i in range(N):
#     s = format(A[i], '060b')
#     for d in range(60):
#         count[d] += int(s[d])
    for j in range(60):
        count[j] += A[i] % 2
        A[i] //= 2


# In[ ]:





# In[3]:


ans = 0
for d in range(60):
    ans = (ans + count[d] * (N - count[d]) * 2 ** (d)) % MOD


# In[4]:


print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
A = [format(Ai, 'b') for Ai in A]
L = max(len(Ai) for Ai in A)
A = ['0'*(L-len(Ai))+Ai for Ai in A]
ans = 0

for i in range(L):
    one, zero = 0, 0
    
    for j in range(N):
        if A[j][i]=='1':
            one += 1
        else:
            zero += 1
    
    add = pow(2, L-i-1, MOD)*one*zero%MOD
    ans += add
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
  tmp = bin(a[i])[2:]
  tmp = '0' * (64-len(tmp)) + tmp
  b.append(tmp)
ans = 0
bit = 1
mod = 10 ** 9 + 7
for k in range(64):
  z1 = 0
  for i in range(n):
    if b[i][-k-1] == '1':
      z1 += 1
  add = z1 * (n-z1) * bit
  add %= mod
  ans += add
  ans %= mod
  bit *= 2
  bit %= mod
  #print(z1,add,ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
C1 = [0 for i in range(60)]
C0 = [0 for i in range(60)]

V = list(map(int, input().split()))
for n in V:
    i = 0
    for i in range(60):
        if (n % 2 == 1):
            C1[i] += 1
        else:
            C0[i] += 1
        n //= 2
MOD = int(pow(10, 9) + 7)
total = 0;
for i in range(60):
    total += pow(2, i) * C1[i] * C0[i]
    total %= MOD
print(total)

Submission status: Accepted

Solution code:
import sys
import heapq
import bisect
 
mod = 10**9+7
 
def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(list(sys.stdin.readline())[:-1])
 
def main():
    N = I()
    A = LI()
    ans = 0
    count = [0]*62

    for i in range(62):
        mask = 1<<i
        for a in A:
            if a&mask:
                count[i]+=1

    for i in range(62):
        ans += (count[i] * (N-count[i]))*(1<<i)%mod
        ans %= mod


    return(ans)
 
if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

x = 1
ans = 0
for i in range(60):
    num1s = 0
    for a in As:
        if a & x:
            num1s += 1
    ans += (x % MOD) * num1s * (N - num1s)
    ans %= MOD
    x <<= 1
print(ans)

Submission status: Accepted

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

l = 60

ones = [0] * l
for i in range(n):
    b = bin(a[i])[2:].zfill(l)
    for j in range(l):
        if b[j] == '1':
            ones[j] += 1


ans = 0
for i in range(l):
    ans += ones[i] * (n - ones[i]) * 2 ** (l - i - 1)
    ans = ans % (10 ** 9 + 7)
print(ans)

Submission status: Accepted

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

bt = [0]*60

ans = 0

for j in range(60):
    for i in range(n):
        s = a[i]
        if((s>>j) & 1):
            ans += (i-bt[j])*(2**j)
            ans %= mod
            bt[j] += 1
        else:
            ans += bt[j]*(2**j)
            ans %= mod

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
al = list(map(int,input().split()))

bit = [0] * 62

for a in al:
    for i in range(62):
        bit[i] += (a % 2)
        a = a // 2

ans = 0
p = 1
for i in range(62):
    ans += bit[i] * (n - bit[i]) * p
    ans %= 10**9 + 7
    p *= 2

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N = int(input())
A = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

dp = [0] * 62
for a in A :
    for i in range(62) :
        if a & (1 << i) :
            dp[i] += 1

ret = 0
for i in range(62) :
    ret += (N * (N - 1) - (N - dp[i]) * (N - dp[i] - 1)) // 2 * (1 << i) % mod
    ret -= dp[i] * (dp[i] - 1) // 2 * (1 << i) % mod
    ret %= mod

print(ret)

Submission status: Accepted

Solution code:
n = int(input())
one = [0 for i in range(70)]
zero = [n for i in range(70)]
for c in input().split():
  b = list(bin(int(c)))
  b.reverse()
  j = 0
  for i in b:
    if i == "b":
      break
    else:
      if i == '1':
        one[j] += 1
        zero[j] -= 1
    j += 1
ans = 0
mod = 10 ** 9 + 7

for j in range(70):
  ans += one[j] * zero[j] * 2 ** j
  ans %= mod
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

#B = [bin(a)[2:].zfill(61)[::-1] for a in A]
N1 = []
for i in range(0,61):
    m = sum([a % 2 for a in A])
    N1.append(m)
    for j in range(N):
        A[j] = A[j] >> 1

ans = 0
for i,n1 in enumerate(N1):
    n0 = N-n1
    m = n0 * n1
    ans += 2**i * m
    ans = ans % MOD
print(ans % MOD)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    ans=(n-1)*sum(A)
    ans%=MOD

    for d in range(60,-1,-1):
        cnt=sum((a>>d)&1 for a in A)
        k=cnt*(cnt-1)
        ans-=k<<d
        ans%=MOD
    print(ans)
resolve()

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    l1=[0]*61
    for i in a:
        j=list(reversed(bin(i)[2:]))
        for k in range(len(j)):
            if j[k]=="1":
                l1[k]+=1
    l0=[n-i for i in l1]
    ans=0
    mod=10**9+7
    for i in range(len(l1)):
        ans=(ans+l0[i]*l1[i]*pow(2,i,mod))%mod
    print(ans)
main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
P = 10**9+7
ans = 0
for i in range(60):
    s = sum([a>>i & 1 for a in A])
    ans += s * (N-s) << i
    ans %= P

print(ans)

Submission status: Accepted

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	D0 = defaultdict(int)
	D1 = defaultdict(int)
	for i in range(N):
		a = A[i]
		for j in range(61):
			if a % 2 == 0:
				D0[j] += 1
			else:
				D1[j] += 1
			a = int(a // 2)

	ans = 0
	for i in range(61):
		ans += (D0[i] * D1[i] * (2 ** i)) % con

	ans = ans % con
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque
from operator import itemgetter
from heapq import heappop, heappush
input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7

N = int(input())
A = sorted(inpl())
DP = [0]*60
B = [pow(2, i, MOD) for i in range(60)]

for i in range(N):
    a = A[i]*1
    
    for j in range(60):
        DP[j] += a&1
        a //= 2

ans = 0
for i in range(N):
    a = A[i] * 1
    for j in range(60):
        DP[j] -= a&1
        if a&1:
            ans = (ans + B[j]*(N-1-i-DP[j]))%MOD
        else:
            ans = (ans + B[j]*(DP[j]))
        a //= 2

print(ans%MOD)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=[0]*60
m=10**9+7
for i in a:
    t=bin(i)[2:][::-1]
    for i in range(len(t)):
        if t[i]=="1":
            s[i]+=1
c=0
for i in range(60):
    c=(c+s[i]*(n-s[i])*pow(2,i,m))%m
print(c)

Submission status: Accepted

Solution code:
def examD(mod):
    N = I(); A = LI()
    d = defaultdict(int)
    for i in range(N):
        cur = A[i]
        j = 1
        while(cur>0):
            if cur&1==1:
                d[j] +=1
            j +=1
            cur >>=1
    ans = 0
    for i,j in d.items():
        ans += j*(N-j) * 2**(i-1)
        ans %=mod
    print(ans)
    return

def examE():
    return

def examF():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examD(mod)

Submission status: Accepted

Solution code:
def main():
    n = input()
    aa = map(int, raw_input().split())
    mod = 10 ** 9 + 7 
    s = 0
    for i in xrange(60):
        c0 = 0
        c1 = 0
        mask = 1 << i
        for a in aa:
            if a & mask:
                c1 += 1
            else:
                c0 += 1
        s = (s + 2 ** i * c0 * c1) % mod
    print s


main()

Submission status: Accepted

Solution code:

N = int(input())

A = list(map(int,input().split()))
ans = 0

for i in range(61):

    z = 0
    o = 0
    now = 2 ** i

    for j in A:

        if j & now == 0:
            z += 1
        else:
            o += 1

    ans += now * (z * o)
    ans %= 10 ** 9 + 7

print (ans)

Submission status: Accepted

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

ans = 0
A.sort()
M = len(bin(A[-1])) - 2

p = 1
for i in range(M):
  z = 0
  t = 1 << i
  for j in range(N):
    if A[j] & t == 0:
      z += 1
  o = N - z
  ans = (ans + z * o * p) % MOD
  p *= 2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mo = 10 ** 9 + 7
b = [0] * 64
for j in range(64):
	for i in range(n):
		if a[i] & (1 << j):
			b[j] += 1
ans = 0
for j in range(64):
	ans += b[j] * (n - b[j]) * (2 ** j)
print(ans % mo)

Submission status: Accepted

Solution code:
import math

n=int(input())
alist = [int(i) for i in input().split()]
alist=sorted(alist)

keta=math.floor(math.log(max(alist[-1],1), 2))+1
zeros=[0]*keta
ones=[0]*keta

for al in alist:
    kaz2=bin(al)[2:]
    kaz2=(keta-len(kaz2))*'0'+kaz2
    for i in range(keta):
        if kaz2[i]=='1':
            ones[i]+=1
        else:
            zeros[i]+=1

answer=0
for i in range(keta):
    tas=ones[-i-1]*zeros[-i-1]
    tas*=((2**i)%(10**9+7))
    answer+=tas%(10**9+7)

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

Submission status: Accepted

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

m = max(A).bit_length()
cnt = 0
k = 1
for i in range(m):
    s = sum((v >> i) & 1 for v in A)
    cnt += s*(N-s)*k
    cnt %= MOD

    k *= 2
    k %= MOD

print(cnt)

Submission status: Accepted

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

mod = 10**9+7

m = 62
d = [0]*m

ans = 0
for i in range(n):
    ai = a[i]
    for j in range(m):
        # 1
        if ai&(1<<j):
            ans += (1<<j)*(i-d[j])
            d[j] += 1
        # 0
        else:
            ans += (1<<j)*d[j]
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

mod = 10**9+7

ans = 0
for i in range(60):
    p = 0
    q = 0
    for a in A:
        if a & (1<<i):
            p += 1
        else:
            q += 1
    ans = (ans + ((1<<i) %mod * p * q) % mod) % mod
print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

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

ans = 0

C = [0]*61
for a in A:
    for idx in range(61):
        if (1<<idx) & a:
            C[idx] += 1

for i in range(61):
    ans = (ans + (1<<i)*C[i]*(N-C[i]))%MOD
print(ans)

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

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

A = np.array(A, dtype=int)
ans = 0

d = 1
while d < (1 << 60):
    cnt = np.count_nonzero(A & d)
    ans += (N - cnt) * cnt * d
    ans %= MOD
    d <<= 1
print(ans)

Submission status: Accepted

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

ans = 0
for d in range(60):
    zero = 0
    one = 0
    for a in A:
        if ((1 << d) & a) != 0:
            one += 1
        else:
            zero += 1

    ans += one * zero * (1 << d)
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
def p_d():
    n = int(input())
    *A, = map(int, input().split())
    mod = 10 ** 9 + 7
    max_bit = len(bin(max(A))) - 2
    ans = 0
    for i in range(max_bit):
        count = [0] * 2
        for a in A:
            count[a >> i & 1] += 1
        ans += (1 << i) * count[0] * count[1]
        ans %= mod
    print(ans)
    
p_d()

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3

M = 64
P = 10 ** 9 + 7


def solve(n, xs):
    su = 0
    for i in range(M):
        zc = 0
        oc = 0
        idsu = 0
        for j in range(n):
            if xs[j] % 2 == 0:
                zc += 1
            else:
                oc += 1
            xs[j] //= 2
        idsu = oc * zc * (1 << i)
        su += idsu
        su %= P
    return su


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    res = solve(n, xs)
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
A = III()

for i in range(N):
    A[i] = str(format(A[i],'b')).zfill(60)

ans = 0
for i in range(60):
    zc = 0
    oc = 0
    for j in range(N):
        if A[j][59-i]=='0':
            zc += 1
        else:
            oc += 1
    ans += 2**i*zc*oc
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

ANS=0

for keta in range(61):
    ZERO=0
    ONE=0

    for a in A:
        if a & (1<<keta)!=0:
            ONE+=1
        else:
            ZERO+=1

    ANS=(ANS+ONE*ZERO*(1<<keta))%mod

print(ANS)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
B = [0] * 61

for i in range(n):
    b = list(format(A[i], "b").zfill(61))
    for j in range(61):
        if b[j] == "1":
            B[j] += 1

mod=10**9+7
M2 = [1]
for i in range(70):
    M2.append((M2[-1] * 2) % mod)

# print(B)
ans = 0
for i in range(61):
    p = (B[i] * (n-B[i]) * M2[61-i-1]) % mod
    ans = (ans+p) % mod
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = 61
ans = 0
mod = 10**9+7
for i in range(M):
    b = 1<<i
    cnt = 0
    for a in A:
        if (a>>i)&1:
            cnt+=1
    ans+=b*(N-cnt)*cnt
    ans%=mod
print(ans)

Submission status: Accepted

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

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

ans = 0
for j in range(60):
    ans += cnt[j] * (n - cnt[j]) * (2**j)
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
import sys

def get(x,n):
    return ((1<<x)&(n))!=0


def main():
    mod=1000000000+7
    n=int(sys.stdin.readline())
    a=list(map(int,sys.stdin.readline().split()))
    ans=0
    cur=1
    for x in range(60):
        res=get(x,a[-1])
        now=res
        nnow=not res
        total=0
        for i in range(n-2,-1,-1):
            res=get(x,a[i])
            now+=res
            nnow+=not res
            if res:
                total+=nnow
            else:
                total+=now
        ans+=cur*total
        ans%=mod
        cur*=2
    print(ans%mod)
main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    m = 61
    d = [0]*m
    ans = 0
    p = [pow(2,j,mod) for j in range(m)]
    for i in range(n):
        ai = a[i]
        for j in range(m):
            if ai&(1<<j):
                ans += (i-d[j])*p[j]%mod
                ans %= mod
                d[j] += 1
            else:
                ans += d[j]*p[j]%mod
                ans %= mod
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

ans = 0
for keta in range(61):
    now = 0
    for x in a:
        if x&(1<<keta):
            now += 1
    ans += (now*(n-now))*2**keta
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
MOD=10**9+7 
def sumXOR( arr, n): 
	sum = 0
	for i in range(0, 75): 
		zc = 0
		oc = 0
		idsum = 0
		for j in range(0, n): 
			if (arr[j] % 2 == 0): 
				zc = zc + 1
			else: 
				oc = oc + 1
			arr[j] >>=1 
		idsum = (oc * zc * pow(2,i,MOD))%MOD
		sum = sum%MOD + idsum; 
		sum%=MOD 
	return sum%MOD 
n=int(input())
arr=[int(i) for i in input().split()]
MOD=10**9+7 
print(sumXOR(arr,n)%MOD)

Submission status: Accepted

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

MOD = 10 ** 9 + 7
ans = 0
m = 1
for _ in range(60):
    bit = sum(a & m for a in aaa)
    bit //= m
    non_bit = n - bit
    ans = (ans + bit * non_bit * m) % MOD
    m <<= 1
print(ans)

Submission status: Accepted

Solution code:

# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines

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

ans = 0

MOD = (10**9+7)
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 %= MOD


print(ans)

Submission status: Runtime Error

Solution 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)