Problem:


Score : 400 points

Problem Statement

We have N integers. The i-th integer is A_i.

Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

What is \mbox{ XOR }?

The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:

When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.

For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Constraints

2 \leq N \leq 3 \times 10^5

0 \leq A_i < 2^{60}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

Sample Input 1

3
1 2 3

Sample Output 1

6

We have (1\mbox{ XOR } 2)+(1\mbox{ XOR } 3)+(2\mbox{ XOR } 3)=3+2+1=6.

Sample Input 2

10
3 1 4 1 5 9 2 6 5 3

Sample Output 2

237

Sample Input 3

10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820

Sample Output 3

103715602

Print the sum modulo (10^9+7).



Sample input:
3
1 2 3


Sample output:
6

Submission status: Accepted

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

MOD = 10**9 + 7

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

ans = 0
for n in range(64):
	Anb = (A >> n) & 1
	cnt_one = np.count_nonzero(Anb)
	cnt_zero = N - cnt_one
	x = cnt_one * cnt_zero
	for i in range(n):
		x *= 2
		x %= MOD
	ans = (ans+x)%MOD
print(ans)

Submission status: Accepted

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + ((n>>j)&1)

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        if (n>>j)&1:
            a = N-a-i # 0

        ans += a*(1<<j)

print(ans%mod)

Submission status: Accepted

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + ((n>>j)&1)

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        if (n>>j)&1:
            a = N-a-i # 0

        ans += a*(1<<j)
    ans %= mod

print(ans)

Submission status: Accepted

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


result = 0
base = 1
for _ in range(max_digit + 1):
  c0 = 0
  for i in range(N):
    a = A[i] % 2
    A[i] >>= 1
    c0 += (a==0)
  
  result = (result + (base*(N - c0)*c0) % MOD) % MOD
  base = base*2 % MOD

print(result)

Submission status: Accepted

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

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

print(result)

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

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
c=0
for i in range(61):
 i=2**i
 t=sum(i&b and 1for b in a)
 c=(c+t*(n-t)*i)%(10**9+7)
print(c)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
c=0
for i in range(61):
  i=2**i
  t=sum(i&b and 1 for b in a)
  c=(c+t*(n-t)*i)%(10**9+7)
print(c)

Submission status: Accepted

Solution code:
import numpy as np

MOD = 10**9 + 7
n = int(input())
a = np.array(input().split(), np.int64)
max_num = np.max(a)
digit_num = len(format(max_num, 'b'))
ans = 0
for digit in range(digit_num):
    b = (a >> digit) & 1
    one = np.count_nonzero(b)
    zero = n - one
    ans += 2 ** digit * (one * zero)
    ans %= MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    ans = [0] * 60
    
    
    for i in range(60):
        # x0 = len([j for j in range(N) if not (A[j]>>i)&1])
        # x1 = len([j for j in range(N) if (A[j]>>i)&1])
        x0 = 0
        x1 = 0
        for j in range(N):
            if (A[j]>>i)&1:
                x1 += 1
            else:
                x0 += 1

        ans[i] = x0*x1

    x = 0
    for i in range(len(ans)):
        # print(i, 2**i)
        x += pow(2, i) * ans[i] % MOD

    print(x%MOD)

    return



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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop
import itertools

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

MOD = 10**9 + 7

ans = 0
for i in range(64):
    B = (A >> i) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y

    for _ in range(i):
        x *= 2
        x %= MOD

    ans += x
ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
res = 0
MOD = int(1e9 + 7)
bit = 0
for n in range(60):
    b1, b0 = 0, 0
    for i in range(len(X)):
       if X[i] & (1 << bit):
           b1 += 1
       else:
           b0 += 1
    res += (b1 * b0 * (1 << bit))
    res = res % MOD
    bit += 1
print(res)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

mod = 1000000007

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()

ans = 0
for i in range(61):
	z, o = [0] * 2
	for j in range(n):
		if a[j] & (1 << i):
			o += 1
		else:
			z += 1
	ans += z * o * (2 ** i)
	ans %= mod

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split( )))
ans = 0
mod = 10**9+7
Bit = [0 for j in range(60)]# for i in range(n+1)
for j in range(60):#ループ交換
    for i in range(1,n):##1から
        if not ((a[i-1]>>j)&1):#a[i-1]のjビット目0
            Bit[j] += 1
        if ((a[i]>>j)&1):#aiのjビット目1
            ans += Bit[j]<<j
            ans %=mod
        else:
            ans += (i-Bit[j])<<j
            ans %= mod
    
print(ans)

Submission status: Accepted

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

cnt = [[0, 0] for _ in range(60)]
for i in range(60): # <= 2^60
    for j, v in enumerate(a):
        cnt[i][bool(v & (1 << i))] += 1


# print(cnt[:5])
sub = [[0, 0] for _ in range(60)]

# "001"
# "010"
# "011"

result = 0
for i, c in enumerate(cnt):
    for j, delete in enumerate(a[:-1]):
        target = not (delete & (1 << i))
        result += (c[target] - sub[i][target]) * (1 << i)

        # print(i, ":", int(target), c[target], result, sub[i], "->", sub[i][target])

        sub[i][not target] += 1

    # print(result)
    # print("-----")
    # if i > 5: break

# print(result)


# for p, delete in enumerate(a):
#     for i, cs in enumerate(cnt):
#         if delete & (1 << i):
#             target = 0
#         else:
#             target = 1
#
#         result += (cs[n - 1][target] - cs[p - 1][target]) * (1 << i)
print(result % (10**9 + 7))

Submission status: Accepted

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

mod = 10**9 + 7

S = [0]*61

for i in range(N):
    tmpA = A[i]
    now = 0
    while tmpA != 0:
        if tmpA%2 == 1:
            S[now] += 1
        tmpA //= 2
        now += 1
ans = 0
for i in range(61):
    ans += pow(2,i,mod)*S[i]*(N-S[i])
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
a = np.array(a)
mod = 10**9 + 7
ans = 0
for i in range(60):
  # a要素のi番目のデータが1であるデータの数 iビット右シフト &:論理積 
  b = np.count_nonzero(a >> i & 1)
  #print(a>>i&1)
  # 2進数から10進数 b*(N-b)は(1の個数)*(0の個数)
  ans += 2 ** i * b*(n-b)
  ans %= mod
print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8
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):
    # i桁目の1の数を数える
    cnt_zero = np.count_nonzero(a >> i & 1)
    cnt_one = n - cnt_zero
    # すべての１と０をそれぞれ掛けあわせた総数を、桁ごとに計算
    ans += 2**i * cnt_zero * cnt_one
    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
N = int(readline())
A = np.array(readline().split(), np.int64)

mod = 10**9+7
ans = 0
for i in range(64):
	B = (A>>i)&1
	x = np.count_nonzero(B)
	y = N - x
	x *= y

	for _ in range(i):
		x *= 2
		x %= mod
	ans += x
	ans %= mod
print(ans)

Submission status: Accepted

Solution code:
#ABC147-D Xor Sum 4
n = int(input())
lst1 = list(map(int,input().split()))
mod = 10**9+7

"""
ビット演算は桁ごとに独立しているので、何桁目かというループを外側において
桁ごとに計算して、最後に全部の値を足す。
↓何が良いか？
XORの性質として、0を1個、1を1個選ぶことで1になるので、そうなる選び方の総数を求めることで
高速に計算が可能となる。
"""

ans = 0

for i in range(60): #桁ごとのループ
    x = 0 #i桁における1の個数
    for j in range(n):
        if lst1[j]>>i &1: #要素Ajのi桁目がiならばxに1を足す
            x += 1
    y = n-x #i桁における0の個数
    now = x*y %mod #XORが1になる回数※コード下部に証明有り

    now *= 2**i #nowを2**iまで持ってく1

    ans += now
    ans %= mod

print(ans)

"""
その桁のXORが１になる回数が
(1の出現回数)*(0の出現回数)であることの証明

その桁の全ループに対して、愚直に1の出現回数を数えてみる
今回は、[0,1,0,1,0,0,1]について考える。X = 3,Y = 4でXOR=12となることを証明する。

[0] 1 0 1 0 0 1 → 3回(0より右に1は3回ある)
0 [1] 0 1 0 0 1 → 3回
0 1 [0] 1 0 0 1 → 2回
0 1 0 [1] 0 0 1 → 2回
0 1 0 1 [0] 0 1 → 1回
0 1 0 1 0 [0] 1 → 1回
---------------------
計：              12回

よって、その桁の全ループにおいて
XORが1になる回数は、(1の出現回数)*(0の出現回数)であることが分かる。
"""

Submission status: Accepted

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

MOD = 10**9+7

m = 1
ans = 0
for i in range(60):
    bit = sum(a & m for a in A)
    bit //= m
    zero = N - bit
    now = bit * zero % MOD
    for j in range(i):
        now = (now * 2) % MOD
    ans += now
    ans %= MOD
    m <<= 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
a = np.array(a)
mod = 10**9 + 7
ans = 0
for i in range(60):
  # a要素のi番目のデータが1であるデータの数
  b = np.count_nonzero(a >> i & 1)
  # 2進数 -> 10進数 (b*(N-b)は(1の個数)*(0の個数))
  ans += 2 ** i * (b*(n-b))
  # 和算のたびに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())))

mod = 10**9 + 7
ans = 0

for j in range(60):
    li = (a >> j) & 1
    i = np.count_nonzero(li)
    o = n - i
    ans += i*o*2**j
    ans %= mod

print(ans % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

mod = 10 ** 9 + 7

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

print(ans%mod)

Submission status: Accepted

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

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

for i in range(65):
    one = 0
    zero = 0
    
    for j in range(N):
        if (A[j]>>i)&1:
            one += 1
        else:
            zero += 1
    
    ans += one*zero*pow(2, i, MOD)
    ans %= MOD

print(ans)

Submission status: Accepted

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

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

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

print(ans % mod)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = 1e9 + 7
digit = 1
for i in range(60):
  one = 0
  for aa in a:
    if (aa >> i) & 1:
      one += 1
  ans += (one * (n - one) * digit) % mod
  ans %= mod
  digit *= 2

print(int(ans))

Submission status: Accepted

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

MOD = 10 ** 9 + 7
cnt = [0] * 61

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

answer = 0
for i in range(61):
  answer = (answer + (2 ** i * cnt[i] * (N - cnt[i]))) % MOD
print(answer)

Submission status: Accepted

Solution code:

MOD = 10 ** 9 + 7
n = int(input())
a = list(map(lambda x: format(int(x), '060b')[::-1], input().split()))

ans = 0
onecount = [0 for i in range(60)]
zerocount = [0 for i in range(60)]
for i in range(n):
    for j in range(60):
        if a[i][j] == '1':
            onecount[j] += 1
        else:
            zerocount[j] += 1

for i in range(60):
    ans += ((2 ** i) * onecount[i] * zerocount[i] % MOD)
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
#python3
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])
mod=int(1e9+7)
ans=0
for k in range(60):
  b = (a>>k)&1
  m = np.count_nonzero(b)
  ans += m*(n-m)*2**k
print(ans%mod)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ml = len(bin(max(a)))-2
ans = 0
for i in range(ml):
  x = sum([1 for j in a if ((j>>i) & 1)])
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)

Submission status: Accepted

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

import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    counts = [0] * 62
    for val in A:
        i = 0
        while val > 0:
            counts[i] += val % 2
            val //= 2
            i += 1
    ret = 0
    for i, cnt in enumerate(counts):
        ret += (2 ** i) * (cnt) * (N - cnt)
        ret %= MOD
    print(ret)
    return

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
MOD = int(1e9+7)
ans=0
for k in range(60):
  x=0
  t=1<<k
  for i in range(n):
    if a[i]&t:
      x+=1
  c=x*(n-x)*2**k
  ans+=c
print(ans%MOD)

Submission status: Accepted

Solution code:
#python3
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
md = len(bin(max(a)))-2
ans = 0
for d in range(md):
    cnt1 = sum([1 for i in a if ((i>>d)&1)]) 
    ans += cnt1 * (n-cnt1) * (1<<d)          
    ans %= mod                              
    
print(ans%mod)

Submission status: Accepted

Solution code:
#python3
import numpy as np
N = int(input())
A = np.array([int(_) for _ in input().split()])
mod = 10**9 + 7
ans = 0
for b in range(60):
    B = (A >> b) & 1
    M = np.count_nonzero(B)
    ans += 2**b * M * (N - M)
print(ans%mod)

Submission status: Accepted

Solution code:
#python3
import numpy as np
N = int(input())
A = np.array([int(_) for _ in input().split()])
mod = 10**9 + 7
ans = 0
for b in range(60):
    B = (A >> b) & 1
    M = np.count_nonzero(B)
    ans += 2**b * M * (N - M)
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
N = int(input())
MOD = 10**9+7
def inputs():return [int(x) for x in input().split()]
A = np.array([inputs()])
ans = 0
for i in range(63):
  B = A&(1<<i)
  x = np.count_nonzero(B)
  y = N-x
  x*=y
  ans+=(2**i*x)%MOD
  ans%=MOD
print(ans)

Submission status: Accepted

Solution code:
#!python3

def resolve():
    N = int(input())
    A = tuple(map(int, input().rstrip().split()))

    ma = max(*A)

    i = 1
    asum = 0
    while i < ma:
        cc = 0
        for x in A:
            if x & i: cc += 1
        asum += i * (N - cc) * cc
        i <<= 1

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N=int(input())
A=[format(i,'060b') for i in map(int,input().split())]
ans=0
mod=10**9+7
for k in range(60):
    count=[a[60-1-k] for a in A].count('0')
    ans+=count*(N-count)*(2**k)%mod
print(ans%mod)

Submission status: Accepted

Solution code:
p = 10**9+7
N = int(input())
C = {i:0 for i in range(60)}
A = input().split()
for i in range(N):
    a = bin(int(A[i]))[2:]
    n = len(a)
    for j in range(n):
        if a[j]=="1":
            C[n-1-j] += 1
cnt = 0
for i in range(60):
    if C[i]>0:
        cnt = (cnt+C[i]*(N-C[i])*2**i)%p
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np 

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

A = np.array(A,np.int64)##Ai<2^60

ans = 0
mod = int(1e9+7)

for i in range(60+1):
    bottom_bit = (A>>i)&1 ##i回シフトしたときの最下位bit
    ones = np.sum(bottom_bit[bottom_bit>0])
    ##ans += (N-ones)*ones*(2**i) ##0の個数*1の個数*2^i個
    tmp = ones*(N-ones)
    for j in range(i):
        tmp = (tmp * 2) % mod
    ans += tmp

print(ans%mod)

Submission status: Accepted

Solution code:
N=int(input())
A=[format(i,'060b') for i in map(int,input().split())]
ans=0
mod=10**9+7
for k in range(60):
    count=[a[60-1-k] for a in A].count('0')
    ans+=count*(N-count)*(2**k)%mod
print(ans%mod)

Submission status: Accepted

Solution code:
mod = int(1e9 + 7)
N = int(input())
A = [format(i, '060b') for i in map(int, input().split())]
S = 0
for k in range(60):
  s = [b[59-k] for b in A]
  v = s.count('0')*s.count('1')
  S += (v<<k)
S %= mod
print(S)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
MOD = 10**9 + 7
n = int(input())
al = list(map(int, input().split()))

b = [0]*100

for a in al:
    for i in range(100):
        b[i] += (a>>i)&1

res = 0
for i in range(100):
    res += b[i]*(n-b[i])*(1<<i)
    res %= MOD

print(res)

Submission status: Accepted

Solution code:
import itertools

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


def main():
    count_1 = [0] * 61
    for i in range(60):
        tmp = 0
        for j, a in enumerate(A):
            tmp += (a >> i) & 1
        count_1[i] += tmp
    ans = 0
    for i, c1 in enumerate(count_1):
        c0 = len(A) - c1
        ans += c0 * c1 * 2**i
    ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
divide = 10 ** 9 + 7

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

for i in range(60):
    bit_list = [b[59-i] for b in a]
    val = bit_list.count('0') * bit_list.count('1')
    ans.append((val * 2 ** i))

print(sum(ans)%divide)

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
As=LI()

DIG_CUM = [[0]*60 for _ in range(N+1)]

for i in range(N):
    for s in range(60):
        DIG_CUM[i+1][s] = DIG_CUM[i][s] + ((As[i] >> s) & 1)

# for arr in DIG_CUM:
#     print(arr)
POW2 = [1]
for i in range(60): POW2.append(POW2[i]*2%DVSR)

res = 0
for i in range(N-1):
    for s in range(60):
        coef = DIG_CUM[N][s] - DIG_CUM[i+1][s]
        if (As[i] >> s) & 1: coef = N - i - 1 - coef
        res += coef * POW2[s]
    res %= DVSR
print(res)

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
As=LI()

DIG_CUM = [[0]*60 for _ in range(N+1)]

for i in range(N):
    for s in range(60):
        DIG_CUM[i+1][s] = DIG_CUM[i][s] + ((As[i] >> s) & 1)

# for arr in DIG_CUM:
#     print(arr)

res = 0
for i in range(N-1):
    for s in range(60):
        coef = DIG_CUM[N][s] - DIG_CUM[i+1][s]
        if (As[i] >> s) & 1: coef = N - i - 1 - coef
        # coef = (N - i - 1 - (DIG_CUM[N][s] - DIG_CUM[i+1][s])) if (As[i] >> s) & 1 else DIG_CUM[N][s] - DIG_CUM[i+1][s]
        res += coef * (1 << s)
    res %= DVSR
print(res)

Submission status: Accepted

Solution code:
import sys


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


if __name__ == '__main__':
    solve()

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):
    x, y = 0, 0
    B = A >> i & 1
    x = np.count_nonzero(B)

    y = N - x
    ans += (x * y) * (2 ** i)
print(ans%mod)

Submission status: Accepted

Solution code:
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

#a = list(map(int, input().split()))
# --------------------------------------------

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

for i in range(n):
    b.append(bitlist(a[i],61))

c = [0 for i in range(61)]

for i in range(61):
    for j in range(n):
        c[i] += b[j][i]
ans = 0
for i in range(61):
    ans += c[i]*(n-c[i])*2**i % 1000000007
print(ans % 1000000007)

Submission status: Accepted

Solution code:

import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

#a = list(map(int, input().split()))
# --------------------------------------------

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

for i in range(n):
    b.append(bitlist(a[i],61))

c = [0 for i in range(61)]

for i in range(61):
    for j in range(n):
        c[i] += b[j][i]
ans = 0
for i in range(61):
    ans += c[i]*(n-c[i])*2**i % 1000000007
print(ans % 1000000007)

Submission status: Accepted

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

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

    A = np.array(A,np.int64)

    mod = 10**9 + 7

    res = 0

    for i in range(60):
        count = np.count_nonzero(A & 1)
        res += (N - count) * count * 2 ** i
        res %= mod
        A >>= 1

    print(res)

main()

Submission status: Accepted

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

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

A = np.array(A,np.int64)

mod = 10**9 + 7

res = 0

for i in range(60):
    count = np.count_nonzero(A & 1)
    res += (N - count) * count * 2 ** i
    res %= mod
    A >>= 1

print(res)

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
bite = []
for _ in range(60):
    bite.append(0)
    
for A in A_list:
    for i in range(60):
        if A & 1 << i:
            bite[i] += 1

ans = 0
on_right = N - 1
for num in range(len(A_list)):
    A = A_list[num]
    for i in range(60):
        if A & 1 << i:
            bite[i] -= 1
            ans += (on_right - bite[i]) * 1 << i
        else:
            ans += bite[i] * 1 << i
    on_right -= 1

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

Submission status: Accepted

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

mod = int(1e9 + 7)
ans = 0
for i in range(61):
    t = 0
    for a in A:
        if a >> i & 1:
            t += 1
    ans = (ans + pow(2, i, mod) * t * (n-t)) % mod
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    digit_count_one = [0] * 61
    nums = N * (N-1) // 2
    cnt = 0
    for a in A:
        for i in range(61):
            c = (a >> i) & 1
            if c == 1:
                digit_count_one[i] += 1
    for ix, count in enumerate(digit_count_one):
        freq = count * (N - count)
        cnt += ((1 << ix) * freq) % mod
        cnt %= mod
    print(cnt % mod)
main()

Submission status: Accepted

Solution code:
import itertools


N = int(input())
nums = [int(i) for i in input().split(" ")]
longest = len(bin(max(nums))) - 2
nums_bin = [format(i, "b").zfill(longest) for i in nums]


result = 0
for index, numbers in enumerate(zip(*nums_bin)):
    i = longest - index - 1
    zero = numbers.count("0")
    one = N - zero
    result += (2 ** i) * (zero * one)
print(result % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
res = 0
for i in range(62):
  cnt = 0
  for x in a:
    if (x & (1<<i)) > 0:
      cnt += 1
  res = (res + (cnt * (n-cnt) * (1 << i))) % mod
print(res)

Submission status: Accepted

Solution code:
N = int(input())
A=list(map(int,input().split()))
L=[0]*65
MOD=(10**9+7)
for i in range(N):
    t=str(format(A[i],"b"))
    for j in range(len(t)):
        L[j]+=int(t[-j-1])

for i in range(len(L)):
    L[i]=L[i]*(N-L[i])
    L[i]*=2**i
    L[i]%=MOD
print(sum(L)%MOD)

Submission status: Accepted

Solution code:
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

N = readi()
A = ints()

w = 1000000007

s = 0
for k in range(60):
  n = [0, 0]
  for i in range(N):
    n[A[i]%2] += 1
    A[i] >>= 1

  s += (n[0]*n[1] << k) % w

print(s%w)

Submission status: Accepted

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

def wash_b(line, s):
    l = len(line)
    neck = 2**s
    cnt = 0
    for i in range(l):
        if line[i] >= neck:
            line[i] -= neck
            cnt += 1
    return cnt
ans = 0
for i in range(60):
    w = wash_b(a, 59 - i)
    ans += (w*(n-w)*(2**(59-i))) % mod

ans %= mod
print(ans)

Submission status: Accepted

Solution code:
div = 10**9 + 7
ans = 0

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

#最大値
A_max = max(A)
#最大値を２進数化
A_max_bin = format(A_max, 'b')
#その桁数
max_digits = len(A_max_bin)

#print(max_digits)

input_format = '0' + str(max_digits) + 'b'

A_bin = [ format(item,input_format) for item in A]

#print(A_bin)

ans = 0

for i in range(1,max_digits+1):
    num0 = 0
    num1 = 0
    #print("桁数 : " + str(i))
    for A_i in A_bin:

        #print(str(A_i) + " : " + str(A_i[-i]))
        #i桁目が0だったら

        #print(type(A_i[-1]))

        if A_i[-i] == '0':
            num0 += 1
        else:
            num1 += 1

    ans += num0 * num1 * 2**(i-1)
    #print(ans)

    num0 = 0
    num1 = 0

#print(ans)
print(ans%div)

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):
    x, y = 0, 0    
    B = A >> i & 1
    x = np.count_nonzero(B)
#     for Ai in A:
#         if Ai >> i & 1:
#             x += 1
    y = N - x
    ans += (x * y) * (2 ** i)
    
print(ans%mod)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
num_list = np.array(input().split(), dtype = np.int64)
mod = 10**9 + 7

ans = 0
for i in range(60):
    b = np.count_nonzero(num_list >> i & 1)
    if i==0:
        pow_two = 1
    else:
        pow_two = pow_two * 2 % mod
    ans += pow_two * b * (n-b) % mod
    ans %= mod
    
print(ans)

Submission status: Accepted

Solution code:
#入力値処理
n = int(input())
data = [int(s) for s in input().split()]

bindata = []

for value in data:
  tmp = format(value,'b').zfill(60)  
  bindata.append(tmp)

#各桁の1の個数を格納
numlist = []
for i in range(60):
  numlist.append([row[i] for row in bindata])
#print(numlist)

binnum = [0] * 60
for i in range(60):
  binnum[59-i] = numlist[i].count('1')
#print(binnum)

"""
for rowdata in bindata:
  for j in range(60):
    if rowdata[j] == '1':
      numlist[59-j] += 1
"""
ans = 0

#各桁の1の個数と0の個数の積の和を求める
for i in range(60):
  ans += binnum[i] * (n-binnum[i]) * (2 ** i)
ans = ans % (10**9 + 7)
print(ans)






"""
ans = 0

for i in range(n-1):
  for j in range(i,n):
    ans = ans +  int(bin(data[i] ^ data[j]),0)
ans = ans % (10 ** 9 + 7)

print(int(ans))
"""