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:
n = int(input())
nums = list(map(int, input().split()))

res =0 
for i in range(60, -1, -1):
  zeros = 0
  ones = 0
  for x in nums:
    if x >> i & 1:
      ones += 1
    else:
      zeros += 1
  res += zeros*ones << i
print(res%(10**9+7))

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
ans=0
mod=10**9+7
for k in range(60):
    X=0
    Y=0
    for i in range(N):
        if A[i]^(2**k)>A[i]:
            X+=1
        else:
            Y+=1
    #print(X,Y)
    ans+=(pow(2,k,mod)*((X*Y)%mod))%mod
    ans%=mod
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
 
N = int(input())
A = np.fromiter(map(int, input().split()), np.int64)
 
result = 0
for bit in range(60):
    c = int((A & 1).sum())
    result = (result + c * (N - c) * (1 << bit)) % 1000000007
    A >>= 1
print(result)

Submission status: Accepted

Solution code:
N = int(input())
A = map(int, input().split())
ones = [0] * 60

for a in A:
    i = 0
    while (1 << i) <= a:
        ones[i] += ((a >> i) & 1)
        i += 1

ans = 0
mod = 10 ** 9 + 7

for idx, one in enumerate(ones):
    ans = (ans + one * (N - one) * (1 << idx)) % mod

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = map(int, input().split())
D = [[0, 0] for _ in range(60)]

for a in A:
    for i in range(60):
        if (a >> i) & 1:
            D[i][1] += 1
        else:
            D[i][0] += 1

ans = 0
mod = 10 ** 9 + 7

for idx, d in enumerate(D):
    ans = (ans + (d[0] * d[1] * (1 << idx))) % mod

print(ans)

Submission status: Accepted

Solution code:
def main():
    """"ここに今までのコード"""
 
n = int(input())
A = [int(a) for a in input().split()]
mod=10**9+7
 
ans=0
for i in range(60):
    l=sum([a%2 for a in A])
    ans=(ans+l*(n-l)*(2**i))%mod
    A=[a//2 for a in A]
    
 
#ans=xor[0]
#for j in range(60-1):
#    ans=((2*ans)+xor[j+1])%mod
print(int(ans)) 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import numpy as np
    n = int(input())
    a = np.array(list(map(int, input().split())), dtype=np.int64)
    l1 = [0]*61
    mod = 10**9+7
    #n = 300000
    #a = np.array([2**60-i for i in range(n)])
    for cnt in range(61):
        b = a % 2
        l1[cnt] = np.nonzero(b)[0].size
        a = a // 2
    l0 = [n-i for i in l1]
    ans = 0
    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:
#D問題

#ビットごとに考えられる
k=10**9+7

anslist=[]

n=int(input())
a=[format(int(i), '060b') for i in input().split()]
d=[]

for i in range(60):
    b=[j[59-i] for j in a]
    c=b.count("0")*b.count("1")
    d.append(c*2**(i)%k)
ans=0

for i in d:
    ans+=i
print(ans%k)

Submission status: Accepted

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

import numpy as np

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

k = [0] * 60

for j in range(60):
    l = a & 1
    k[j] = np.count_nonzero(l)
    a >>= 1

ans = 0
c = 0
for d in k:
    ans += (d * (n - d) * 2**c)  % (10**9 + 7)
    c += 1
    
print(ans % (10**9 + 7))

Submission status: Accepted

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

n = int(input())
a = np.asarray(list(map(int, input().split())))
ans = 0
bit = 1
for i in range(60):
  n_one = np.count_nonzero(a & 1)
  ans += n_one * (n - n_one) * bit
  a >>= 1
  bit *= 2
  ans %= mod
  bit %= mod
print(ans)

Submission status: Accepted

Solution code:
import cmath
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7


def main():
    N=int(input())
    a=list(map(int, input().split()))

    ans=0
    for b in range(60):
        c0=0
        c1=0
        for ai in a:
            if ai & (1<<b):
                c1+=1
            else:
                c0+=1

        ans+=(1<<b)*c0*c1
        ans%=MOD

    print(ans)


if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
#D - Xor Sum 4

import math
n=int(input())
al=list(map(int,input().split()))
a=['{:060b}'.format(x) for x in al]
a=''.join(a)
 
m=math.ceil(math.log(max(1,max(al)),2))
 
ans=0
for i in range(m):
  sum1=a[59-i::60].count('1')
  sum0=n-sum1
  ans+=2**i*sum1*sum0
 
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
import numpy as np

N = int(raw_input())
A = np.array(map(int, raw_input().split()))
B = map(lambda x: format(x, '060n'), A)
# A = map(lambda x: format(x, '060b'), A)
MOD = 10**9 + 7

count = dict()
for i in range(60):
    # zeros = len([a[i] for a in A if a[i] == '0'])
    zeros = np.count_nonzero((A>>i)&1)
    ones = N - zeros
    count[i] = zeros*ones

ans = 0
for i in count:
    ans = (ans + count[i] * pow(2,i,MOD)) % MOD

print ans

Submission status: Accepted

Solution code:
import numpy as np

N = int(raw_input())
A = np.array(map(int, raw_input().split()))
# A = map(lambda x: format(x, '060b'), A)
MOD = 10**9 + 7

count = dict()
for i in range(60):
    # zeros = len([a[i] for a in A if a[i] == '0'])
    zeros = np.count_nonzero((A>>i)&1)
    ones = N - zeros
    count[i] = zeros*ones

ans = 0
for i in count:
    ans = (ans + count[i] * pow(2,i,MOD)) % MOD

print ans

Submission status: Accepted

Solution code:
import numpy as np

N = int(raw_input())
A = np.array(map(int, raw_input().split()))
# A = map(lambda x: format(x, '060b'), A)
MOD = 10**9 + 7

count = dict()
for i in range(60):
    # zeros = len([a[i] for a in A if a[i] == '0'])
    zeros = np.count_nonzero((A>>i)&1)
    ones = N - zeros
    count[i] = zeros*ones

ans = 0
for i in count:
    ans = (ans + count[i]*pow(2,i)) % MOD

print ans

Submission status: Accepted

Solution code:
import numpy as np

N = int(raw_input())
A = np.array(map(int, raw_input().split()))
# A = map(lambda x: format(x, '060b'), A)
MOD = 10**9 + 7

count = dict()
for i in range(60):
    # zeros = len([a[i] for a in A if a[i] == '0'])
    zeros = np.count_nonzero((A>>i)&1)
    ones = N - zeros
    count[i] = zeros*ones

mod_val = dict()
curr = 1
for i in range(60):
    mod_val[i] = curr % MOD
    curr = (2*curr) % MOD

ans = 0
for i in count:
    ans = (ans + count[i]*mod_val[i]) % MOD

print ans

Submission status: Accepted

Solution code:
# D - Xor Sum 4

modulus = 10 ** 9 + 7
maxbits = 60

N = int(input())

def add_bits(n, vec):
    """配列vecに整数nの2進各桁を加える"""
    for i in range(len(vec)):
        if n & 1: vec[i] += 1
        n >>= 1

# 各数を2進数に変換したときの各桁の1の個数を求める
vec = [0] * maxbits
for a in map(int, input().split()):
    add_bits(a, vec)

# 2進各桁のXORの総和 (= 1の個数 * 0の個数) の総和
acc = sum(((n * (N - n)) << i) % modulus for i, n in enumerate(vec))

print(acc % modulus)

Submission status: Accepted

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

ans = 0

for bit in range(61):
    now = 0
    for x in a:
        if x&(1<<bit):now += 1

    ans += (2**bit)*(now*(n - now))
    ans %= mod


print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    tmp = A & 1
    A >>= 1
    x = np.count_nonzero(tmp)
    x *= n - x
    ans = (ans + pow(2, i, mod) * x) % mod
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())), np.int64)
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    tmp = (A >> i) & 1
    x = np.count_nonzero(tmp)
    x *= n - x
    ans = (ans + pow(2, i, mod) * x) % mod
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    tmp = (A >> i) & 1
    x = np.count_nonzero(tmp)
    x *= n - x
    ans = (ans + pow(2, i, mod) * x) % mod
print(ans)

Submission status: Accepted

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

#Aiを二進数として，各けたを見れば良い？1の個数*0の個数

ans =0
mod =pow(10,9)+7

#Aiは最大で2^60-1
Max = 61

 #i桁目を見る
for i in range(Max):
    count = 0#その桁での1の数
    for j in range(N):
        if(A[j]>>i & 1)==1:
            count+=1
    ans+=count*(N-count)*pow(2,i)
    ans = ans%mod
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

ans = 0
for i in range(64):
    tmp = (A >> i) & 1
    x = np.count_nonzero(tmp)
    x *= n - x
    ans += pow(2, i, mod) * x % mod

print(ans % mod)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(n) for n in input().split(' ')]
 
ans = 0
for i in range(60):
    x = 0
    for A_i in A:
        if A_i>>i&1:
            x += 1
    ans += x*(N-x)*2**i
ans = ans % (10**9+7)
print(ans)

Submission status: Accepted

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

n = int(input())
a = np.array(list(map(int, input().split())))
l = len(bin(max(a))) - 2

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

print(ans % MOD)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
a = np.array([int(x) for x in input().split(" ")], np.int64)
sum = 0
pow = 0
while any(a):
    one = np.count_nonzero(a & 1)
    sum += one * (N - one) * 2 ** pow
    sum %= (10 ** 9 + 7)
    pow += 1
    a >>= 1
print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

mod = 10 ** 9 + 7

res = 0
for d in range(60):
    one = sum(x & 1 for x in arr)
    res = (res + one * (n - one) * (1 << d)) % mod
    arr = [x >> 1 for x in arr]

print(res)

Submission status: Accepted

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

mod = 10 ** 9 + 7

res = 0
for d in range(60):
    one = sum(x & 1 for x in arr)
    res += one * (n - one) * (1 << d)
    res %= mod
    arr = [x >> 1 for x in arr]

print(res)

Submission status: Accepted

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

mod = 10 ** 9 + 7

res = 0
for d in range(60):
    one = sum(x % 2 == 1 for x in arr)
    res += one * (n - one) * 2 ** d
    res %= mod
    arr = [x // 2 for x in arr]

print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict

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

mod=10**9+7
ans=0
for keta in range(60):
    C=defaultdict(lambda: 0)     #0と1の出現回数をカウント
    temp_ans=0  #2進数での各桁のxorの和
    for i,a in enumerate(A):
        a=a>>keta&1
        if i==0:
            C[a]+=1
        else:
            if a==1:
                temp_ans+=C[0]  #aが1の場合は、xorを取ったら1になるのは0なので0の出現回数をカウント
            elif a==0:
                temp_ans+=C[1]  #aが0の場合は、xorを取ったら1になるのは1なので1の出現回数をカウント
            C[a]+=1
    ans+=pow(2,keta,mod)*temp_ans
    ans%=mod
print ans

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

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

wa = 0
kazu = 10**9 + 7
for i in range(60):
    b = int((a & 1).sum())
    wa = (wa + b*(n-b)*(1<<i)) % kazu
    a = a >> 1

print(wa)

Submission status: Accepted

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

wa = 0
kazu = 10**9 + 7
for i in range(60):
    b = 0
    for j in a:
        b += j & 1
    wa = (wa + b*(n-b)*(1<<i)) % kazu
    for j in range(n):
        a[j] = a[j] >> 1

print(wa)

Submission status: Accepted

Solution code:
import numpy as np
import math
n = int(input())
A = np.fromstring(input(),dtype=np.int64,sep=" ")
#rng = int(math.log2(np.max(A)))+1
sum = 0
d = 10**9+7
for bit in range(64):
    c = int((A & 1).sum())
    sum += c *(n-c)*(1<<bit)%d
    A = A>>1

print(sum %(d))

Submission status: Accepted

Solution code:
import numpy as np
 
 
def solve(string):
    n, *a = map(int, string.split())
    # a = ["{:060b}".format(_a) for _a in a]
    a = np.asarray(a, dtype=np.int64)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = int((a & 1).sum())
        a >>= 1
        # ans += s * (n - s) * pow(2, 59 - i, m)
        ans += s * (n - s) * pow(2, i, m) % m
        ans %= m
    return str(ans)
 
 
if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

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

ans = 0
for i in range(64):
    tmp = (A >> i) & 1
    #print(tmp)
    x = np.count_nonzero(tmp)
    x *= n - x
    ans += pow(2, i, mod) * x % mod

print(ans % mod)

Submission status: Accepted

Solution code:
import numpy as np 
N = int(input())
A = np.fromstring(input(), dtype = np.int64, sep = ' ')

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

print(res % 1000000007)

Submission status: Accepted

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

ans = 0
for i in range(64):
    tmp = (A >> i) & 1
    x = np.count_nonzero(tmp)
    x *= n - x
    ans += pow(2, i, mod) * x % mod

print(ans % mod)

Submission status: Accepted

Solution code:
N = int(input())
mod = 10 ** 9 + 7

A = [int(x) for x in input().split()]
ans = 0
for i in range(60):
    cnt = 0
    for a in A:
        cnt += a >> i & 1
    ans += cnt * (N - cnt) * (1 << i)
print(ans % mod)

Submission status: Accepted

Solution code:
def run():
  bit = 60
  N = int(input())
  a_li = list(map(int, input().split()))
  ans = 0
  dp = [[0]*bit for i in range(N)]
  for i in range(bit):
    dp[0][i] = (a_li[0] >> i) & 1
  for i in range(1, N):
    for j in range(bit):
      a_j = (a_li[i] >> j) & 1
      dp[i][j] = dp[i-1][j] + a_j
      ans += abs(a_j*i - dp[i-1][j]) << j
  print(ans%(10**9+7))

if __name__ == '__main__':
  run()

Submission status: Accepted

Solution code:
import math
import  numpy as np

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

ans = 0
a_max = max(a)

if a_max==0:alog=1
else:alog = int(math.log2(a_max))+1

for i in range(alog):
    p = pow(2, i)
    cnt = np.count_nonzero((a >> i)& 1 == 1)
    
    ans += cnt * (N - cnt)*(2**i)
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
As = np.array(list(map(int, input().split())))
modNum = 10**9 + 7
sum = 0
for d in range(60):
	n1 = np.count_nonzero((As >> d) & 1 == 1)
	sum += (2 ** d) * n1 * (N - n1)
print(sum % modNum)

Submission status: Accepted

Solution code:
def solve():
    import numpy as np
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N = int(f_i.readline())
    A = np.array(f_i.readline().split(), dtype=np.int64)
    
    ans = 0
    for i in range(60):
        cnt = np.count_nonzero((A >> i) & 1)
        ans += (1 << i) * cnt * (N - cnt)
    
    print(ans % mod)

solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def main():
    MOD = 10**9+7
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    count = [0] * 61
    ans = 0
    for a in A:
        for i, c in enumerate(format(a, 'b')[::-1]):
            if c == '1':
                count[i] += 1

    for i, c in enumerate(count):
        tmp = (c*(N-c) * pow(2, i, MOD))%MOD
        ans = (ans + tmp)%MOD
    print(ans)


if __name__ == '__main__':
    main()

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=0
    for d in range(60,-1,-1):
        k=sum((a>>d)&1 for a in A)
        ans+=(k*(n-k))<<d
        ans%=MOD

    print(ans)
resolve()

Submission status: Accepted

Solution code:
import math
n=int(input())
al=list(map(int,input().split()))
a=['{:060b}'.format(x) for x in al]
a=''.join(a)

m=math.ceil(math.log(max(1,max(al)),2))

ans=0
for i in range(m):
  sum1=a[59-i::60].count('1')
  sum0=n-sum1
  ans+=2**i*sum1*sum0

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

Submission status: Accepted

Solution code:
import sys


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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    a = np.asarray(a)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = int((a & 1).sum())
        a >>= 1
        ans += s * (n - s) * pow(2, i, m) % m
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
"""
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m, ans = 10**9 + 7, 0
    for s in map(lambda x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
"""
import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    # a = ["{:060b}".format(_a) for _a in a]
    a = np.asarray(a, dtype=np.int64)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = int((a & 1).sum())
        a >>= 1
        # ans += s * (n - s) * pow(2, 59 - i, m)
        ans += s * (n - s) * pow(2, i, m) % m
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
"""
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m, ans = 10**9 + 7, 0
    for s in map(lambda x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
"""
import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    # a = ["{:060b}".format(_a) for _a in a]
    a = np.asarray(a, dtype=np.int64)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = int((a & 1).sum())
        a >>= 1
        # ans += s * (n - s) * pow(2, 59 - i, m)
        ans = (ans + s * (n - s) * (1 << i)) % m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m, ans = 10**9 + 7, 0
    for c in zip(*a):
        s = c.count("1")
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m, ans = 10**9 + 7, 0
    for s in map(lambda x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    m = 10**9 + 7
    ans = 0
    for s in map(lambda x: x.count("1"), zip(*("{:060b}".format(_a) for _a in a))):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m = 10**9 + 7
    ans = 0
    for s in map(lambda x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
from itertools import starmap


def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for s in starmap(lambda *x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for s in map(lambda x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    *s, = map(lambda x: x.count("1"), zip(*a))
    for _s in s:
        ans <<= 1
        ans += _s * (n - _s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    *s, = map(lambda x: x.count("1"), zip(*a))
    for i, _s in enumerate(s):
        ans += _s * (n - _s) * pow(2, 59 - i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for i, d in enumerate(zip(*a)):
        # s = "".join(d).count("1")
        s = d.count("1")
        ans += s * (n - s) * pow(2, 59 - i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for d in zip(*a):
        ans <<= 1
        s = "".join(d).count("1")
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for i, d in enumerate(zip(*a)):
        s = "".join(d).count("1")
        ans += s * (n - s) * pow(2, 59 - i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
N = int(input())
A = [str(bin(a)).lstrip('0b').zfill(60) for a in map(int,input().split())]
A_rev = list(zip(*A))

ans = 0
for i, a in enumerate(A_rev):
	k = a.count('1')
	ans+=(k*(N-k)*2**(59-i))
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

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

    mod = 10 ** 9 + 7

    a_bin = [format(i, 'b') for i in a]

    m = len(max(a_bin, key = len))

    ans = 0

    for i in range(n):
        a_bin[i] = '0' * (m - len(a_bin[i])) + a_bin[i]

    for i in range(1, m+1):
        count = [0, 0]
        for j in a_bin:
            count[int(j[-i])] += 1
        ans += count[0] * count[1] * 2 ** (i-1)

    print(ans % mod)

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

    a = np.array(a)
    ans = 0
    mod = 10**9 + 7

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

    print(ans % mod)

if __name__ == '__main__':
    main2()

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
def solve(n, a, p=60):
    res, m = 0, 1
    for i in range(p):
        y = sum(x & m for x in a) // m
        res += y * (n-y) * m
        m *= 2
    return res % MOD

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

Submission status: Accepted

Solution code:
import numpy as np
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
A = np.array(A, dtype = np.int64)
tmp = 0
for i in range(61):
    tmp_1 = np.count_nonzero(A & 1)
    tmp += ((tmp_1)*(N - tmp_1)*(2**i)) % mod
    A = A >> 1
print(tmp % mod)

Submission status: Accepted

Solution code:
import numpy as np

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

mod = 10 ** 9 + 7
s = 0

for i in range(60):# Aは2の6乗より小さい
    c = np.count_nonzero(A & 1) # 最下位のbitで0じゃないものの個数
    s += 2 ** i * c * (N - c) # https://qiita.com/ZhangChaoran/items/0d59eb5c95cd9414801d
    A >>= 1 #　1bitずつ右にずらす。これを繰り返し続ける
print(s % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    A = list(map(int, input().split()))
    zeros = [0] * 60
    ones = [0] * 60
    for a in A:
        for i, c in enumerate(bin(a)[2:].zfill(60)):
            if c == '0':
                zeros[59 - i] += 1
            else:
                ones[59 - i] += 1
    ans = 0
    for i in range(60):
        ans += zeros[i] * ones[i] * (2 ** i)
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(raw_input())
l = [int(x) for x in raw_input().split()]
ret = 0
for bit in xrange(62):
  num = sum([(l[i] & (1 << bit)) > 0 for i in xrange(n)])
  ret += num * (n - num) * (1<<bit)
print ret % 1000000007

Submission status: Accepted

Solution code:
import numpy as np

MOD = 10 ** 9 + 7

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

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

ans %= MOD
print(ans)

Submission status: Accepted

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

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

print(s % mod)

Submission status: Accepted

Solution code:
n=int(input())
mod=10**9+7;ans=0
a=list(map(int,input().split()))
for i in range(61):
  checkbit=1 << i
  cnt=sum([1 for j in a if j & checkbit])
  ans+=checkbit*cnt*(n-cnt)
  ans%=mod
print(ans)

Submission status: Accepted

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

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

print(ans % MOD)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i] = str(bin(a[i]))

ans = [0] * 65
for i in a:
    for j in reversed(range(len(i))):
        if i[j] == '1':
            ans[-len(i)+j] += 1
        elif i[j] == '0':
            continue
        elif i[j] == 'b':
            break

tmp = 0
for i in range(len(ans)):
    tmp += 2 ** abs(i - 64) * (n - ans[i]) * ans[i]
    #print(i,2 ** abs(i - 64) * (n - ans[i]) * ans[i])
    tmp %= 10**9+7

print(tmp)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

mod = 10 ** 9 + 7

j_max = 0
cnt = [0] * 60
for i in range(n):
    for j in range(60):
        cnt[j] += a[i] % 2
        a[i] = a[i] // 2
        if a[i] == 0:
            j_max = max(j_max, j)
            break

ans = 0
for i in range(j_max + 1):
    ans = (ans + (2 ** i) * cnt[i] * (n - cnt[i])) % mod

print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8
MOD = 10 ** 9 + 7
n = int(input())
A = list(map(int, input().split()))
ans = 0
b = 1
for _ in range(60):
    sm = sum(a&b for a in A)
    sm //= b
    ans = (ans + sm * (n-sm) * b) % MOD
    b<<=1
print (ans)

Submission status: Accepted

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

for k in range(60):
    zero = 0
    one = 0
    for i in range(N):
        # A[i]のk桁目のbitが0か1か取り出す
        x = (A[i] >> k) & 1
        if x == 0: zero += 1
        else: one += 1
    ans += (2**k * (zero * one)) % mod

print(ans % mod)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
l=[0]*60
r=[0]*60
for i in range(n):
	x=format(a[i],'b').zfill(60)
	for j in range(60):
		if x[j]=='0':
			l[j]+=1
		else:
			r[j]+=1
#print(l,r)
ans=0
for i in range(60):
	ans+=l[i]*r[i]*(2**(59-i))
print(ans%(10**9+7))

Submission status: Accepted

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

s=0
for c in range(60):
  m=1<<c
  bc=len([1 for x in A if x&m])
  s+=bc*(N-bc)*m
  s%=10**9+7
  
print(s)