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=int(input())
mod=10**9+7
l=list(map(int,input().split()))
d=len(str(bin(max(l))))-2
ll=[[0,0] for i in range(d)]
ans=0
for i in l:
  f=bin(i)[2:]
  for v in range(len(f)):
    ll[-1-v][int(f[v])]+=1
for i,(a,s) in enumerate(ll):
  ans+=pow(2,i,mod)*a*s%mod
  ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
mod=10**9+7
l=list(map(int,input().split()))
d=len(str(bin(max(l))))-2
ll=[[0,0] for i in range(d)]
ans=0
for i in l:
  f=bin(i)[2:]
  for v in range(len(f)):
    ll[v][int(f[v])]+=1
for i,(a,s) in enumerate(ll):
  ans+=pow(2,i,mod)*a*s%mod
  ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
mod=10**9+7
l=list(map(int,input().split()))
d=len(str(bin(max(l))))-2
ll=[[0,0] for i in range(d)]
ans=0
for i in l:
  f=bin(i)[:1:-1]
  for v in range(len(f)):
    ll[-1-v][int(f[v])]+=1
for i,(a,s) in enumerate(ll):
  ans+=pow(2,i,mod)*a*s%mod
  ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
mod=10**9+7
l=list(map(int,input().split()))
d=len(str(bin(max(l))))-2
ll=[[0,0] for i in range(d)]
ans=0
for i in l:
  f=bin(i)[:1:-1]
  for v in range(len(f)):
    ll[v][int(f[v])]+=1
for i,(a,s) in enumerate(ll):
  ans+=(2**i)*a*s%mod
  ans%=mod
print(ans)

Submission status: Wrong Answer

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

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

for i in range(0, len(A)):
    _a = A[i]
    for j in range(len(li))[::-1]:
        quo = _a // pow(2, j)
        li[j] += quo
        _a -= quo*pow(2, j)


res = 0
print(li)
for i in range(len(li)):
    res += (pow(2, i) * (li[i]*(N-li[i])))%MOD
    res %= MOD
print(res)

Submission status: Wrong Answer

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()

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

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()

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):
    result += ((a * (n-a)) * 2**(59-i)) % mod
    result = result % mod

#print(num1)
#print(result)

Submission status: Wrong Answer

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

ans = 0
M = 10**9+7
for i in range(60):
    for j in range(N):
        x = 0
        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: Wrong Answer

Solution code:
n = int(input())
alist = list(map(int,input().split()))
anslist = []
for i in range(n):
  for j in range(i+1,n):
    anslist.append(alist[i]^alist[j])
print(sum(anslist))

Submission status: Wrong Answer

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

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(sum(ad))
    A = A // 2
ans = 0
for i in range(60):
    num0 = N - cnt[i]
    num1 = cnt[i]
    ans += (num0 * num1) * (2 ** i)
print(ans % MOD)

Submission status: Wrong Answer

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(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)
print(ans % MOD)

Submission status: Wrong Answer

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(np.sum(ad))
    A = A // 2
ans = 0
for i in range(60):
    num0 = N - cnt[i]
    num1 = cnt[i]
    ans += ((N * (N - 1) // 2) - (num0 * (num0 - 1) // 2) - (num1 * (num1 - 1) // 2)) * (2 ** i)
print(ans % MOD)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
mod = 10**9+7

N = int(raw_input())

num0 = [0]*61
num1 = [0]*61

A = map(int, raw_input().split())

for i in range(N):
    ai = A[i]
    for j in range(61):
        if ai & 1 << j:
            num1[j] += 1
        else:
            num0[j] += 1
ans = 0

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

print int(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

total = 0
mod = 10 ** 9 + 7
ls = []
max_length = len(bin(max(A))) - 2
print(max_length)
for i in range(max_length+1):
    d = {0: 0, 1: 0}
    ls.append(d)
for i in range(N):
    idx = 0
    for j in range(max_length + 1):
        try:
            b = int(bin(A[i])[-j - 1])
        except Exception:
            b = 0
        ls[j][b] += 1
        idx += 1

ans = 0
for i in range(len(ls)):
    zero = ls[i][0]
    one = ls[i][1]
    ans += zero*one * 2**i
    ans %= mod
print(ans)

Submission status: Wrong Answer

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.sum(A >> i & 1) % mod
    ans += 2 ** i * bit * (N - bit)
    ans %= mod
    
print(ans)

Submission status: Wrong Answer

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

ans = 0
mod = 10 ** 9 + 7

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

print(ans)

Submission status: Wrong Answer

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

bit_nums = [0 for _ in range(K)]
ans = 0
mod = 10 ** 9 + 7

for i in range(K):
    bit_nums[i] = np.sum(A >> i & 1)
    
ans = 0
for i in range(K):
    ans += (2 ** i) * (bit_nums[i] * (N - bit_nums[i]))
    ans %= mod

print(ans)

Submission status: Wrong Answer

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

bit_nums = [0 for _ in range(K)]
ans = 0
mod = 10 ** 9 + 7

for i in range(K):
    bit_nums[i] = np.sum(A >> i & 1)
    
ans = 0
for i in range(K):
    ans += (2 ** i) * (bit_nums[i] * (N - bit_nums[i]))
    ans %= mod
  
print(ans)

Submission status: Wrong Answer

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

bit_nums = [0 for _ in range(K)]
ans = 0
mod = 10 ** 9 + 7

for i in range(K):
    bit_nums[i] = np.sum([A >> i & 1])
    
ans = 0
for i in range(K):
    ans += (2 ** i) * (bit_nums[i] * (N - bit_nums[i]))
    ans %= mod
  
print(ans)

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
cnt = [100 for i in range(60)]
mod = 10 ** 9 + 7

# for i in A:
#     tmp = format(i, '060b')
#     for j in range(60):
#         if tmp[j] == "1":
#             cnt[j] += 1

ans = 0

lst = [1 for i in range(60)]

for i in range(59):
    lst[58-i] = (lst[59-i] * 2) % mod

for i in range(60):
    ans += (lst[i] * cnt[i] * (N -cnt[i])) % mod
    
ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
cnt = [0 for i in range(60)]
mod = 10 ** 9 + 7

for i in A:
    tmp = format(i, '060b')
    for j in range(60):
        if tmp[j] == "1":
            cnt[j] += 1

ans = 0

lst = [1 for i in range(60)]

for i in range(59):
    lst[58-i] = (lst[59-i] * 2) % mod

for i in range(60):
    ans += (lst[i] * cnt[i] * (N -cnt[i])) % mod

print(ans)

Submission status: Wrong Answer

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

for i in A:
    tmp = format(i, '060b')
    for j in range(60):
        if tmp[j] == "1":
            cnt[j] += 1

ans = 0
for i in range(60):
    ans += (2 ** (59-i)) * cnt[i] * (N -cnt[i])

print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0
    for i in range(60):
        # count = 0
        # b = []
        # b = [1 if a[j] & (1 << i) == 2 ** i else 0 for j in range(n)]
        b = [a[j] & (1 << i) for j in range(n)]
        count = sum(b)
        # for j in range(n):
        #     b = [1 if a[j] & (1 << i) == 2**i else 0 for j in range(n)]
        #     if a[j] & (1 << i) == 2**i:
        #         count += 1
        # ans += (2**i) * (count * (n - count))
        ans += count * (n - (count/ (2**i)))

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

Submission status: Wrong Answer

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

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
print(ans//2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
n = int(input())
a = list(map(int,input().split()))
ans = 0
mod = (10**9 +7)
for j in range(61):# 2**j 桁に対して1なものの数を求める
    num_one = 0
    for i in range(len(a)):
        if a[i] & 1 << i: 
            num_one += 1
    # num_one = sum(1 for j in a if 1 << i & j == 1)
    #print(j,num_one)
    ans += (2**j % mod) * (n-num_one)*(num_one) % mod
    #print(ans)
print(ans%mod)

Submission status: Wrong Answer

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

for i in range(60):
  x=0
  for j in range(N):
    if A[j]>>i&1: x+=1
  ans+=x*(N-x)*(2**i)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
s=0
for i in range(N-1):
  s+=sum([A[i]^a for a in A[i+1:]])
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
keta = len(bin(max(A))) - 2
ans = 0
shift = 0
for _ in range(keta):
    num_1 = 0
    for a in A:
        if a&1:
            num_1 += 1
        a=a>>1
    ans += num_1 * (N-num_1) * 2 ** shift
    shift += 1
print(ans % INF)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
keta = len(bin(max(A))) - 2
ans = 0
shift = 0
num_1 = 0
for _ in range(keta):
    
    for a in A:
       num_1=1 if a>>shift&1 else 0
    ans += num_1 * (N-num_1) * 2 ** shift
    shift += 1
print(ans % INF)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ans = 0
for i in range(n):
    ans+=np.sum(np.bitwise_xor(a,a[i]))

print((ans // 2) % mod)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ans = 0
for i in range(n):
    ans+=np.sum(np.bitwise_xor(a,a[i]))
print((ans//2) % mod)

Submission status: Wrong Answer

Solution code:
import numpy as np
mod = 10**9+7
n = int(input())
a = np.fromstring(input(), dtype = np.int64, sep = ' ')

result = 0
for i in range(60):
    count_one = (a&1).sum()
    result += count_one*(n-count_one)*(2**i)
    a >>= 1
print(result%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())))

result = 0
for i in range(60):
    count_one = sum(a&1)
    result += count_one*(n-count_one)*(2**i)%mod
    a = a >> 1
print(result%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())))

result = 0
for i in range(62):
    count_one = sum(a&1)
    result += count_one*(n-count_one)*(2**i)%mod
    a = a >> 1
print(result%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())))

result = 0
for i in range(62):
    count_one = sum(a%2)
    result += count_one*(n-count_one)*(2**i)%mod
    a = a >> 1
print(result%mod)

Submission status: Wrong Answer

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

b = [format(x,'b').zfill(60) for x in a]
b = [list(reversed(x)) for x in b]


ones = [0 for i in range(60)]
for x in b:
    for i in range(60):
        if x[i]=='1':
            ones[i] += 1

pow_two = [pow(2,i,mod) for i in range(60)]

ans = 0
for x in b:
    for i in range(60):
        if x[i]=='0':
            ans += ones[i]*pow_two[i]
        else:
            ans += (n-ones[i])*pow_two[i]
    ans %= mod

print(ans//2)

Submission status: Wrong Answer

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

b = [format(x,'b').zfill(60) for x in a]
b = [list(reversed(x)) for x in b]


ones = [0 for i in range(60)]
for x in b:
    for i in range(60):
        if x[i]=='1':
            ones[i] += 1

ans = 0
for x in b:
    for i in range(60):
        if x[i]=='0':
            ans += ones[i]*pow(2,i,mod)
        else:
            ans += (n-ones[i])*pow(2,i,mod)
    ans %= mod

print(ans//2)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
ar=[0]*60
for i in a:
  for j in range(60):
    if i&(1<<j):
      ar[j]+=1


for i ,j in enumerate(ar):
  b=n-j
  ans+= j*b*1<<i

print(ans)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = map(int, input().split())
p = 7 + 10**9
b = 60

x = np.array([tuple(map(int, bin(ai)[2:].zfill(b))) for ai in a])

s = np.count_nonzero(x, axis=0)

pow2 = (2 ** np.array(list(range(b)), np.int64))[::-1]

ans = s%p * (n-s)%p * (pow2%p)
print(np.sum(ans) % p)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
p = 7 + 10**9
b = 60

x = np.zeros((n, b), np.int)
for i in range(n):
    x[i] = np.array(list(bin(a[i])[2:].zfill(b)), int)

s = np.sum(x, axis=0)

pow2 = (2 ** np.array(list(range(b)), np.int64))[::-1]

ans = s * (n - s) * pow2
print(np.sum(ans) % p)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
p = 7 + 10**9
b = 60

x = np.zeros((n, b), np.int)
for i in range(n):
    x[i] = np.array(list(bin(a[i])[2:].zfill(b)), int)

s = np.sum(x, axis=0)

pow2 = (2 ** np.array(list(range(b)), np.int64))[::-1]

ans = s * (n - s) * pow2
print(np.sum(ans))

Submission status: Wrong Answer

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


b = [tuple(map(int, format(i, "061b"))) for i in a]
bits1 = np.array(b)
bits0 = bits1 ^ 1

accum1 = np.add.accumulate(bits1[::-1])[::-1]
accum0 = np.add.accumulate((bits0)[::-1])[::-1]

sum1 = bits1[:-1] * accum0[1:]
sum0 = bits0[:-1] * accum1[1:]

sumall = np.sum(sum1, axis=0) + np.sum(sum0, axis=0)
ans = sumall * (2 ** np.array(list(range(61)), np.int64))[::-1] % p

print(np.sum(ans) % p)

Submission status: Wrong Answer

Solution code:
import numpy as np 
n=int(input())
a=np.array(list(map(int, input().split())))
sum=0
i=0
while a.any():
  x= np.count_nonzero(a & 1)
  sum+=x*(n-x)<<i
  a>>=1
  i+=1
  
print(int(sum%(1e9+7)))

Submission status: Wrong Answer

Solution code:
import numpy as np 
n=int(input())
a=np.array(list(map(int, input().split())))
sum=0
for i in range(60):
  x= np.count_nonzero(a>>i & 1)
  sum+=x*(n-x)<<i
print(int(sum%(1e9+7)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
sum=0
for i,ii in enumerate(a[:-1]):
  for j in a[i+1:]:
    sum+=ii^j
print(int(sum%(1e9+7)))

Submission status: Wrong Answer

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

LARGE = 10 ** 9 + 7

shift = 0
total = 0
while A.any():
    bits = (A & 1).sum()
    total += (bits * (N - bits)) << shift
    A >>= 1
    shift += 1

print(total % LARGE)

Submission status: Wrong Answer

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

b = [tuple(map(int, format(i, "060b"))) for i in a]
bits1 = np.array(b)
bits0 = bits1 ^ 1

accum1 = np.add.accumulate(bits1)
accum0 = np.add.accumulate(bits0)

sum1 = bits1[-1:0:-1] * accum0[-2::-1]
sum0 = bits0[-1:0:-1] * accum1[-2::-1]

s1 = np.sum(sum1, axis=0)
s0 = np.sum(sum0, axis=0)

ans = (s1 + s0) * (2 ** np.array(tuple(range(59,-1,-1)), np.int64)) % p

print(np.sum(ans) % p)

Submission status: Wrong Answer

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


# TLE
def xor(ai, a): return list(map(lambda x: x^ai, a))
def naive():
    ans = 0
    for i in range(n-1):
        ans += sum(xor(a[i], a[i+1:]))
    print(ans % p)


# MAIN
b = [tuple(map(int, format(i, "060b"))) for i in a]
bits1 = np.array(b)
bits0 = bits1 ^ 1

accum1 = np.add.accumulate(bits1[::-1])[::-1]
accum0 = np.add.accumulate((bits0)[::-1])[::-1]

sum1 = bits1[:-1] * accum0[1:]
sum0 = bits0[:-1] * accum1[1:]

sumall = np.sum(sum1, axis=0) + np.sum(sum0, axis=0)
ans = sumall * (2 ** np.array(list(range(60)), np.int64))[::-1] % p

print(np.sum(ans) % p)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())), dtype="int64")
p = 7 + 10**9

ans = 0

for i in range(n-1):
    ans += np.sum(a[i+1:] ^ a[i]) % p

print(ans % p)

Submission status: Wrong Answer

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

    res = 0
    bits = [[0]*2 for _ in range(60)]
    for a in al:
        i = 0
        while a > 0:
            bits[i][a&1] += 1
            a = a >> 1
            i += 1

    res = 0

    for i in range(60):
        res += bits[i][0] * bits[i][1]  * (2 ** i)

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
ba = [format(i,'b').zfill(60) for i in a]
mod = 10**9+7

#2^iをmodで割った余りを出しておく
twos = np.ones(60)
for i in range(1,60):
    twos[i] = (twos[i-1]*2)%mod


#各baのbitごとに0の個数を求める
c0 = np.zeros(60)
"""
for i in range(n):
    ins0 = list(format(a[i],'b').zfill(60))
    ins1 = np.array(ins0,dtype=int)
    c0 += ins1
"""

#答えは各bitごとの(0の数)*(1の数)より求まる
ans = 0
for i in range(60):
    ans += (((c0[59-i]*(n-c0[59-i]))%mod)*twos[i])%mod

ans %= mod
print(int(ans))

Submission status: Wrong Answer

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

#2^iをmodで割った余りを出しておく
twos = np.ones(60)
for i in range(1,60):
    twos[i] = (twos[i-1]*2)%mod


#各baのbitごとに0の個数を求める
c0 = np.zeros(60)
"""
for i in range(n):
    ins0 = list(format(a[i],'b').zfill(60))
    ins1 = np.array(ins0,dtype=int)
    c0 += ins1
"""

#答えは各bitごとの(0の数)*(1の数)より求まる
ans = 0
for i in range(60):
    ans += (((c0[59-i]*(n-c0[59-i]))%mod)*twos[i])%mod

ans %= mod
print(int(ans))

Submission status: Wrong Answer

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

#2^iをmodで割った余りを出しておく
twos = np.ones(60)
for i in range(1,60):
    twos[i] = (twos[i-1]*2)%mod

#各baのbitごとに0の個数と1の個数を求める
c0 = np.zeros(60)
for i in range(n):
    ins0 = list(format(a[i],'b').zfill(60))
    ins1 = np.array(ins0,dtype=int)
    c0 += ins1

#答えは各bitごとの(0の数)*(1の数)より求まる
ans = 0
for i in range(60):
    ans += (((c0[59-i]*(n-c0[59-i]))%mod)*twos[i])%mod

ans %= mod
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.reverse()
mod = 7 + 10**9
leng = len(format(max(a), 'b'))
bit_acc = [0 for i in range(leng)]
for i in range(n):
    #先頭から二進数を0埋めした
    bit_data = format(a[i], 'b').zfill(leng)
    for j in range(leng):
        if bit_data[j] == '1':
            bit_acc[j] += 1
ans = 0
for i in range(n):
    bit_data = format(a[i], 'b').zfill(leng)
    for j in range(leng):
        if bit_data[j] == '1':
            ans += (n - bit_acc[j]) * (2 ** (leng - j - 1))
        else:
            ans += bit_acc[j] * (2 ** (leng - j - 1))
        ans %= mod
print(ans // 2)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
m = len(bin(max(a)))-2
b = np.array([0]*m)
ans = 0
for i in range(n):
  b += np.array([(a[i] >> j) & 1 for j in range(m)])
for i in range(m):
  ans += ((2**i)*b[i]*(n-b[i]))%(10**9+7)
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())))

Cn, ans = N * (N-1) // 2, 0

for i in range(60):
    count = np.sum(A % 2)
    A //= 2
    if count == 0:
        continue
    ans += (Cn - (count*(count-1)//2 + (N-count)*(N-count-1)//2)) * (2**i)
print(ans % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
input_num = int(input())
N = list(map(int,input().rstrip().split()))
ans = 0
for i in range(60):
  bit_1 = 0
  bit_0 = 0
  for i2 in range(input_num):
    if N[i2] % (2 ** i) == 0:
      bit_0 += 1
    else:
      N[i2] -= (2 ** (i - 1))
      bit_1 += 1
  ans += bit_0 * bit_1 * (2 ** (i - 1))
print(int(ans % ((10 ** 9) + 7)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
mod = 10**9+7
SUM = 0

maxA = max(A)
d = 0
while 1:
    if maxA < 2**d:
        break
    d += 1

BitA = [[0]*d for _ in range(N)]
for i in range(N):
    for j in range(d):
        BitA[i][j] = int(bin(A[i]|2**d)[3+j])

BitSumB = 0
for i in range(d):
    tmp = sum([BitA[j][i] for j in range(N)])
    BitSumB += 2 ** (d-i-1) * (tmp * (N - tmp))

print(BitSumB)

Submission status: Wrong Answer

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

sum_ = 0
for i in range(n-1):
  for j in range(i,n):
    sum_ += a[i] ^ a[j]
print(int(sum_%(1e9+7)))

Submission status: Wrong Answer

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

import numpy

MAX = 10**9 + 7

def main():
  n = int(input())
  As = map(int, input().strip().split())
  counts = numpy.zeros(60)
  for A in As:
    i = 0
    while A:
      if A%2 == 1:
        counts[-(i+1)] += 1
      A >>= 1
      i += 1
  print(int(sum([(n-count) * count * (2**(60-(i+1)) % MAX) for i, count in  enumerate(counts)])) % MAX)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7
ans = 0
m = 1
ans = 0
for _ in range(60):
    one_count = 0
    for a in aaa:
        one_count += (a & m) // m
    zero_count = n - one_count
    ans += (one_count * zero_count * m)
    m *= 2
        
print(ans)

Submission status: Wrong Answer

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

def two(s):
  b = bin(s)[2:]
  b = "0"*(U-len(b)) + b
  return list(b)

n = int(input())
A = list(map(int, input().split()))
C = np.zeros(U, dtype=np.int64)
T = np.array([1<<i for i in range(U)])
for i in A:
  C += np.array(two(i)[::-1], dtype=np.int64)
ans = (T * ((n-C) * C)).sum()
print(ans%MOD)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
# all_sum = 0
# for i in range(n):
#     for j in range(i+1, n):
#         # print("i:{}, j:{}, xor:{}".format(i, j, a_list[i] ^ a_list[j]))
#         mod_num = (a_list[i] ^ a_list[j]) % (10 ** 9 + 7)
#         all_sum += mod_num

# print(all_sum % (10 ** 9 + 7))

# 結果の数
result_num = 0

# ある桁について考える
for i in range(1, 61):
    zero_count = 0
    one_count = 0
    for a in a_list:
        i_num = str(bin(a))[2:].zfill(60)[-1 * i]
        if int(i_num) == 0:
            zero_count += 1
        else:
            one_count += 1
    result_num += 2 ** (i-1) * zero_count * one_count 
    result_num &= (10 ** 9 + 7)
print(result_num % (10 ** 9 + 7))

Submission status: Wrong Answer

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

all_sum = 0
for i in range(n):
    for j in range(i+1, n):
        # print("i:{}, j:{}, xor:{}".format(i, j, a_list[i] ^ a_list[j]))
        mod_num = (a_list[i] ^ a_list[j]) % (10 ** 9 + 7)
        all_sum += mod_num

print(all_sum)

Submission status: Wrong Answer

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):
    for j in range(60):
        d1[i+1][j] = d1[i][j]
        if n%(2**(j+1)):
            d1[i+1][j] += 1
        n //= 2

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

        if n%(2**(j+1)):
            ans += (b*(2**j))%mod
        else:
            ans += (a*(2**j))%mod
        n //= 2

print(ans%mod)

Submission status: Wrong Answer

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]
    A[i] >>= 1
    c0 += (a==0)
  
  result = (result + (base*(N - c0)*c0) % MOD) % MOD
  base = base*2 % MOD

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

mod = 10**9+7

ans = 0
for i in range(0,n-1):
    for j in range(i,n):
        ans += ( a[i] ^ a[j] ) % mod

print(ans)

Submission status: Wrong Answer

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

def main():
    N = int(input())
    INF = 10**9+7
    A = list(map(int,input().split()))
    M = max(A)
    l = M.bit_length()
    d = np.array([[0,0] for _ in range(l)])
    for i in range(N):
        num = A[i]
        count = 0
        while count != l:
            use = num%2
            d[count][use] += 1
            num //= 2
            count += 1
        
    ans = 0    
    for i in range(l):
        x,y = d[i]
        ans += (x*y)*(2**i)
        ans %= INF
        
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(lambda x:format(int(x), '060b') , input().split()))
n1 = [0]*60
for i in a:
  for j in range(60):
    if i[59-j]=='1':
      n1[j] += 1
over = 0
for i in range(60):
  tmp = n1[i]*(n-n1[i])+over
  n1[i] = tmp%2
  over = tmp//2
bin_str = ''
for i in n1[::-1]:
  bin_str += str(i)
print(int(bin_str, 2)%(10**9+7))

Submission status: Wrong Answer

Solution code:
a=int(input())
l=input().split()
count=0
# N=0
for i in range(a):
    for j in range(1,a-i):
        count+=int(l[i])^int(l[a-j])
        # N+=1
        # print(N,"回目")
        # print(l[i],"^",l[a-j],"=",int(l[i])^int(l[a-j]))

print(count)