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: Wrong Answer

Solution code:
N = 60
MOD = 10**9 + 7
n = int(input())
# c1 = [0 for _ in range(N)]
c0 = [0 for _ in range(N)]

a = list(map(int,input().split()))
for i in range(n):
    for j in range(N):
        if a[i] & (1 << j) == 0:
            c0[j] += 1
        # else:
        #     c1[j] += 1

ans = 0
for i in range(n-1):
    for j in range(N):
        if a[i] & (1 << j) == 0:
            c0[j] -=1
        # else:
        #     c0[j] -=1
    for j in range(N):
        if a[i] & (1 << j) == 0:
            ans += (1<<j) * c0[j]
        else:
            ans += (1<<j) * (n-i-1-c0[j])
            #ans += (1<<j) * c1[j]

print(ans % MOD)

Submission status: Wrong Answer

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

INF = 10 ** 9 + 7
N = int(input())
a = list(map(int, input().split()))
cnt = [0] * 60
for i in a:
    for j in range(60):
        tmp = i >> j
        if tmp != 0:
            cnt[j] += tmp % 2
        else:
            break
ans = 0
#for b in range(60):
#    ans += cnt[b] * (N - cnt[b]) << b
#    ans %= INF
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

result = 0
for b in range(60):
  t = 0
  bs = (A[N - 1] >> b) & 1
  for i in range(N - 1):
    a = (A[i] >> b) & 1
    if a == 0:
      t += bs
    else:
      t += (N - (i + 1)) - bs
    bs += a
  result = (result + t * (1 << b)) % 1000000007
print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[int(i) for i in input().split()]
def sumXOR(arr, n):
    MOD=int((1e+9)+7)
    sum = 0
    for i in range(0, 64): 
        zc = 0
        oc = 0
        idsum = 0
        for j in range(0, n): 
            if (arr[j] % 2 == 0): 
                zc = zc + 1
            else: 
                oc = oc + 1
            arr[j] = int(arr[j] / 2) 
        idsum = oc * zc * ((1 << i)%MOD) 
        sum = sum + idsum
        sum= sum%MOD
    return sum

ans = sumXOR(arr, n); 
print (ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[int(i) for i in input().split()]
def sumXOR(arr, n):
    MOD=int((1e+9)+7)
    sum = 0
    for i in range(0, 61): 
        zc = 0
        oc = 0
        idsum = 0
        for j in range(0, n): 
            if (arr[j] % 2 == 0): 
                zc = zc + 1
            else: 
                oc = oc + 1
            arr[j] = int(arr[j] / 2) 
        idsum = oc * zc * (1 << i) 
        sum = (sum%MOD) + (idsum%MOD)
        sum= sum%MOD
    return sum

ans = sumXOR(arr, n); 
print (ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[int(i) for i in input().split()]
def sumXOR(arr, n):
    MOD=int((1e+9)+7)
    sum = 0
    for i in range(0, 60): 
        zc = 0
        oc = 0
        idsum = 0
        for j in range(0, n): 
            if (arr[j] % 2 == 0): 
                zc = zc + 1
            else: 
                oc = oc + 1
            arr[j] = int(arr[j] / 2) 
        idsum = (oc * zc * (1 << i))%MOD 
        sum = (sum + idsum)%MOD
    return sum

ans = sumXOR(arr, n); 
print (ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())
a = np.array(a, dtype=np.int64)

def main():
    b = a >> np.arange(61).reshape(-1, 1) & 1
    x = np.count_nonzero(b, axis=1)
    y = n - x
    x *= y 
    x %= MOD
    x *= 2 ** np.arange(61) % MOD
    x %= MOD
    
    ans = np.sum(x) % MOD
    return ans

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())
a = np.array(a, dtype=np.int64)

powmod = [None] * 61
powmod[0] = 1
for i in range(60):
    powmod[i+1] = powmod[i] * 2 % MOD
powmod = np.array(powmod, dtype=np.int64)

def main():
    b = a >> np.arange(61).reshape(-1, 1) & 1
    x = np.count_nonzero(b, axis=1)
    y = n - x
    x *= y 
    x %= MOD
    x *= powmod
    x %= MOD
    
    ans = np.sum(x) % MOD
    return ans

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

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[int(i) for i in input().split()]
def sumXOR(arr, n):
    MOD=int((1e+9)+7)
    sum = 0
    for i in range(0, 60): 
        zc = 0
        oc = 0
        idsum = 0
        for j in range(0, n): 
            if (arr[j] % 2 == 0): 
                zc = zc + 1
            else: 
                oc = oc + 1
            arr[j] = int(arr[j] / 2) 
        idsum = oc * zc * (1 << i) 
        sum = sum + idsum
        sum%=MOD
    return sum

ans = sumXOR(arr, n); 
print (ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())
a = np.array(a, dtype=np.int64)

powmod = [None] * 61
powmod[0] = 1
for i in range(60):
    powmod[i+1] = powmod[i] * 2 % MOD
powmod = np.array(powmod, dtype=np.int64)

def main():
    b = a >> np.arange(61).reshape(-1, 1) & 1
    x = np.count_nonzero(b, axis=1)
    y = n - x
    x *= y 
    x %= MOD
    x *= powmod
    x %= MOD
    return x
    
    ans = np.sum(x) % MOD
    return ans

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

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7

lst = [0] * 65
for a in A:
    tmp = a
    for i in range(61):
        lst[i] += tmp % 2
        tmp //= 2
        if tmp == 0:
            break

ans = 0
for a in A:
    tmp = a
    for i in range(61):
        n = tmp % 2
        tmp //= 2
        if n == 1:
            ans += pow(2, i, MOD) * (N - lst[i])
        else:
            ans += pow(2, i, MOD) * lst[i]
    ans %= MOD

print (ans // 2 % MOD)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())
a = np.array(a, dtype=np.int64)

powmod = [None] * 60
powmod[0] = 1
for i in range(59):
    powmod[i+1] = powmod[i] * 2 % MOD
powmod = np.array(powmod, dtype=np.int64)

def main():
    b = a >> np.arange(60).reshape(-1, 1) & 1
    x = np.count_nonzero(b, axis=1)
    y = n - x
    x *= y
    x *= powmod
    x %= MOD
    ans = np.sum(x) % MOD
    return ans

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())
a = np.array(a, dtype=np.int64)

def main():
    b = a >> np.arange(60).reshape(-1, 1) & 1
    x = np.count_nonzero(b, axis=1)
    x = x * (n - x) % MOD
    x *= 2 ** np.arange(60) % MOD
    x %= MOD
    ans = np.sum(x) % MOD
    return ans

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())
a = np.array(a, dtype=np.int64)

def main():
    b = a >> np.arange(61).reshape(-1, 1) & 1
    x = np.count_nonzero(b, axis=1)
    x = x * (n - x)
    x *= np.power(2, np.arange(60)) % MOD
    x %= MOD
    ans = np.sum(x) % MOD
    return ans

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())
a = np.array(a, dtype=np.int64)

def main():
    b = a >> np.arange(60).reshape(-1, 1) & 1
    x = np.count_nonzero(b, axis=1)
    x = x * (n - x)
    x *= np.power(2, np.arange(60)) % MOD
    x %= MOD
    ans = np.sum(x) % MOD
    return ans

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())
a = np.array(a, dtype=np.int64)

def main():
    b = a >> np.arange(60).reshape(-1, 1) & 1
    x = np.count_nonzero(b, axis=1)
    x *= n - x
    x *= np.power(2, np.arange(60)) % MOD
    x %= MOD
    ans = np.sum(x) % MOD
    return ans

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

Submission status: Wrong Answer

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

MOD = 100000000 + 7
ans = 0
for i in range(0, N-1):
  for j in range(i+1,N):
    ans = (ans + (A[i] ^ A[j])) % MOD

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
l = len(bin(a_max)) - 2
bits = np.zeros((l,2))
for num in a:
    for i, bit in enumerate(format(num, 'b').zfill(l)):
        if bit == '0':
            bits[i,0] += 1
        else:
            bits[i,1] += 1

sumation = 0
for i in range(l):
    sumation += bits[i,0] * bits[i, 1] * 2**(l-i-1)
print(int(sumation % (10**9+7)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#https://atcoder.jp/contests/abc141/tasks/abc147_d
import sys
#import collections

n= int(input())

tmp = input().split()
s = list(map(lambda a: int(a), tmp))

total=0
a=[]
b=[]
c=[]
for i in range(0,60):
	a.append(0)
	b.append(0)
	c.append(0)

tmp = s[0]
for j in range(0,60):
	if(tmp==0):
		break
	if(tmp%2==1):
		a[j]+=1
	tmp=tmp//2

tmp = s[n-1]
for j in range(0,60):
	if(tmp==0):
		break
	if(tmp%2==1):
		c[j]+=1
	tmp=tmp//2

for i in range(1,n-1):
	tmp = s[i]
	for j in range(0,60):
		if(tmp==0):
			break
		if(tmp%2==1):
			b[j]+=1
		tmp=tmp//2

#print(s)
#print(a)
#print(b)
#print(c)

total=0
for j in range(60,0,-1):
	total*=2
	total=total+(a[j-1]+b[j-1]+c[j-1])*(n-a[j-1]-b[j-1]-c[j-1])
#	print(total)
print(total)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[2**66+int(i) for i in input().split()]
ans=0
for i in range(64):
    x,y=0,0
    for j in a:
        if bin(j)[-i-1]=='1':
            y+=1
        else:
            x+=1
    ans+=x*y*(1<<i)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[int(i) for i in range(n)]

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ans = 0
for k in range(60):
  x = sum(A >> k & 1)
  ans += x * (N - x) * 2**k

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split()))).reshape(n, 1)
mod = 10**9 + 7
bit = np.arange(64).reshape(1, 64)
b = np.sum((a >> bit) & 1, axis=0)
b *= n - b
b *= (1 << np.arange(64)) % mod
ans = 0
for x in b:
    ans += x
    ans %= mod

print(ans)

Submission status: Wrong Answer

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

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

A_max = max(A)
L = len(Base_10_to_n(A_max, 2))

all = N
bit = np.array([0]*L)
for i in range(N):
	tmp = Base_10_to_n(A[i],2).rjust(L,"0")
	for j in range(L):
		if tmp[j] == "1":
			bit[j] += 1

ans = np.array([0] * L, dtype="int64")
for i in range(N):
	tmp = Base_10_to_n(A[i],2).rjust(L,"0")
	for j in range(L):
		if tmp[j] == "0":
			ans[j] += bit[j]
		else:
			ans[j] += (all - bit[j])
			bit[j] -= 1

	all -= 1

a = 0
for i in range(L):
	ans[i] %= mod
	tmp = (2**(L-i-1)) % mod
	a += ans[i] * tmp
	a %= mod
print(a)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split()))).reshape(n, 1)
mod = 10**9 + 7
bit = np.arange(64).reshape(1, 64)
b = np.sum((a >> bit) & 1, axis=1)
b *= n - b
ans = 0
for x in b:
    ans += x
    ans %= mod

print(ans)

Submission status: Wrong Answer

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

s = [0]*61
for a in range(n):
    for i in range(61):
        if(A[a]>>i&1)==1:
            s[i+1] += 1
ans = 0
for i in range(61):
    # print("a",2**(i-1)*s.get(i,0)*(n-s.get(i,0)))
    # print("b",s.get(i,0))
    # print("c",(n-s.get(i,0)))
    ans += 2**(i-1)*s[i]*(n-s[i])
ans = ans % (10**9+7)
print(int(ans))
# print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np


n = int(input())
a = [int(_) for _ in input().split()]
M = max(a)
p = len(format(M, 'b'))
l = [[0 for _ in range(n)] for _ in range(p)]
ans = 0
for i in range(n):
    a_s = format(a[i], '0' + str(p) + 'b')
    for c in range(p):
        l[c][i] = int(a_s[c])
arr = np.array(l)
for i in range(p):
    c1 = np.sum(arr[i])
    ans += (2**(p - i - 1)) * c1 * (n - c1)
    ans %= (10**9 + 7)
print(ans)

Submission status: Wrong Answer

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

s = [0]*61
for a in A:
    for i in range(61):
        if(a>>i&1)==1:
            s[i+1] += 1
ans = 0
for i in range(61):
    # print("a",2**(i-1)*s.get(i,0)*(n-s.get(i,0)))
    # print("b",s.get(i,0))
    # print("c",(n-s.get(i,0)))
    ans += 2**(i-1)*s[i]*(n-s[i])
ans = ans % (10**9+7)
print(int(ans))
# print(s)

Submission status: Wrong Answer

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

s = [0]*61
# for a in A:
#     for i in range(61):
#         # print(cnt,a)
#         if(a>>i&1)==1:
#             s[i+1] += 1
ans = 0
for i in range(61):
    # print("a",2**(i-1)*s.get(i,0)*(n-s.get(i,0)))
    # print("b",s.get(i,0))
    # print("c",(n-s.get(i,0)))
    ans += 2**(i-1)*s[i]*(n-s[i])
ans = ans % (10**9+7)
print(int(ans))
# print(s)

Submission status: Wrong Answer

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

s = [0]*61
for a in A:
    for i in range(61):
        # print(cnt,a)
        if(a>>i&1)==1:
            s[i+1] += 1
ans = 0
for i in range(61):
    # print("a",2**(i-1)*s.get(i,0)*(n-s.get(i,0)))
    # print("b",s.get(i,0))
    # print("c",(n-s.get(i,0)))
    ans += 2**(i-1)*s[i]*(n-s[i])
ans = ans % (10**9+7)
print(int(ans))
# print(s)

Submission status: Wrong Answer

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

s = {}
mx = 0
for a in A:
    cnt = 0
    while a != 0:
        # print(cnt,a)
        if(a&1)==1:
            if s.get(cnt+1)==None:
                s[cnt+1]=1
            else:
                s[cnt+1] += 1
        cnt+=1
        a = a >> 1
    mx = max(mx,cnt)
ans = 0
for i in range(mx+1):
    # print("a",2**(i-1)*s.get(i,0)*(n-s.get(i,0)))
    # print("b",s.get(i,0))
    # print("c",(n-s.get(i,0)))
    ans += 2**(i-1)*s.get(i,0)*(n-s.get(i,0))
ans = ans % (10**9+7)
print(int(ans))
# print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(_) for _ in input().split()]
M = max(a)
p = len(format(M, 'b'))
l = [[0 for _ in range(n)] for _ in range(p)]
for i in range(n):
    a_s = format(a[i], '0' + str(p) + 'b')
    for c in range(p):
        l[c][i] = int(a_s[c])
# for i in range(p):
#     print(l[i])
s = [[0 for _ in range(n+1)] for _ in range(p)]
for i in range(p):
    for j in range(n):
        s[i][j+1] = s[i][j] + l[i][j]
# for i in range(p):
#     print(s[i])
ans = 0
for j in range(n-1):
    for i in range(p):
        if l[i][j] == 1:
            ans += ((2**(p - i - 1)) * (n - j - 1) - (s[i][n] - s[i][j+1]))
        else:
            ans += (2**(p - i - 1)) * (s[i][n] - s[i][j+1])
        ans = ans % ((10**9) + 7)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
MOD = 10e9 + 7
bit = []
for ith_dig in range(len(bin(max(A))) - 2):
    num_0 = 0
    num_1 = 0
    for i in range(N):
        if str(A[i]).zfill(len(bin(max(A))) - 2)[ith_dig] == 0:
            num_0 += 1
        else:
            num_1 += 1
    bit.append(num_0 * num_1)
bit.reverse()
ans = 0
for i in range(len(bit)):
    ans += bit[i] * pow(2, i)
print(ans)

Submission status: Wrong Answer

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

print(sum(A))

mod=10**9+7
comb=list(itertools.combinations(A,2))
ans=0
for c in comb:
  a,b=c
  ans+=a^b
print(ans%mod)

Submission status: Wrong Answer

Solution code:
def solve(a_s) -> int:
  def get_ret_from_xs(xs) -> int:
    # 繰り上がり処理ありバージョン
    ret = 0
    for i, x in enumerate(xs):
      ret += 2**i * (x % 2)
      ret %= 10**9 + 7
    return ret

  def get_ret_from_xs2(xs) -> int:
    ret = 0
    for i, x in enumerate(xs):
      ret += 2**i * x
      ret %= 10**9 + 7
    return ret

  # zeros = [1, 1] + [0] * 58  # 各要素 0 ~ n. 要素iは、下 i +1 桁目が0である A_? の個数
  # ones = [2, 2] + [0] * 58 # 各要素 0 ~ n. 要素iは、下 i +1 桁目が0である A_? の個数
  zeros = [0] * 60
  ones = [0] * 60

  for a in a_s:
    for i in range(len(zeros)):
      # a_bin = format(a, '060b')
      # a_i_digit_from_right = a_bin[60 - i - 1]
      # if a_i_digit_from_right == '0':
      #   zeros[i] += 1
      # else:
      #   ones[i] += 1

      a_i_digit_from_right = ((a & (2**i)) >> i) & 0b1
      if a_i_digit_from_right == 0:
        zeros[i] += 1
      else:
        ones[i] += 1

  # 繰り上がり処理しないでも、各桁で収めてもいいんだ！
  xs = [zeros[i] * ones[i] for i in range(60)]
  return get_ret_from_xs2(xs)


  # # 繰り上がりのせいで、xsの要素数は60を超えることがあるので注意
  # xs = []
  # i = 0
  # while True:
  #   x_i = 0
  #   if i <= 59:
  #     x_i = (zeros[i] * ones[i])
  #   if i >= 1:
  #     x_i += xs[i - 1] // 2
  #   xs.append(x_i)
  #
  #   if i >= 60 and x_i // 2 == 0:
  #     break
  #
  #   i += 1

  #xs = [2, 3, 1]
  return get_ret_from_xs(xs)


# n = int(input().strip())
# a_s = [int(s) for s in input().split()]

#a_s = [1, 2, 3]
#a_s = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]
a_s = [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]

print(solve(a_s))

Submission status: Wrong Answer

Solution code:
def solve(a_s) -> int:
  def get_ret_from_xs(xs) -> int:
    ret = 0
    for i, x in enumerate(xs):
      ret += 2**i * (x % 2)
      ret %= 10**9 + 7
    return ret

  # zeros = [1, 1] + [0] * 58  # 各要素 0 ~ n. 要素iは、下 i +1 桁目が0である A_? の個数
  # ones = [2, 2] + [0] * 58 # 各要素 0 ~ n. 要素iは、下 i +1 桁目が0である A_? の個数
  zeros = [0] * 60
  ones = [0] * 60

  for a in a_s:
    for i in range(len(zeros)):
      # a_bin = format(a, '060b')
      # a_i_digit_from_right = a_bin[60 - i - 1]
      # if a_i_digit_from_right == '0':
      #   zeros[i] += 1
      # else:
      #   ones[i] += 1

      a_i_digit_from_right = (a & (2**i) >> i) & 0b1
      if a_i_digit_from_right == 0:
        zeros[i] += 1
      else:
        ones[i] += 1

  # 繰り上がりのせいで、xsの要素数は60を超えることがあるので注意
  xs = []
  i = 0
  while True:
    x_i = 0
    if i <= 59:
      x_i = (zeros[i] * ones[i])
    if i >= 1:
      x_i += xs[i - 1] // 2
    xs.append(x_i)

    if i >= 60 and x_i // 2 == 0:
      break

    i += 1

  #xs = [2, 3, 1]
  return get_ret_from_xs(xs)


n = int(input().strip())
a_s = [int(s) for s in input().split()]

#a_s = [1, 2, 3]
#a_s = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]
#a_s = [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]

print(solve(a_s))

Submission status: Wrong Answer

Solution code:
def solve(a_s) -> int:
  def get_ret_from_xs(xs) -> int:
    ret = 0
    for i, x in enumerate(xs):
      ret += 2**i * (x % 2)
      ret %= 10**9 + 7
    return ret

  # zeros = [1, 1] + [0] * 58  # 各要素 0 ~ n. 要素iは、下 i +1 桁目が0である A_? の個数
  # ones = [2, 2] + [0] * 58 # 各要素 0 ~ n. 要素iは、下 i +1 桁目が0である A_? の個数
  zeros = [0] * 60
  ones = [0] * 60

  for a in a_s:
    for i in range(len(zeros)):
      a_bin = format(a, '060b')
      a_i_digit_from_right = a_bin[60 - i - 1]
      if a_i_digit_from_right == '0':
        zeros[i] += 1
      else:
        ones[i] += 1

  # 繰り上がりのせいで、xsの要素数は60を超えることがあるので注意
  xs = []
  i = 0
  while True:
    x_i = 0
    if i <= 59:
      x_i = (zeros[i] * ones[i])
    if i >= 1:
      x_i += xs[i - 1] // 2
    xs.append(x_i)

    if i >= 60 and x_i // 2 == 0:
      break

    i += 1

  #xs = [2, 3, 1]
  return get_ret_from_xs(xs)


# n = int(input().strip())
# a_s = [int(s) for s in input().split()]

#a_s = [1, 2, 3]
#a_s = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]
a_s = [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]

print(solve(a_s))

Submission status: Wrong Answer

Solution code:
from numpy import*
M=10**9+7
a=int_(open(0).read().split())
c=0
for i in range(61):
  i=2**i
  t=sum(i&a[1:]>0)
  c=(c+t*(a[0]-t)%M*i)%M
print(c)

Submission status: Wrong Answer

Solution code:
from numpy import*
a=int_(open(0).read().split())
c=0
for i in range(61):
  i=2**i
  t=sum(i&a[1:]>0)
  c=(c+t*(a[0]-t)*i)%(10**9+7)
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in input().split():
    a.append(int(i))
ans = 0
MOD = 1e9 + 7
for i in range(n - 1):
    for j in range(i + 1, n):
        ans += a[i] ^ a[j]
print(int(ans % MOD))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in input().split():
    a.append(int(i))
ans = 0
MOD = 1e9 + 7
for i in range(n - 1):
    for j in range(i + 1, n):
        ans += a[i] ^ a[j]
        ans = int(ans % MOD)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
lists=list(map(int,input().split()))
length=61
use=[0 for i in range(61)]
a,b=divmod(n,9)
anslist=[0 for i in range(a+1)]
for  j in range(n):
    k=format(lists[j],"0%ib"%length)
    k=k[::-1]
    p,q=divmod(n,9)
    if p>a:
        anslist.append(int(k))
    else:
        anslist[p]+=int(k)
answer=0
for some in anslist:
    some=str(some)
    some=some.zfill(61)
    for j in range(61):
        if int(some[j])!=0:
            use[j]+=int(some[j])

for j in range(61):
    answer+=(2**j)*use[j]*(n-use[j])%(10**9+7)
print(answer%(10**9+7))

Submission status: Wrong Answer

Solution code:
import numpy as np

mod = 10 ** 9 + 7
n = int(input())
a = np.array(list(input().split()), np.int64)
ans = 0
for i in range(60):
    b = (a >> i) & 1
    cnt = np.sum(b[b > 0])
    ans = (ans + (cnt * (n - cnt)) * (2 ** i)) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ans = 0
for i in range(60):
    b = (a >> i) & 1
    cnt = np.sum(b[b > 0])
    ans = (ans + (cnt * (n - cnt)) * (2 ** i)) % mod
print(ans)

Submission status: Wrong Answer

Solution code:

def sumXOR( arr,  n): 
      
    sum = 0
    for i in range(0, 61): 
  
        #  Count of zeros and ones 
        zc = 0
        oc = 0
           
        # Individual sum at each bit position 
        idsum = 0
        for j in range(0, n): 
            if (arr[j] % 2 == 0): 
                zc = zc + 1
                  
            else: 
                oc = oc + 1
            arr[j] = int(arr[j] / 2) 
          
           
        # calculating individual bit sum  
        idsum = oc * zc * (1 << i) 
   
        # final sum     
        sum = sum + idsum; 
        sum %= 10**9+7
      
    return sum
n = int(input())
sum = 0
mod = 10**9+7
arr = list(int(i) for i in input().split())
n = len(arr) 
sum = sumXOR(arr, n); 
print(sum%mod)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ans = 0
for i in range(63):
    b = (a >> i) & 1
    cnt = np.sum(b[b == 1])
    ans = (ans + (cnt * (n - cnt)) * (2 ** i)) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ans = 0
for i in range(60):
    b = (a >> i) & 1
    cnt = np.sum(b[b == 1])
    ans = (ans + (cnt * (n - cnt)) * (2 ** i)) % mod
print(ans)

Submission status: Wrong Answer

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 = [int(x) for x in readline().rstrip().split()]
B = [0] * 60
C = [[0] * 60 for _ in range(N)]
ans = 0
for i in range(N):
    i_bin = list(bin(A[i]))
    i_bin = i_bin[2:]
    i_bin = i_bin[::-1]
    k = 0
    for j in i_bin:
        if j == "1":
            C[i][k] += 1 
            B[k] += 1
        k += 1
B = np.array(B)
for p in range(N-1):
    temp = np.array(C[p])
    B -= temp
    for q in range(60):
        if temp[q] == 1:
            ans += (N - (p + 1) - B[q]) * 2 ** q
            ans %= 7 + 10 ** 9
        else:
            ans += B[q] * 2 ** q
            ans %= 7 + 10 ** 9
print(ans)

Submission status: Wrong Answer

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

for i in range(60):
    # assert np.count_nonzero(arr & 1) == np.sum(arr & 1)
    c1 = np.sum(arr & 1)
    s += 2 ** i * c1 * (n - c1)
    arr >>= 1
print(s % mod)

Submission status: Wrong Answer

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

for i in range(60):
    c1 = round(np.sum(arr & 1))
    s += 2 ** i * c1 * (n - c1)
    arr >>= 1
print(s % mod)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
 
n = int(input())
lst = [int(i) for i in sys.stdin.readline().split()]
arr = np.array(lst, np.int64)

mod = 10 ** 9 + 7
x_sum = 0

for i in range(60):
    c1 = np.sum(arr & 1)
    x_sum += (c1 * (n - c1) * 2 ** i)
    x_sum %= mod
    arr >>= 1
print(x_sum)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
 
n = int(input())
lst = [int(i) for i in sys.stdin.readline().split()]
arr = np.array(lst, np.int64)

mod = 10 ** 9 + 7
x_sum = 0

for i in range(60):
    c1 = sum(arr & 1)
    x_sum += (c1 * (n - c1) * 2 ** i)
    x_sum %= mod
    arr >>= 1
print(x_sum)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
 
n = int(input())
lst = np.array([int(i) for i in sys.stdin.readline().split()])

mod = 10 ** 9 + 7
x_sum = 0

for i in range(60):
    c1 = sum(lst & 1)
    x_sum += (c1 * (n - c1) * 2 ** i)
    x_sum %= mod
    lst >>= 1
print(x_sum)

Submission status: Wrong Answer

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

sum = 0
for i in range(0, 10000):
    zc = 0
    oc = 0

    idsum = 0
    for j in range(0, n):
        if (arr[j] % 2 == 0):
            zc = zc + 1
        else:
            oc = oc + 1
        arr[j] = int(arr[j] / 2)

    idsum = oc * zc * (1 << i)

    sum = sum + idsum

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
 
n = int(input())
lst = np.array([int(i) for i in sys.stdin.readline().split()])

mod = 10 ** 9 + 7
c = []

for i in range(60):
    c1 = sum(lst & 1)
    c.append(c1 * (n - c1))
    lst >>= 1
print(sum([v * 2 ** i for i, v in enumerate(c)]) % mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
import numpy as np
A = np.array(list(map(lambda x:list('{:060b}'.format(int(x))),input().split())))
ans = 0
mod = 10**9+7
ones = np.sum(A == '1', axis=0) 
xor = ones * (np.array([n for i in range(60)]) - ones)
xor *= np.array([2**i for i in range(59,-1,-1)])
print(np.sum(xor)%mod)

Submission status: Wrong Answer

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

sum = 0
for i in range(0, 100):
    zc = 0
    oc = 0

    idsum = 0
    for j in range(0, n):
        if (arr[j] % 2 == 0):
            zc = zc + 1
        else:
            oc = oc + 1
        arr[j] = int(arr[j] / 2)

    idsum = oc * zc * (2 ** i)

    sum = sum + idsum

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

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
lst = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
c = []

for i in range(60):
    c1 = sum(lst & 1)
    c.append(c1 * (n - c1))
    lst >>= 1
print(sum([v * 2 ** i for i, v in enumerate(c)]) % mod)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input()) 
A =[list(bin(int(i))[2:].zfill(60)) for i in input().split()] 
keta = np.array([2**(59-i) for i in range(60)])
T = np.zeros((N,60))
for i in range(N):
  T[i] = list(map(int,A[i]))
S = np.sum(T, axis=0)
S = S*(N-S)
print(int(np.dot(S,keta)))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
lst = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
c = []

while lst.any():
    c1 = sum(lst & 1)
    c.append(c1 * (n - c1))
    lst >>= 1
print(sum([v * 2 ** i for i, v in enumerate(c)]) % mod)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    A = np.array(A, np.int64)
    ans = 0
    for i in range(60):
        bit = np.count_nonzero(A | 0)
        ans += bit * (N - bit) * (2 ** i)
        ans %= mod
        A >>= 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    A = np.array(A, np.int64)
    ans = 0
    for i in range(60):
        bit = np.count_nonzero(A | 0)
        ans += bit * (N - bit) * (2 ** i)
        ans %= mod
        A >>= 1
        print(ans)

if __name__ == '__main__':
    main()