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 numpy as np

n=int(input())



a= list(map(int,input().split()))
a=np.array(a,np.int64)


max=60
mod=10**9+7
ans=0
cnt1=0
cnt0=0


for i in range(max):
    new_a=(a>>i & 1)

    cnt1=np.count_nonzero(new_a)
    cnt0=n-cnt1
    ans=(ans+cnt1*cnt0*(2**i))%mod
    cnt1=0
    cnt0=0
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
bin_a="".join(["{:060b}".format(a) for a in map(int, input().split())])
mod=10**9+7
xor=0
for d in range(60):
  ones=bin_a[59-d::60].count('1')
  xor+=2**d*ones*(N-ones)    
print(xor%mod)

Submission status: Accepted

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0]*60
    for a in A:
        for i in range(len(B)):
            if (a >> i) & 1:
                B[i] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += 2**i * b * (N-b)
        ans %= 10**9+7
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


n = 60
N = read_a_int()
A = read_ints()


def ret_binary(a: int):  # 逆順で返すことに注意
    ret_r = [0] * n
    for i in range(n):
        bit = a % 2
        a = a // 2
        ret_r[i] = bit
    return ret_r


MOD = 10**9 + 7

n_1_max = 0
n_1_ls = [0] * n
ans = 0
for a in A:
    tmp = ret_binary(a)
    for i in range(n):
        n_1_ls[i] += tmp[i]


for i, n_1 in enumerate(n_1_ls):
    num_sonoketa = n_1 * (N - n_1)
    ans += (((2**i) % MOD) * num_sonoketa)
    ans %= MOD
print(ans)

Submission status: Accepted

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0]*60
    for a in A:
        for i in range(len(B)):
            if (a >> i) & 1:
                B[i] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += 2**i * b * (N-b)
    ans %= 10**9+7
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0]*60
    for a in A:
        for i in range(len(B)):
            if a & (2**i):
                B[i] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += 2**i * b * (N-b)
    ans %= 10**9+7
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [sum(1 for a in A if a&(1<<i)) for i in range(60)]
  res = 0
  for i in range(60):
    res += ones[i] * (N - ones[i]) * ((2 ** i) % MOD)
    res %= MOD
  print(res)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
L = [0 for i in range(60)]
As = list(map(int, input().split()))
mod = 1000000007
ans = 0

for A in As:
    for i in range(60):
        if A >> i & 1 == 1:
            L[i] += 1

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

for i in range(60):
    tmp = tmps[i]
    a = L[i] % mod
    b = (N - a) % mod
    ans += (tmp * a * b) % mod

ans = ans % mod
print(ans)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


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 StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def sumXOR(arr,  n):
    _sum = 0
    for i in range(0, 64):
        zc = 0
        oc = 0

        # Individual sum at each bit position
        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

        # calculating individual bit sum
        idsum = oc * zc * (1 << i)

        # final sum
        _sum = _sum + idsum
        _sum %= MOD

    return _sum


def main():
    N = I()
    A = list(MI())
    print(sumXOR(A, len(A)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
# print(*A)

# print(bin(A[0]))
# print(format(A[0], "b"))
MOD = (10**9) +7
result = 0

cnt = [0] *60
for num in a:
    for j in range(60):
        cnt[j] += (num >> j) %2

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

print(ans)

Submission status: Accepted

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

d = [0 for k in range(61)]

for e in A:
    t = bin(e)[2:]
    for k in range(len(t)):
        if t[-k-1] == "1":
            d[k] += 1

MOD = 10**9 + 7
ans = 0
for k in range(61):
    ans += (2**k)*d[k]*(N-d[k])
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
import sys
import bisect
from math import ceil, floor, sqrt
readline = sys.stdin.buffer.readline
MOD = int(1e9 + 7)

def LL():
    return list(map(int, readline().split()))

n = int(readline())
A = LL()

counter = [0] * 60
ans = 0
for i in range(60):
    for v in A:
        counter[i] += (v >> i) & 1
    ans += pow(2, i, MOD) * (n - counter[i]) * counter[i]
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10 **9 + 7
 
ni = [0 for _ in range(60)]
for i in range(N):
    tmp = A[i]
    count = 0
    while(True):
        if tmp % 2 == 1:
            ni[count] += 1
        count += 1
        tmp = tmp // 2
        if tmp == 0:
            break
ans = 0
for j in range(60):
    ans += (ni[j] * (N-ni[j])) * 2 ** j 
 
print(ans%MOD)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    maxa = max(a)
    k = 0
    while 2 ** k <= maxa:
        k += 1
    mod = 10 ** 9 + 7
    mo2 = [1]
    for _ in range(k):
        mo2.append(mo2[-1] * 2)

    p = [[0, 0] for i in range(k)]
    for sa in a:
        for j in range(k):
            if mo2[j] & sa != 0:
                p[j][1] += 1
            else:
                p[j][0] += 1
    res = 0
    for i in range(k):
        res += (p[i][0] * p[i][1] * mo2[i]) % mod
    print(res % mod)


main()

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7
fac = [1]
caf = [1]


def pow(n, p):
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod


for i in range(1, 3):
    fac.append((fac[i - 1] * i) % mod)
    caf.append(pow(fac[i], mod - 2))


def main():
    n = int(input())
    a = list(map(int, input().split()))
    maxa = max(a)
    k = 0
    while 2 ** k <= maxa:
        k += 1
    mod = 10 ** 9 + 7
    mo2 = [1]
    for _ in range(k):
        mo2.append(mo2[-1] * 2)

    p = [[0, 0] for i in range(k)]
    for sa in a:
        for j in range(k):
            if mo2[j] & sa != 0:
                p[j][1] += 1
            else:
                p[j][0] += 1
    res = 0
    for i in range(k):
        res += (p[i][0] * p[i][1] * mo2[i]) % mod
    print(res % mod)


main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
mxbit = 0
for i in range(N):
  mxbit = max(mxbit, a[i].bit_length())
cs = [0] * mxbit
for i in range(N):
  for j in range(mxbit):
    t = 1 << j
    #print(a[i], t, a[i] & t)
    x = (a[i] & t) > 0
    cs[j] += x
res = 0
#print(cs[-1])
#print(cs)
for i in range(N):
  t = 0
  for j in range(mxbit):
    x = 1 << j
    if a[i] & x != 0:
      x %= mod
      #if i == 1: print((1 << j) * (N - i - 1), (cs[-1][j] - cs[i + 1][j]))
      t += x * (N - (cs[j]))
    else:
      x %= mod
      #if i == 1: print(a[i] & (1 << j), (cs[-1][j] - cs[i + 1][j]))
      t += x * cs[j]
    #print(t)
    t %= mod
  res += t
  res %= mod
print(res % mod * pow(2, mod - 2, mod) % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
a_ls = [bin(int(i))[2:].zfill(60)[::-1] for i in sys.stdin.readline().split()]
MOD = 10**9 + 7
#memo_ls[i][j] : 後ろからi番目まででj桁に1がある個数
memo_ls = [[0 for j in range(60)] for i in range(n+1)]
ct = {i : 0 for i in range(60)}
for i, a in enumerate(a_ls[::-1], 1):
    for j, k in enumerate(a):
        if k == "1":
            ct[j] += 1

res = 0
for i in range(60):
    res += ct[i] * (n - ct[i]) * 2 ** i
    res %= MOD
print(res)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
cnt = [[0,0] for i in range(61)]
for i in range(61):
    for j in range(N):
        if ((A[j] >> i) & 1):
            cnt[i][1] += 1
        else:
            cnt[i][0] += 1

ans = 0
for i in range(61):
    ans += (cnt[i][0] * cnt[i][1]) * (2**i)
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

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

answer = 0
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
answer %= MOD
print(answer)

Submission status: Accepted

Solution code:
import numpy as np

mod = 10 ** 9 + 7

N = int(input())
 
AList = np.array(input().split(), dtype=np.int64)
count = 0
for i in range(60):
    Plus = np.count_nonzero(AList >> i & 1)
    count += 2 ** i * (Plus * (N - Plus))
print(count % mod)

Submission status: Accepted

Solution code:
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = list(map(int, inputs[1].split()))
MOD = 10 ** 9 + 7

bit = len(format(max(A), 'b'))
ans = 0
for i in range(bit):
    nb_1 = sum(((a >> i) & 1 for a in A))
    ans += (nb_1 * (n - nb_1)) << i
    ans %= MOD
    
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ct0=[0]*64
ct1=[0]*64
for i in range(n):
  x=format(a[i],'0'+str(64)+'b')
  for j in range(64):
    if x[j]=='0':
      ct0[j]+=1
    else:
      ct1[j]+=1
ct0.reverse()
ct1.reverse()
ans=0
for i in range(64):
  x=(ct0[i]*ct1[i])%mod
  ans+=x*(2**i)
  ans%=mod
print(ans)

Submission status: Accepted

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

bits = [0] * 60
p = 10**9 + 7

for b in range(60):
  x = 1 << b
  for i in range(N):
    if A[i] & x:
      bits[b] += 1

ans = 0
for b in range(60):
  ans += (bits[b] * (N - bits[b])) * (1 << b)
  ans %= p

print(ans)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
l = list(map(int, input().split()))
u = 10**9+7
M = 61
ANS = 0

for i in range(M):
    d = 1 << i
    zero = 0
    for j in range(N):
        k = l[j]
        if (k & d)==0:
            zero += 1
    ANS += zero*(N-zero)*(2**i)
    ANS %= u
print(ANS)

Submission status: Accepted

Solution code:
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
s = 0
n = len(bin(max(A))[2:])
for i in range(n):
  b = 1<<i
  N_t = sum([1 for Ai in A if (b&Ai)>0])
  N_f = N-N_t
  s += (1<<i) * N_t * N_f
print(s%MOD)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    ls = [0] * 60
    t = 0
    for i in range(60):
        for v in a:
            ls[i] += (v >> i) & 1
        t += pow(2, i, mod) * (n - ls[i]) * ls[i]
        t %= mod
    print(t)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = int(input())
arrayOfNumber = list(map(int, input().split()))
MOD = 10**9+7
 
res = 0
for dig in range(61):
    one = 0
    for i in arrayOfNumber:
        if i & (1<<dig) != 0:
            one += 1
    res = (res + one*(n-one)*(1<<dig))%MOD
print(res)

Submission status: Accepted

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

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    mLEN = len(format(max(A),'b'))

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

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:
import numpy as np
mod = 10 ** 9 + 7

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

answer = 0
for d in range(61):
    x, r = x // 2, x % 2
    s = int(r.sum())
    b = (2 ** d) % mod
    answer += (b * s * (n - s)) % mod
print(answer%mod)

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

mod = 10**9 + 7
def solve(n, a):

    zero_count = [0] * 60
    for a_i in a:
        for j in range(60):
            if a_i >> j & 1:
                zero_count[j] += 1

    ans = 0
    for i, count in enumerate(zero_count):
        # ans += (2**i) * (count * (n - count)) 
        ans += pow(2, i, mod) * (count % mod) * ((n - count) % mod) 
        ans %= mod
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

Submission status: Accepted

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

res = 0
for dig in range(61):
    one = 0
    for i in a:
        if i & (1<<dig) != 0:
            one += 1
    res = (res + one*(n-one)*(1<<dig))%MOD
print(res)

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

mod = 10**9 + 7
def solve(n, a):

    zero_count = [0] * 60
    for a_i in a:
        for j in range(61):
            if a_i >> j & 1:
                zero_count[j] += 1

    ans = 0
    for i, count in enumerate(zero_count):
        # ans += (2**i) * (count * (n - count)) 
        ans += pow(2, i, mod) * (count % mod) * ((n - count) % mod) 
        ans %= mod
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A = list(map(int, input().split()))
A = np.array(A, dtype=np.int64)
ans = 0
mod = 10**9+7
i = 1
while i < (1 << 60):
    count = np.count_nonzero(A & i)
    ans += count * (N-count) * i
    ans %= mod
    i <<= 1
print(ans)

Submission status: Accepted

Solution code:

def sumXOR(arr,n): 
      
    sum = 0
    for i in range(0, 65): 
    
        #  Count of zeros and ones 
        zc = 0
        oc = 0
           
        # Individual sum at each bit position 
        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
          
           
        # calculating individual bit sum  
        idsum = oc * zc * (1 << i) 
    
        # final sum     
        sum = sum + idsum;  
      
    return sum%(1000000007)
  
  
  
# driver function  
sum = 0
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
sum = sumXOR(arr, n); 
print (sum)

Submission status: Accepted

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

def sumXOR(arr, n, MOD):
    s = 0
    for i in range(0, 62):
        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] //= 2
        idsum = oc * zc * (1 << i)
        idsum %= MOD
        s = s + idsum
        s %= MOD
    return s

print (sumXOR(A, N, 10**9 + 7))

Submission status: Accepted

Solution code:
import numpy as np
mod = 10 ** 9 + 7

if __name__ == "__main__":
	N = int(input())
	L = list(map(int, input().split()))
	L = np.array(L, np.int64)
	ans = 0
	for i in range(60):
		bit = np.count_nonzero(L & 1)
		ans += bit * (N - bit) * (2 ** i)
		ans %= mod
		L >>= 1
	print(ans % mod)

Submission status: Accepted

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

result = 0
base = 1
for _ in range(max_digit + 1):
  a = A % 2
  c = np.count_nonzero(a == 0)
  result = (result + (base*(N - c)*c) % mod) % mod
  A = A >> 1
  base *= 2

print(result)

Submission status: Accepted

Solution code:
#O(nm) = O(60n)で解けるはず・・・！
n = int(input())
l = list(map(int,input().split()))
#2進数の桁の出現数をカウントする。
lone = [0]*60
for i in range(n):
  s = bin(l[i])[2:]
  for j in range(len(s)):
    lone[j] += int(s[-j-1])
ans = 0
for i in range(60):
  ans += (2**i*lone[i]*(n-lone[i]))%(10**9+7)
print(ans%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 1000000007
N = int(input())
A = list(map(int,input().split()))
xorsum = 0
for i in range(64):
    zc = 0
    oc = 0
    for j in range(N):
        if A[j]%2 == 0:
            zc += 1
        else:
            oc += 1
        A[j] //= 2
    xorsum += oc*zc*(2**i)
    xorsum %= MOD
print(xorsum%MOD)

Submission status: Accepted

Solution code:
import sys
import numpy as np

read = sys.stdin.read

N, *A = map(int, read().split())
a = np.array(A, np.int64)
mod = 10 ** 9 + 7
answer = 0
for i in range(60):
    bit = np.count_nonzero(a & 1)
    answer += 2 ** i * bit * (N - bit)
    answer %= mod
    a >>= 1

print(answer)

Submission status: Accepted

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

def sumXOR(arr, n, MOD):
    ret = 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] //= 2
        idsum = oc * zc * (1 << i)
        ret += idsum
        ret %= MOD
    return ret

print(sumXOR(A, N, 10**9 + 7))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

mod = 10**9 + 7

def pow_r(x, n):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2) % mod
    else:
        return (x * pow_r(x ** 2, (n - 1) // 2)) % mod


def solve(n, a):

    zero_count = [0] * 60
    for a_i in a:
        # binary = format(a_i, '060b')
        # for j, b_j in enumerate(binary):
        #    zero_count[j] += int(b_j)
        for j in range(61):
            if a_i >> j & 1:
                zero_count[j] += 1

    ans = 0
    # for i, count in enumerate(zero_count[::-1]):
    for i, count in enumerate(zero_count):
        # ans += (2**i) * (count * (n - count)) 
        ans += pow_r(2, i) * (count % mod) * ((n - count) % mod) 
        ans %= mod
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())

def main():
    n = II()
    a_s = LI()
    kaizyo = [1]
    kaizyo_append = kaizyo.append
    keta = [0 for i in range(60)]
    ans = 0
    for i in range(60):
        kaizyo_append(kaizyo[i] * 2 % MOD)
    for i in a_s:
        for j in range(60):
            v, i = i % 2, i // 2
            keta[j] += v
    for i, v in enumerate(keta):
        c = v * (n-v) % MOD
        ans += c * kaizyo[i] % MOD
        ans = ans % MOD

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

Submission status: Accepted

Solution code:
import numpy as np
 
MAX_DIGIT = 60
MOD = 10**9 + 7
 
N = int(input())
A = np.array([int(a) for a in input().split()])
 
answer = 0
for d in range(MAX_DIGIT + 1):
    A, r = (A>>1), A % 2
    s = int(r.sum())
    base = (1<<d) % MOD
    answer += (base * s * (N - s)) % MOD
 
answer %= MOD
print(answer)

Submission status: Accepted

Solution code:
import numpy as np

MAX_DIGIT = 60
MOD = 10**9 + 7

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

answer = 0
for d in range(MAX_DIGIT + 1):
    A, r = (A>>1), A % 2
    s = int(r.sum())
    base = (1<<d) % MOD #this may be key
    answer += (base * s * (N - s)) % MOD

answer %= MOD
print(answer)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    ls = [0] * 65
    for v in a:
        tt = bin(v)
        for i in range(len(tt)-2):
            ls[i] += int(tt[-i-1])
    t = 0
    for i in range(len(ls)):
        t += pow(2, i, mod) * (n - ls[i]) * ls[i]
        t %= mod
    print(t)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

o = []

MOD = 10**9 + 7

for b in range(60):
    count = 0
    x = 2**b
    for i in range(n):
        if (a[i] & x) == 0:
            count += 1
    o.append(count)

sum = 0
for b in range(60):
    sum += (o[b] * (n - o[b])) * 2**b

print(sum % MOD)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    ls = [0] * 65
    for v in a:
        tt = bin(v)
        for i in range(len(tt)-2):
            ls[i] += int(tt[-i-1])
    t = 0
    for i in range(len(ls)):
        t += 2 ** i * (n - ls[i]) * ls[i]
        t %= mod
    print(t)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
MAXBIT = 60
MOD = 10 ** 9 + 7
A = list(map(int, input().split()))
B = []
C = [[] for _ in range(MAXBIT)]
for a in A:
    for d in range(MAXBIT):
        C[d].append(a >> d & 1)
ans = 0
for d in range(MAXBIT):
    num0 = C[d].count(0)
    num1 = N - num0
    ans += ((num0 * num1) % MOD) * pow(2, d, MOD)
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
def main():
    mod=1000000007
    n=int(input())
    A=list(map(int,input().split()))
    D=[0]*61
    for i in range(61):
        for a in A:
            if a>>i&1:
                D[i]+=1
    ans=0
    for i,d in enumerate(D):
        ans+=(pow(2,i,mod)*(d*(n-d)))
        ans%=mod
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = map(int, input().split())
mod = 10**9 + 7
p=[0] * 60
for a_ in a:
  for i in range(60):
    p[i] += (a_ >> i) & 1
ans = 0
for i in range(60):
  sn = (n - p[i]) * p[i]
  ans = (ans + (sn << i)) % mod
print(ans)

Submission status: Accepted

Solution code:
MOD = 1000000007

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

def sumXOR(arr,n):
    xorsum = 0
    for i in range(64):
        zc = 0
        oc = 0
        idsum = 0
        for j in range(n):
            if arr[j] % 2 == 0:
                zc += 1
            else:
                oc += 1
            arr[j] = arr[j]//2
        idsum = oc*zc*(1 << i)
        xorsum += idsum
        xorsum %= MOD
    return xorsum

XORSUM = 0
XORSUM = sumXOR(A,N);
print(XORSUM%MOD)

Submission status: Accepted

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

ans = 0
for i in range(61):
  c0 = 0
  c1 = 0
  for a in A:
    if (a>>i)&1 == 1:
      c1 += 1
    else:
      c0 += 1
  #print(c1,c0)
  ans += ((c0*c1)<<i)
  ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

a_b = []
for i in A:
    this_b = []
    this_a = i
    for j in range(59,-1,-1):
        j2 = 2**j
        if this_a >= j2:
            this_b.append(1)
            this_a -= j2
        else:
            this_b.append(0)
    a_b.append(this_b)
    
#print(a_b)

count_a_b = []
for i in range(60):
    count_a_b.append(0)

    
for i in a_b:
    for j in range(len(i)):
        count_a_b[j] += i[j]
#print(count_a_b)

count = 0
for i in range(len(count_a_b)):
    count += (count_a_b[i] * (N-count_a_b[i])) *2**(59-i)
    
print(count%(10**9+7))

Submission status: Accepted

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

cnt=[0]*60
p=10**9+7
for m in a:
    #b=bin(m)
    #l=len(b)-2
    #print(b)
    for i in range(60):
        if((m>>i) & 1):
            cnt[i]+=1
    #for i in range(l):
    #    cnt[i]+=int(b[-i-1])
    #kei=m
    #for i in range(100):
    #    cnt[i]+=kei%2
    #    kei//=2
    #    if(kei==0):
    #        break

#print(cnt)

lis=[]
jou=1
for i in range(60):
    lis.append(jou)
    jou*=2
    jou%=p

ans=0

for i in range(60):
    ans+=(lis[i]%p)*(cnt[i]%p)*((n-cnt[i])%p)
    ans%=p

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
q = 10 ** 9 + 7
ans = 0
cnt = [0] * 61
for i in range(N):
    b = bin(A[i])[2:].zfill(61)
    for i in range(61):
        if b[i] == '1':
            cnt[i] += 1
for num, c in enumerate(cnt[::-1]):
    zero = N - c
    ichi = c
    ans += zero * ichi * (2 ** num)
    ans = ans % q
print(ans % q)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int64)

X = (1 << np.arange(60, dtype=np.int64)) & A.reshape(-1,1)
B = np.sum(X != 0, axis=0)

total = 0

for i,count in enumerate(B):
  total += int(count) * int(N - count) * int(1 << i)

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

Submission status: Accepted

Solution code:
from itertools import accumulate
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
aa = list(accumulate(a))
aa = aa[::-1]
a.sort()
div = 10**9+7
ans=0

ls = [0]*60
for i in range(60):
    for j in a:
        if j&(1<<i):
            ls[i]+=1
        else:
            ls[i]-=1
    
for i in range(n-1):
    ans+=aa[i+1]
    for j in range(60):
        if a[i]&(1<<j):
            ls[j]-=1
            ans-=ls[j] * 2**j
        else:
            ls[j]+=1
    
    ans %= div

print(ans)