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:
#!/usr/bin/env python3
import sys
from itertools import chain, count

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    a_max = max(A)
    ans = 0
    for i in count(0):
        mask = 2**i
        if mask > a_max:
            return ans
        c0 = 0
        c1 = 0
        for a in A:
            if a & mask:
                c1 += 1
            else:
                c0 += 1
        mask = mask % MOD
        ans = (ans + mask*(c0 * c1)) % MOD 

def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(N, A)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
C = 10**9+7
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    L = [(A[j] >> i) & 1 for j in range(N)]
    # print(L)
    a = L.count(0)
    b = L.count(1)
    ans += a*b*pow(2, i, C)
print(ans % C)

Submission status: Accepted

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

mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    ones = 0
    for a in A:
        # 数列Aの全要素の(二進法表記の)i桁目の１の数を集計する
        if a & (1 << i):
            ones += 1
    # Aの要素から任意の2つを選んで排他的論理和をとってできた数列をBとすると、
    # 数列Bの全要素のi桁目の合計は、(Aのi桁目の１の数)*(0の数)となる
    # 選んだ２つのAの要素が(0,1)の組み合わせになっている場合(XOR)だけに、Bの桁を構成する要素になるため
    ans = (ans + ones * (N - ones) * (1 << i)) % mod

print(ans)

Submission status: Accepted

Solution code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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(len(bin(max(A)))):   # 最大桁数は、最も大きい数値の2進数の桁数
    num_1 = np.count_nonzero((A >> n)&1)   # 1の数をカウント
    num_0 = N - num_1                      # 0の数をカウント
    mul = num_1 * num_0   # 0 XOR 1の回数
    ans += ((2 ** n)*mul) % mod
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
mod=10**9+7
n=int(sys.stdin.buffer.readline())
a=np.fromstring(sys.stdin.buffer.readline(),dtype=np.int64,sep=' ')
ans=0
b=1
for i in range(60):
    s=int((a&1).sum())
    ans=(ans+s*(n-s)*b)%mod
    a>>=1
    b=b*2%mod
print(ans)

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        if k<0 or n<k:
            return 0
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

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

N,A=ilint()
ans=0
beki2=[2**(59-i) for i in range(60)]
S=[0]*60
B=list(map(lambda x:bin(x)[2:].zfill(60),A))

def f(x):
    global S
    for i in range(60):
        S[i]+=int(x[i])

f(B[N-1])
for i in range(N-2,-1,-1):
    for j in range(60):
        ans += beki2[j]*S[j] if B[i][j]=='0' else beki2[j]*(N-1-i-S[j])
        ans %= MOD
    f(B[i])
    
print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    for i in range(60):
        one = 0
        for a in A:
            if a & (1 << i):
                one += 1
        ans = (ans + one * (N - one) * (1 << i)) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())

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

ans=0
mod = 10**9 +7
for i in range(60):
  cnt = np.count_nonzero(A&1)
  ans+=(N-cnt)*cnt*(2**i)
  ans %= mod
  A>>= 1
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

x=[0]*61

for i in range(61):
  for j in a:
    if (j>>i)%2==1:
      x[i]+=1


for i in a:
  for j in range(61):
    if (i>>j)%2==1:
      ans+=(n-x[j])*(2**j)


print(ans%mod)

Submission status: Accepted

Solution code:
# ABC 147 D

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

bits=[0]*71
for a in A:
    j=0
    while a>>j:
        if (a>>j)&1:
            bits[j]+=1
        j+=1

t=0
n=70
while n>=0:
    if bits[n]!=0:
        break
    n-=1

for a in A:
    j=0
    while j<=n:
        if (a>>j)&1:
            res+=((2**j)*(N-bits[j]))%p
        else:
            res+=((2**j)*bits[j])%p
        j+=1
    t=res
print((res*500000004)%p)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    ans = 0
    p = 1
    for _ in range(60):
        n = 0
        for i in range(N):
            if A[i] % 2:
                n += 1
            A[i] //= 2
        ans = (ans + n * (N - n) * p) % MOD
        p = p * 2 % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
n,*a = map(int,open(0).read().split())
a = np.array(a)
mod = 10**9+7
ans = 0
for i in range(61):
  b = np.count_nonzero(a>>i&1)
  ans += b*(n-b)*1<<i
print(ans%mod)

Submission status: Accepted

Solution code:
import queue
import numpy as np
import math

n = int(input())
A = list(map(int, input().split()))
A = np.array(A,np.int64)
ans = 0

for i in range(60 + 1):
    a = (A >> i) & 1
    count1 = np.count_nonzero(a)
    count0 = len(A) - count1
    ans += count1*count0 * pow(2, i)
    ans%=1000000007

print(ans)

Submission status: Accepted

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

count = 0

max = A[-1]
if max == 0:
	print(0)
	exit()

import math
V = [0]*(math.floor(math.log(max, 2))+1)

for i in range (0, N):
	B = A[i]
	vount = 0
	while B > 0:
		if B%2 == 0:
			B = B//2
			vount+=1			
		else:
			B = (B-1)//2
			V[vount]+=1
			vount+=1

for i in range (0, len(V)):
	count+=((V[i]*(N-V[i]))*(2**i))

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

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
bit = [0] * 60
MOD = 10 ** 9 + 7
for a in A:
    i = 0
    waru = 1
    while a > 0:
        if a % (waru * 2) != 0:
            a -= waru
            bit[i] += 1
        waru *= 2
        i += 1
answer = 0
for i, b in enumerate(bit):
    answer += (2 ** i) * (b * (N-b))
print(answer % 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(60):
  keta=1<<i
  cnt=0
  for j in a:
    if keta & j:
      cnt+=1
  ans+=((keta%mod)*cnt*(n-cnt))%mod


print(ans%mod)

Submission status: Accepted

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

ones = [0]*60
ans = 0
for i in range(n):
    x = l[i]
    for j in range(60):
        ones[j] += (x>>j)&1
    ans = (ans + (n-1)*x)%mod
# print(ans)

for i in range(60):
    ans = (ans - ones[i]*(ones[i]-1)*2**i)%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
two = 1
for i in range(61):
    one = np.count_nonzero(a & 1)
    a = a >> 1
    ans = (ans + (one*(n-one))*two) % mod
    two = (two * 2) % mod
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''
import numpy as np
n=int(input())
a = np.array([int(i) for i in input().split()])

ans=0
for i in range(60):
    cnt=np.count_nonzero(a&1)
    ans+=(n-cnt)*cnt*(2**i)
    if ans>=10**9+7:
        ans%=(10**9+7)
    a>>=1
print(ans)

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    M=65
    A=LI()
    cnt=[0]*M
    
    for i in range(N):
        a=A[i]
        for j in range(M):
            if a>>j & 1:
                cnt[j]+=1
                
    ans=0
    for i in range(M):
        a=cnt[i]
        b=N-a
        ans=(ans + a*b*pow(2,i,mod))%mod
        
    print(ans)
                

main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
d=1
for i in range(61):
  s=0
  for j in a:
    s+=(j>>i)&1
  ans+=s*(n-s)*d%mod
  ans%=mod
  d*=2
  d%=mod
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

ans=0
M=pow(10,9)+7
for i in range(100):
  one=int(np.sum((A>>i)&1))
  zero=N-one
  ans+=(one*zero)*pow(2,i)
  ans%=M
  #print(one,zero)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

ans=0
M=pow(10,9)+7
for i in range(100):
  one=int(np.sum((A>>i)&1))
  zero=N-one
  ans+=(one*zero)*pow(2,i,M)
  ans%=M
  #print(one,zero)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

ans=0
M=pow(10,9)+7
for i in range(100):
  one=np.sum((A>>i)&1)
  zero=N-one
  ans+=(one*zero)%M*pow(2,i,M)%M
  ans%=M
  #print(one,zero)
print(ans)

Submission status: Accepted

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

ans=0
for i in range(60):
  one=sum([a>>i&1 for a in A])
  zero=N-one
  ans+=(one*zero)*pow(2,i,M)%M
  ans%=M
  #print(one,zero)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
M=10**9+7
#A=[int(x) for x in input().split()]
A=list(map(int,input().split()))

ans=0
for i in range(60):
  one=sum([a>>i&1 for a in A])
  zero=N-one
  ans+=(one*zero)*2**i
  ans%=M
  #print(one,zero)
print(ans)

Submission status: Accepted

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

ans=p=0
for i in range(60):
  one=sum([a>>p&1 for a in A])
  zero=N-one
  p+=1
  ans+=(one*zero)*2**i
  ans%=M
  #print(one,zero)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
res = 0
n = 0
quot = (10 ** 9) + 7
while 1:
  p = 0
  q = 0
  temp = 0
  for i, var in enumerate(A):
    if var % 2 == 1:
      p += 1
    else:
      q += 1
    A[i] = A[i] >> 1
    temp += var
  
  if temp == 0:
    break
  res += p*q*(2**n)
  res %= quot
  n += 1
print(res)

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):
    cnt0 = 0
    cnt1 = 0
    for a in A:
        if (a>>i) & 1 == 0:
            cnt0 += 1
        else:
            cnt1 += 1
    ans += cnt0 * cnt1 * (2 ** i)
    ans %= mod

print(ans)

Submission status: Accepted

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

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

b = 1
ans = 0
for i in range(m):
    ans += b*xor_num[i]*(n-xor_num[i])
    b *= 2
    b %= mod
print(ans%mod)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
P = int(1e9+7)
max_log_2 = 60
k_zyo=[0] * max_log_2
k_2=[1]*max_log_2
for i in range(1, max_log_2):
    k_2[i] = k_2[i-1]*2
for a in A:
    for i in range(max_log_2):
        k_zyo[i] += (a // (k_2[i])) % 2

ans = 0
for a in A:
    for i in range(max_log_2):
        if (a // (k_2[i])) % 2 == 0:
            ans = (ans + k_zyo[i] * k_2[i]) % P
print(ans)

Submission status: Accepted

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


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


MOD = 10 ** 9 + 7


def main():
    N = II()
    targets = LI()

    ttl_bins = [0]*60
    for i in range(N):
        target = targets[i]
        target_str = format(target, f"0{60}b")
        for keta in range(60):
            ttl_bins[keta] += int(target_str[keta])

    ans = 0
    for i in range(60):
        ttl = ttl_bins[i] * (N - ttl_bins[i])
        ans += pow(2, 59-i, MOD) * ttl
        ans %= MOD

    print(ans)


main()

Submission status: Accepted

Solution code:

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

    ans = 0
    for i in range(60):
        p = 1 << i
        one = sum([1 for a in A if a & p])
        zero = N - one
        ans += p * one * zero
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

a_bin=[]

for i in a:
    a_bin.append(format(i, '#062b')[2:])



def get_keta_num(keta,a_list):
    zero=0
    one=0
    for i in a_list:
        if i[-keta]=="0":
            zero+=1
        else:
            one+=1
    return zero*one

ans=0
for i in range(1,61):
    ans+=(2**(i-1))*get_keta_num(i,a_bin)
    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
S0 = [0 for i in range(60)]
S1 = [0 for i in range(60)]
for i in range(N):
  for j in range(60):
    if A[i] % 2  == 0:
      S0[j] += 1
    else:
      S1[j] += 1
    A[i] //= 2
ans = 0
c = 1
for j in range(60):
  ans = (ans + S0[j] * S1[j] * c) % mod
  c *= 2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
num_one_for_digit = [0]*61
for i in range(N):
    b = bin(A[i])[2:].zfill(61)
    for d in range(61):
        if b[d] == "1":
            num_one_for_digit[d] += 1
ans = 0
t = 1
for d in range(60, -1, -1):
    n_1 = num_one_for_digit[d]
    ans += n_1 * (N - n_1) * t % MOD
    ans %= MOD
    t *= 2
print(ans%MOD)

Submission status: Accepted

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

ans=0
cnt=[0 for i in range(61)]

for i in range(n):
    now=A[i]
    bek=1
    for q in range(61):
        if now&1==0:
            ans+=cnt[q]*bek
        else:
            ans+=(i-cnt[q])*bek
        bek=bek*2%mod
        cnt[q]+=now&1
        now>>=1
    ans=ans%mod
    #print(ans)
print(ans)

Submission status: Accepted

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

n = int(sys.stdin.buffer.readline())
a = np.fromstring(sys.stdin.buffer.readline(), dtype = np.int64, sep = ' ')
ans = 0
for i in range(60):
    s = int((a&1).sum())
    ans += s*(n-s) * 2**i
    ans %= MOD
    a >>= 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    ans = 0
    L = 100
    for l in range(L):
        one = 0
        zero = 0
        for a in A:
            if (a & (1<<(L - l - 1))):
                one += 1
            else:
                zero += 1
        ans += (one * zero) * 2 ** (L - l - 1)
        ans %= MOD

    print(ans)
    


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
mod = 10**9+7
n = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
zero = defaultdict(int)
one = defaultdict(int)
for a in A:
    for i in range(61):
        if a &(1<<i):
            one[i] += 1
        else:
            zero[i] += 1
ans = 0
for i in range(61):
    ans += pow(2,i,mod)*zero[i]*one[i]
    ans %=mod

print(ans%mod)

Submission status: Accepted

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

mod = 10**9 + 7

pows = [pow(2, i, mod) for i in range(60)]
count = [0]*60
num = [0]*60
ans = 0

for i in range(n):
    bit = a[i]
    for g in range(60):
        if bit % 2 == 1:
            count[g] += 1
            num[g] += i+1 - count[g]
        else:
            num[g] += count[g]
        bit //= 2

for i in range(60):
    ans += num[i]*pows[i]

print(ans % mod)

Submission status: Accepted

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

mod = 10**9 + 7

pows = [pow(2, i, mod) for i in range(60)]
count = [0]*60

for i in range(n):
    bit = a[i]
    for g in range(60):
        count[g] += bit%2
        bit //= 2
        if bit == 0:
            break

ans = 0
num = [0]*60

for i in range(n):
    bit = a[i]
    for g in range(60):
        if bit % 2 == 1:
            num[g] += n - count[g]
        else:
            num[g] += count[g]
        bit //= 2

for i in range(60):
    ans += num[i]*pows[i]

print(ans//2 % mod)

Submission status: Accepted

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

bit_l=[0 for _ in range(60)]

for x in a:
  for i in range(60):
    if ((x>>i)&1):
      bit_l[i]+=1
ans=0
mod=10**9+7
for y in range(len(bit_l)):
  r=2**y
  k=(n-bit_l[y])*bit_l[y]
  ans+=r*k%mod
  
print(ans%mod)

Submission status: Accepted

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

ans = 0
M = 10**9 + 7
for i in range(60):
  c0 = 0
  c1 = 0
  m = 1 << i
  for a in A:
    if a & m == 0:
      c0 += 1
    else:
      c1 += 1
  ans += (c0 * c1) * m
  ans %= M
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
keta_0=[0]*70
keta_1=[0]*70
for shift in range(70):
    for i in range(n):
        if a[i]>>shift & 1:
            keta_1[shift]+=1
        else:
            keta_0[shift]+=1
ans=0

for i in range(70):
    ans+=2**i*keta_0[i]*keta_1[i]
    ans%=10**9+7

print(ans)

Submission status: Accepted

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

c = [0]*100
for i in a:
    b = format(i,'b')[::-1]
    for x in range(len(b)):
        c[x] += int(b[x])

ans = 0
mod = 10**9+7
for i in range(100):
    ans += c[i]*(n-c[i])*2**i
    ans %= mod

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):
    x, y = 0, 0
    for a in A:
        x += 1 & a >> k
    tmp = x * (n - x) % mod
    tmp *= 2**k%mod
    ans += tmp
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))

    mod = 10**9+7
    ans = 0

    for k in range(60):
        x, y = 0, 0
        for a in A:
            x += 1 & a>>k
        tmp = x*(n-x)%mod
        tmp *= pow(2, k, mod)
        ans += tmp
        ans %= mod
    print(ans)


if __name__ =='__main__':
    main()

Submission status: Accepted

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

mod = 10**9 + 7
ans = 0
# 制約より、aはそれぞれ60桁以内で表せる
# i+1(=1,2,...,60)桁目についてそれぞれ考える
for i in range(60):
    k = 1 << i  # k = 100....00(2) = 2**i(10)
    cnt_1 = 0
    cnt_0 = 0

    for ai in a:
        if k & ai:
            cnt_1 += 1
        else:
            cnt_0 += 1
    # 1 XOR 0 = 1 となる個数 = cnt_1 * cnt_0
    # 桁が違うのでk(== 2**0, 2**1, 2**2,...)をかける必要がある
    ans += ((k % mod) * cnt_1 * cnt_0) % mod

print(ans % mod)

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

def bit(S, j):
    # Sの右からj bit目(0-indexed)
    return (S>>j)&1

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

B = [0 for i in range(61)]
for i in range(61):
    for j in range(N):
        B[i] += bit(A[j], i)

for i in range(61):
    B[i] = B[i]*(N-B[i]) % mod

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

print(ans % mod)

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    k = sum(a >> i & 1 for a in a_list)
    ans += (k * (n - k) % mod) * ((1 << i) % mod) % mod
print (ans % mod)

Submission status: Accepted

Solution code:
import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

import numpy as np

def Main():
    n = read_int()
    a = np.array(read_int_list(), np.int64)
    ans = 0
    for i in range(60):
        cnt_one = np.count_nonzero(a >> i & 1)
        cnt_zero = n - cnt_one
        ans += (cnt_one * cnt_zero * (1 << i)) % MOD
        ans %= MOD
    print(ans)
    

if __name__ ==  '__main__':
    Main()

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

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

Submission status: Accepted

Solution code:
mod = 10**9 + 7
N = int(input())
A = [int(i) for i in input().split()]
# bitにしてor
# 一桁だけの時、111000なら3 * 3
maxl = 0
textlist = []
for i in range(N):
    tmp = str(bin(A[i]))
    tmp = tmp[2:]
    length = len(tmp)
    if maxl < length:
        maxl = length
    textlist.append(tmp)
zeros = {}
ones = {}
for i in range(maxl):
    zeros[i] = 0
    ones[i] = 0

for i in range(N):
    tmp = textlist[i]
    length = len(tmp)
    if maxl < length:
        maxl = length
    for j in range(length):
        if tmp[-j-1]== '1':
            ones[j] += 1
for i in range(maxl):
    zeros[i] = N-ones[i]

result = 0
n2 = 1
for i in range(maxl):
    result = (result + n2 * (zeros[i] * ones[i])) % mod
    n2  = (n2 * 2) % mod
print(result)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = 0
    m = 10**9 + 7
    
    for i in range(60):
        x = 0
        for j in l:
            x += 1 & j >> i
        
        tmp = x * (N - x) % m
        tmp *= 2 ** i % m
        ans += tmp
        ans %= m

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input())
    A = [int(x) for x in input().split()]
    ans = 0
    mod = 10 ** 9 + 7
    # 制約がai <= 2^60なので
    for d in range(61):
        # d桁目ごとに考える
        x = 0
        for a in A:
            if (a >> d) & 1:
                x += 1
        ans += x * (n-x) * 2**d
        ans %= mod
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    ans = 0
    mod = 10 ** 9 + 7
    for d in range(60):
        # d桁目ごとに考える
        x = 0
        for a in A:
            if (a >> d) & 1:
                x += 1
        ans += x * (n-x) * 2**d
        ans %= mod
    print(ans)
 
if __name__ == '__main__':
    main()

Submission status: Accepted

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

B=[[] for i in range(n)]
for i in range(n):
    B[i]= [((A[i]>>(59-j))) & 1 for j in range(60)]
    B[i] = [0]*(60-len(B[i]))+B[i]

TB=[[0]*n for i in range(60)]
for i in range(60):
    TB[i] = [B[j][i] for j in range(n)]
        
# import numpy as np
#print(TB)
ans=0
for i in range(60):
    now=TB[i]
    q=sum(now)
    
    ans+= ((pow(2,59-i,mod)* (q*(n-q)))%mod)%mod
    ans%=mod


print((ans)%mod)

Submission status: Accepted

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

c = [n]*61
for i in range(n):
    b = str(bin(a[i]))[2:]
    b = b[::-1]
    for j, x in enumerate(b):
        if x == "1":
            c[j] -= 1

ans = 0
for i in range(60):
    ans += c[i]*(n-c[i])*pow(2,i,mod)
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:

MOD = 10 ** 9 + 7
MAX = 60

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

cnt = [0 for i in range(MAX)]
for i in range(n):
    bit = bin(a[i])[2:].zfill(MAX)
    for j in range(MAX):
        cnt[j] += int(bit[j])

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(60):
    cnt = 0
    digit = 1 << i
    for j in a:
        if digit & j:
            cnt += 1
    ans += digit*cnt*(n - cnt)%mod

print(ans%mod)

Submission status: Accepted

Solution code:
import os
import sys
import numpy as np

def solve(A, N):
    mod = 10**9+7
    C = [0] * 60
    for a in A:
        for i in range(60):
            if a>>i&1:
                C[i] += 1
    ans = 0
    for i, c in enumerate(C):
        ans += (1<<i) % mod * c % mod * (N-c) % mod
    return ans % mod

# >>> numba compile >>>
numba_config = [
    [solve, "i8(i8[:],i8)"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
    from numba import njit
    from numba.pycc import CC
    cc = CC("my_module")
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature)(func)
        cc.export(func.__name__, signature)(func)
    cc.compile()
    exit()
elif os.name == "posix":
    exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
    from numba import njit
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature, cache=True)(func)
    print("compiled!", file=sys.stderr)
# <<< numba compile <<<

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