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 pypy3

import sys
import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from fractions import gcd                    # for Python3.4.3


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = lmi()
    m = max(a)
    # corner case: all numbers are equal to zero
    if m == 0:
        print(0)
        exit(0)

    ans = 0
    for shift in range(int(math.log(m, 2)+1)):    # log2 は PyPy2.4.0 で使えない
        mask = 0b1 << shift
        # print(tuple(map(lambda x: (x&mask)>>shift, a)))
        count_one = tuple(map(lambda x: (x&mask)>>shift, a)).count(1)
        ans = (ans + int(pow(2, shift, mod)) * count_one * (n - count_one)) % mod
        # print(ans)
    print(ans)
    # TLE -> random_31 to random_35 system test cases


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

n = int(readline())
a = np.array(read().split(), np.int64)
ans = 0
mod = 10 ** 9 + 7
for i in range(63):
    b = (a >> i) & 1
    x = np.count_nonzero(b)
    y = n - x
    x *= y
    for j in range(i):
        x *= 2
        x %= mod
    ans += x
print(ans % mod)

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):
    one = np.count_nonzero(a >> i & 1)
    zero = n - one
    ans += one * zero * 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
m = 1

for i in range(60):
    #mbit目に情報を持つものをすべて足し合わせる。
    #m = 1: 1bit目（2^0の位）、m=10: 2bit目（2^1の位）
    #sum = sigma(1の数 * 2^(m-1))
    one = sum(a_e & m for a_e in a)
    one //= m
    zero = n - one
    ans += one * zero * m
    ans %= MOD
    
    m <<= 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mod = 10**9+7
ans = 0
for i in range(60):
    cnt = 0
    for j in range(n):
        if a[j]>>i & 1 == 0: cnt += 1
    ans += pow(2,i,mod)*cnt*(n-cnt)
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
m = max(a)
x = 0
while m > 0:
    m >>= 1
    x += 1 

for i in range(x):
    cnt = 0
    for j in range(n):
        if a[j]>>i & 1 == 0: cnt += 1
    ans = (ans+pow(2,i,mod)*cnt%mod*(n-cnt)%mod)%mod
    
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())))
ans=0
for i in range(60):
  b=np.count_nonzero(A>>i&1)
  ans+=(2**i)*b*(N-b)
  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 i in range(60):
    c = sum([1 for ai in a if (ai >> i) & 1])
    ans += (1 << i) * c * (n-c)
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = [0 for i in range(62)]
for i in range(n):
    b = bin(a[i])
    for i in range(len(b)-2):
        if b[-1-i] == '1':
            x[-i-1] += 1
mod = 10**9+7
ans = 0
two = 1
for i in range(1,62):
    ans = (ans + x[-i]*(n-x[-i])*two)%mod
    two = two*2%mod
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    for i in range(60):
        cnt = 0
        for j in a:
            if (j>>i) & 1:
                cnt += 1
        res += ((cnt*(n-cnt))*2**i) % mod
    print(res%mod)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby
#from itertools import product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
#from operator import itemgetter

#inf = 10**17
mod = 10**9 + 7

n = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(60):
    cnt = 0
    for j in a:
        if (j>>i) & 1:
            cnt += 1
    res += ((cnt*(n-cnt))*2**i) % mod
print(res%mod)

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
digit = 0

while A.any():
    one = np.count_nonzero(A & 1)
    ans += (one * (N - one) * pow(2, digit, MOD))
    ans %= MOD
    A >>= 1
    digit += 1

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
digit = 0

while A.any():
    one = np.count_nonzero(A & 1)
    ans += (one * (N - one) * pow(2, digit, MOD)) % MOD
    ans %= MOD
    A >>= 1
    digit += 1

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 digit in range(60):
    one = np.count_nonzero(A & 1)
    ans += (one * (N - one) * pow(2, digit, MOD)) % MOD
    ans %= MOD
    A >>= 1

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

max_digit = len(bin(max(A))) - 2

for digit in range(max_digit):
    one = np.count_nonzero((A >> digit) & 1)
    ans += (one * (N - one) * pow(2, digit, MOD)) % MOD
    ans %= 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 digit in range(60):
    one = np.count_nonzero((A >> digit) & 1)
    ans += (one * (N - one) * pow(2, digit, MOD)) % MOD
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
mod=10**9+7
N=int(input())
A = list(map(int,input().split()))
B=[0]*N
for i in range(N):
 B[i]=str(bin(A[i]))
f=0
for i in range(2,62):
 d=0
 e=0
 for j in range(N):
  g=62-len(B[j])
  if i<g:
   e+=1
  elif B[j][i-g]=="1":
   d+=1
  else:
   e+=1
 f+=(d*e*pow(2,61-i,mod))%mod
 f%=mod
print(f)

Submission status: Accepted

Solution code:
mod=10**9+7
N=int(input())
A = list(map(int,input().split()))
B=[0]*N
for i in range(N):
 B[i]=str(bin(A[i])).rjust(62,"0")
f=0
for i in range(2,62):
 d=0
 e=0
 for j in range(N):
  if B[j][i]=="1":
   d+=1
  else:
   e+=1
 f+=(d*e*pow(2,61-i,mod))%mod
 f%=mod
print(f)

Submission status: Accepted

Solution code:
mod=10**9+7
N=int(input())
A = list(map(int,input().split()))
B=[0]*N
for i in range(N):
 B[i]=str(bin(A[i])).rjust(62,"0")
f=0
for i in range(2,62):
 d=0
 e=0
 for j in range(N):
  c=B[j]
  if c[i]=="1":
   d+=1
  else:
   e+=1
 f+=(d*e*pow(2,61-i,mod))%mod
 f%=mod
print(f)

Submission status: Accepted

Solution code:
mod=10**9+7
N=int(input())
A = list(map(int,input().split()))
B=[0]*N
for i in range(N):
 B[i]=str(bin(A[i])).rjust(62,"0")
f=0
for i in range(2,62):
 d=0
 e=0
 for j in range(N):
  c=B[j]
  if c[i]=="1":
   d+=1
  else:
   e+=1
 f+=d*e*pow(2,61-i,mod)
 f%=mod
print(f)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
ans=0
cnt0=[0]*60
cnt1=[0]*60
mod=10**9+7
tp=[0]*60
for i in range(60):
  tp[i]=(1<<i)%mod
for i in range(60):
    x=1<<i
    one=sum(1 for j in a if j&x)
    ans+=tp[i]*one*(n-one)
print(ans%mod)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
cnt0=[0]*60
cnt1=[0]*60
mod=10**9+7
tp=[0]*60
for i in range(60):
  tp[i]=(1<<i)%mod
for i in range(60):
    x=1<<i
    one=sum(1 for j in a if j&x)
    ans+=tp[i]*one*(n-one)
print(ans%mod)

Submission status: Accepted

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N = ir()
A = np.array(lr(), np.int64)
answer = 0
limit = int(A.max()).bit_length()
for i in range(limit):
    B = (A >> i) & 1
    x = np.count_nonzero(B)
    y = N - x
    add = (x*y) * 2 ** i % MOD
    answer += add

print(answer%MOD)

Submission status: Accepted

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N = ir()
A = lr()
bit = [0 for _ in range(60)]
for a in A:
    for i in range(a.bit_length()):
        if (a >> i) & 1:
            bit[i] += 1

answer = 0
for i, x in enumerate(bit):
    answer += x * (N-x) * 2 ** i

print(answer%MOD)
# 22

Submission status: Accepted

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

def myinput():
    return map(int,readline().split())

n = int(readline())
a = list(myinput())
mod = 10**9 + 7
ans = 0

for j in range(60):
    k = 2**j
    one = 0
    zero = 0
    for i in range(n):
        if (a[i]&k)!=0:
            one += 1
        else:
            zero += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**j) 
    ans %= mod   

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

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

p = 10**9+7
ans = 0
for i in range(60):
    x = 1<<i
    one = sum(1 for j in a if j&x)
    ans += pow(2,i,p)*one*(n-one)

print(ans%p)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
 
one_count = [0] * 61
for v in a:
  count = 0
  while v != 0:
    if v % 2 == 1:
      one_count[count] += 1
      
    count += 1
    v //= 2
  
 
ans = 0
for i in range(len(one_count)):
  ans += (one_count[i] * (n - one_count[i]) * (2 ** i))
  ans %= MOD
  
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
B=[format(a,'b').zfill(60) for a in A]
mod=pow(10,9)+7
answer=0
for i in range(60):
    zero=0
    one=0
    kotae=1
    for j in B:
        if j[i]=='0':
            zero+=1
        elif j[i]=='1':
            one+=1
    kotae=zero*one
    for _ in range(60-i-1):
        kotae*=2
    answer+=kotae
print(answer%mod)

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):
    cnt = np.count_nonzero((A >> i) & 1)
    ans += (2**i * cnt*(N-cnt)) % MOD
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
if max(a)==0:
  print(0)
  exit()
m=math.floor(math.log(max(a),2))+1
ans=0
for i in range(m):
  cnt0=0
  cnt1=0
  for j in range(n):
    if a[j]>>i&1:
      cnt1+=1
    else:
      cnt0+=1
  ans+=(2**i)*(cnt1*cnt0)
  ans%=mod
print(ans)

Submission status: Accepted

Solution code:
mod=10**9+7
N=int(input())
str_a = ''.join(['{:060b}'.format(a) for a in map(int, input().split())])

ans=0
for i in range(60):
    ones=str_a[59-i::60].count("1")
    ans+= pow( 2, i ,mod)* ones *(N-ones)
print(ans%mod)

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 bit in range(60):
   cnt=np.count_nonzero(a>>bit&1)
   ans += 2**bit * cnt * (n - cnt)
   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
N=int(input())
A=np.array(list(map(int, input().split())))


mod = 10**9+7
ans = 0
#bitの60桁を見ていく
#桁ごとに分割して足していく
for i in range(60):
  #i桁目が1である要素数　N-b1はi桁目が0である要素数
  b1 = np.count_nonzero(A>>i&1)
  #bi * (N-b1) がxorを意味している
  ans += 2**i*b1*(N-b1)
  ans %= mod
print (ans)

Submission status: Accepted

Solution code:

def submit():
    n = int(input())
    alist = list(map(int, input().split()))
    modp = 10**9 + 7

    d = 1
    ans = 0
    for i in range(60):
        bit_test = [a & d > 0 for a in alist]
        on_count = sum(bit_test)
        off_count = n - on_count
        ans += d * on_count * off_count
        ans %= modp
        d = d<<1

    print(ans)


submit()

Submission status: Accepted

Solution code:
def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

n = iip()
al = iip()
#al = [2**60 - 114514 - i for i in range(1000)]

mod = 10**9 + 7
num1 = [0 for i in range(60)]

for a in al:
    b = bin(a)[2:].zfill(60)
    #print(b)
    for i in range(60):
        if b[i] == "1":
            num1[i] += 1

result = 0
for i, a in enumerate(num1):
    a1 = 2**(59-i) % mod
    a2 = (a * (n-a)) % mod
    result += a1*a2 % mod
    result = result % mod


#print(num1)
print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a = int(input())
b = list(map(int,input().split()))
z_o_cnt = []
max_b = max(b)
base = 0
while True:
    z_o_cnt.append(sum(list(map(lambda x:x%2,b))))
    b = list(map(lambda x:x//2,b))
    max_b //=2
    if max_b==0:
        break
ret = 0
for i,v in enumerate(z_o_cnt):
    ret+=(2**i*(v * (a-v)))%(10**9+7)
print(ret%(10**9+7))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
l = inputIL()

ans = 0
for n in range(60):
  count_0 = 0
  count_1 = 0
  for i in l:
    if (pow(2,n)&i)>>n:
      count_1 += 1
    else:
      count_0 += 1
  ans = (ans + count_0*count_1*pow(2,n,MOD))%MOD
  
print(ans)

Submission status: Accepted

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

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

ans = 0
two = 1
for i in range(61):
  n = len([ a for a in A if (a >> i) & 1 ])
  ans += (n * (N - n) * two % MOD)
  two *= 2 
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):
    x = 0
    for j in range(N):     
        if A[j]>>i & 1:
            x += 1
    now = x * (N - x) % M
    for j in range(i):
        now = now * 2 % M
    ans += now
    ans %= M
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

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

    ans = 0
    for mask in range(60): # 各桁ごとに、1を持つ数を探す
        one_sum = 0
        for a in A:
            one_sum += (a >> mask) & 1

        ans += one_sum * (N - one_sum) * 2**mask

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

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
i = 1
for _ in range(60):
    b = 0
    c = 0
    for j in a:
        if j & i != 0:
            b += 1
        else:
            c += 1
    ans += b * c * i % mod
    i *= 2
print(ans%mod)

Submission status: Accepted

Solution code:
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
ans=0
for j in range(60):
    k=2**j
    count=0
    for i in range(N):
        if(A[i]&k):
            ans=(ans+k*(i-count))%MOD
            count+=1
        else:
            ans=(ans+k*count)%MOD
print(ans)

Submission status: Accepted

Solution code:
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
ans=0
for j in range(60):
    k=2**j
    count=0
    for i in range(N):
        if(A[i]&k):
            ans=(ans+(2**j)*(i-count))%MOD
            count+=1
        else:
            ans=(ans+(2**j)*count)%MOD
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int,input().split()))
cnt = []
A = np.array(A)
for _ in range(60):
    ad = A % 2
    cnt.append(int(np.sum(ad)))
    A = A // 2
ans = 0
for i in range(60):
    num0 = N - cnt[i]
    num1 = cnt[i]
    ans += ((num0 * num1) * (2 ** i)) % MOD
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
mod = 10**9+7
N = int(input())
A = list(map(int,(input().split())))
bi = [[0]*2 for _ in range(60)]
for i in range(N):
    c = 0
    while c < 60:
        if A[i] & 1 == 0:
            bi[c][0] += 1
        else:
            bi[c][1] += 1
        A[i] >>= 1
        c += 1
ans = 0
for i in range(60):
    ans += bi[i][0] * bi[i][1] * pow(2,i)
    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):
    b1 = np.count_nonzero(A>>i&1)
    ans += 2**i*b1*(N-b1)
    ans %= mod
print (ans)

Submission status: Accepted

Solution code:
MOD=10**9+7
n=int(input())
x=[0 for i in range(60)]
a=list(map(int,input().split()))

for i in range(n):
    k=0
    while a[i]>0:
        if a[i]&1:
            x[k]+=1
        a[i]>>=1
        k+=1
ans=0
for i in range(60):
    ans+=x[i]*(n-x[i])*(2**i)
    ans%=MOD
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys 
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int,input().split()))
    
    
    mod = 10**9+7
    ans = 0
    ni = 1
    for j in range(60):
        x = 0
        for i in l:
            if (i >> j) & 1:
                x += 1
        now = x*(n-x)*ni%mod
        ans = (ans+now)%mod
        ni = (ni*2)%mod

    print(ans%mod)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

m = 0
t = 1
for i in range(61):
    count = 0
    for j in range(N):
        count += A[j] % 2
        A[j] //= 2
    m += ((t * (N - count)) % int(1e9+7)) * count % int(1e9+7)
    m %= int(1e9+7)
    t *= 2
    t %= int(1e9+7)
    
print(m)

Submission status: Accepted

Solution code:
def xor_sum(a):
    sum = 0
    d = 10**9+7
    new_a = []
    for j in a:
        new_a.append(str(format(j, 'b')).zfill(60))
    for i in range(60):
        n_0 = 0
        n_1 = 0
        for j in new_a:
            if j[i] == '0':
                n_0 += 1
            else:
                n_1 += 1
        sum += (pow(2, 59-i)*(n_0*n_1))%d
    print(sum%d)

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

xor_sum(a)

Submission status: Accepted

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

print(ans)

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
ans = 0
for i in range(60):
    b = np.count_nonzero(A >> i & 1)
    ans += 2 ** i * b * (N - b)
    ans %= mod
print(ans)

Submission status: Accepted

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

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
N %= mod

for i in range(K):
    bit = np.count_nonzero(A >> i & 1) % mod
    ans += pow(2, i, mod) * bit * (N - bit)
    ans %= mod
    
print(ans)

Submission status: Accepted

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

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
N %= mod

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

Submission status: Accepted

Solution code:
MOD = 1000000007

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

ans = 0
for k in range(60):
    mask = 1<<k
    cnt1 = sum(1 for x in a if x&mask != 0)
    ans += cnt1*(n-cnt1)*(1<<k)
print(ans%MOD)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(60):
    x = 1<<i
    o = sum(1 for j in A if j&x)
    ans += x*o*(N-o)
    ans %= 10**9+7
print(ans)

Submission status: Accepted

Solution code:


import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int64)
mod = 10 ** 9 + 7

ans = 0
dmax = 61
for d in range(dmax):
    B = np.right_shift(A, d)
    one = np.count_nonzero(np.bitwise_and(B, 1))
    zero = N - one
    add = pow(2, d, mod) * one * zero
    ans = (ans + add) % mod

print(ans)

Submission status: Accepted

Solution code:
'''
結局この計算は Ai のすべての組み合わせ(Ai 自身同士は含まない)の 
XOR の合計なので、Ai のあるビットの立っている数の合計を c とすると、
Ai のあるビットが0であった場合により計算結果に立つビットの数は 
c、Ai のあるビットが1であった場合により計算結果に立つビットの数は 
N - c になるので、あるビットに関する計算結果は c * (N -c) の
ビットシフトした値になる. 結果として以下の計算で解ける.
'''
N = int(input())
A = list(map(int, input().split()))

result = 0
for bit in range(60):
    m = 1 << bit
    c = sum(a & m for a in A) >> bit
    result += (c * (N - c)) << bit
    result %= 1000000007
print(result)

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):
	x = 0
	for j in a:
		if j >> i & 1:
			x += 1
	z = x*(n-x)%mod
	z *= 2**i
	z %= mod
	ans += z
	ans %= mod
print (ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[]
M=0
for a in A:
    b=bin(a)
    if M<len(b[2:]):
        M=len(b[2:])
    B.append(b[2:])
ans=0
for i in range(0,M):
    z=0;o=0
    for j in range(0,N):
        if len(B[j])<i+1:
            z+=1
        else:
            index=len(B[j])-i-1
            if B[j][index]=='0':
                z+=1
            else:
                o+=1
    ans+=(2**i*(z*o))%(10**9+7)
print(ans%(10**9+7))

Submission status: Accepted

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

bitsum = [0 for _ in range(60)]
for x in a:
    for i in range(60):
        bitsum[i] += bool(x & (1 << i))

ans = 0
for x in a:
    for i in range(60):
        k = bitsum[i]
        if (x & (1 << i)):
            k = n - k
        ans += k << i
    ans %= law
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + law) // 2)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
MOD = 10**9 + 7
for i in range(60):
    z = 0
    o = 0
    for j in range(N):
        if A[j]&(2**i):
            o += 1
        else:
            z += 1
    ans += z*o*(2**i)
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
import numpy as np


def main():
    length = int(input())
    numbers = np.array(list(map(int, input().split())))
    mod = 10 ** 9 + 7
    answer = 0
    for d in range(60):
        count_one = np.count_nonzero((numbers >> d) & 1)
        answer = (answer + pow(2, d) * count_one * (length - count_one)) % mod
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    d = [0] * 60
    for a in A:
        b = 0
        while a:
            if a&1: d[b] += 1
            a >>= 1
            b += 1

    ans = Mint()
    for i in range(60):
        ans += Mint(d[i]) * (N-d[i]) * (1<<i)
    print(ans)

class Mint:
    def __init__(self, value=0, mod=10**9+7):
        self.value = ((value % mod) + mod) % mod
        self.mod = mod

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, self.mod
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        return (u + self.mod) % self.mod

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.val
    def __neg__(self): return Mint(-self.value, self.mod)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % self.mod
        return self
    def __add__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other) + self.mod) % self.mod
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other), self.mod)
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % self.mod
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other, self.mod)
        self *= other.inverse
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other), self.mod)
        new_obj //= self
        return new_obj


if __name__ == '__main__':
    main()

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):
    mask = 1 << i
    count = sum(1 for j in a if mask & j == 0)
    ans += count * (n-count) * pow(2,i,mod)
print(ans % mod)