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:
"""
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m, ans = 10**9 + 7, 0
    for s in map(lambda x: x.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
"""
import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    # a = ["{:060b}".format(_a) for _a in a]
    a = np.asarray(a, dtype=np.int64)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = (a & 1).sum()
        a >>= 1
        # s = "".join(d).count("1")
        # ans += s * (n - s) * pow(2, 59 - i, m)
        ans = (ans + s * (n - s) * (1 << i)) % m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    # a = ["{:060b}".format(_a) for _a in a]
    a = np.asarray(a, dtype=np.int64)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = (a & 1).sum()
        a >>= 1
        # s = "".join(d).count("1")
        # ans += s * (n - s) * pow(2, 59 - i, m)
        ans = (ans + s * (n - s) * pow(2, i, m)) % m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    # a = ["{:060b}".format(_a) for _a in a]
    a = np.asarray(a, dtype=np.int64)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = (a & 1).sum()
        a >>= 1
        # s = "".join(d).count("1")
        # ans += s * (n - s) * pow(2, 59 - i, m)
        ans += s * (n - s) * pow(2, i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    a = np.asarray(a, np.int64)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = (a & 1).sum()
        a >>= 1
        ans += s * (n - s) * pow(2, i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    # a = ["{:060b}".format(_a) for _a in a]
    a = np.asarray(a)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = (a & 1).sum()
        a >>= 1
        # s = "".join(d).count("1")
        # ans += s * (n - s) * pow(2, 59 - i, m)
        ans += s * (n - s) * pow(2, i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
import numpy as np


def solve(string):
    n, *a = map(int, string.split())
    a = np.asarray(a, int)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = (a & 1).sum()
        a >>= 1
        ans += s * (n - s) * pow(2, i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    return str(0)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    return str(0)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = [list(map(int, "{:060b}".format(_a))) for _a in a]
    m = 10**9 + 7
    ans = 0
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = [list(map(int, "{:060b}".format(_a))) for _a in a]
    m = 10**9 + 7
    ans = 0
    for d in zip(*a):
        s = sum(d)
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = [list(map(int, "{:060b}".format(_a))) for _a in a]
    m = 10**9 + 7
    print(a)
    ans = 0
    for i, d in enumerate(zip(*a)):
        ans += (sum(d) * (n - sum(d)) * 2**(59 - i)) % m
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
import numpy as np
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
A = np.array(A, dtype = np.int64)
tmp = 0
for i in range(61):
    tmp_1 = np.sum(A & 1)
    tmp += ((tmp_1)*(N - tmp_1)*(2**i)) % mod
    A = A >> 1
print(tmp % mod)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
A = np.array(A, dtype = np.int64)
tmp = 0
for i in range(61):
    tmp_1 = sum(A & 1)
    tmp += ((tmp_1)*(N - tmp_1)*(2**i)) % mod
    A = A >> 1
print(tmp % mod)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
A = np.array(A, dtype = np.int64)
tmp = 0
for i in range(61):
    tmp_1 = sum(A & 1)
    tmp += ((tmp_1)*(N - tmp_1)*(2**i)) % mod
    A >> 1
print(tmp % mod)

Submission status: Wrong Answer

Solution code:
import numpy as np
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
A = np.array(A, dtype = np.int64)
tmp = 0
for i in range(61):
    tmp_1 = np.sum((A >> i) & 1 )
    tmp += ((tmp_1)*(N - tmp_1)*(2**i)) % mod
print(tmp % mod)

Submission status: Wrong Answer

Solution code:
n = input()
l = list(map(int,input().split()))
ans = 0
for i in range(60):
    c0 = 0
    c1 = 0
    for s in l:
        s0 = format(s,"b").zfill(60)
        s0 = s0[::-1]
        if s0[i] == "1": c1 += 1
        else: c0 += 1
    ans += (c1*c0)*(2**i)
print(ans%10**9+7)

Submission status: Wrong Answer

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

sums=0
for i in range(0,len(e)):
  ai=e[i]
  for j in range(i+1,len(e)):
    aj=e[j]
    sums=sums+(ai^aj)
sums=sums%(10**9-7)

Submission status: Wrong Answer

Solution code:
n = int(input())
sl = list(map(int,input().split()))
l = []
for i in range(len(sl)):
    print(i)
    for j in range(i+1,len(sl)):
        l.append(sl[i]^sl[j])
print(sum(l)%((10**9)+7))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.readline
import numpy as np
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    ans = 0
    for a in A:
        ans += np.sum(A ^ a)
        ans %= MOD
    print(ans // 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
l = [int(x) for x in raw_input().split()]
ret = 0
for bit in xrange(62):
  num = sum([(l[i] & (1 << bit)) > 0 for i in xrange(n)])
  ret += num * (n - num) * bit
print ret % 1000000007

Submission status: Wrong Answer

Solution code:
N = int(input())
A = tuple(map(int,input().split()))
A_1 = A[:-1]
A_2 = A[1:]
b = 0
num = 1000000007
for i in A_1:
    for j in A_2:
        b += i ^ j
print(b%num)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
S=[0]*60

for i,a in enumerate(A):
  c=0
  while a>0:
    if a&1!=0:
      S[c]+=1
    a>>=1
    c+=1

s,c=0,0
while c<60:
  s+=S[c]*(N-S[c])*((2**c)%(10**9+7))
  c+=1

print(s)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        ans+=A[i]^A[j]%1000000007

print(ans%1000000007)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
arr=np.array([int(i) for i in input().split()])
def sumXOR(arr, n):
    MOD=int((1e+9)+7)
    summ = 0
    for i in range(0, 61):
        zc = 0
        oc = 0
        idsum = 0
        newarr=arr % 2
        oc = np.sum(newarr)
        zc = n-oc
        arr = arr//2
        idsum = (oc * zc * ((1 << i)%MOD))%MOD
        summ = (summ + idsum)%MOD
    return summ

ans = sumXOR(arr, n)
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()])
def sumXOR(arr, n):
    MOD=int((1e+9)+7)
    summ = 0
    for i in range(0, 61):
        zc = 0
        oc = 0
        idsum = 0
        newarr=arr % 2
        oc = np.sum(newarr)
        zc = n-oc
        arr = arr//2
        idsum = oc * zc * ((1 << i)%MOD)
        summ = (summ + idsum)%MOD
    return summ

ans = sumXOR(arr, n)
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()])
def sumXOR(arr, n):
    MOD=int((1e+9)+7)
    sum = 0
    for i in range(0, 61): 
        zc = 0
        oc = 0
        idsum = 0
        newarr=arr % 2
        oc = np.sum(newarr)
        zc = n-oc
        arr = arr//2
        idsum = oc * zc * (1 << i) 
        sum = (sum + idsum)%MOD
    return sum

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

Submission status: Wrong Answer

Solution code:

sum = 0
num = input()
list = [int(i) for i in input().split()]

list2 = [3,1,4,1,5,9,2,6,5,3]
#list2 = [1,2,3]

for i in range(len(list2)):
    for j in range(len(list2)):
        if i < j:
            sum += list2[i]^list2[j]

print(sum % 1000000007)

Submission status: Wrong Answer

Solution code:
N = int(input())
from collections import defaultdict
d = dict()
d[0] = defaultdict(int)
d[1] = defaultdict(int)
for i in map(int,input().split()):
  for idx,j in enumerate(reversed('{:b}'.format(i))):
    d[int(j)][idx]+=1

m = max(set(d[0].keys()) | set(d[1].keys()) )

A=1
res=0
for i in range(m+1):
  res += (A* (N-d[1][i])*d[1][i])%(1e9+7) 
  A = int((A*2)%(1e9+7))
  
print(int(res%(1e9+7)))

Submission status: Wrong Answer

Solution code:
nums = int(input())
a = list(map(int, input().split(" ")))
xor = 0

for i in range(0, nums - 1):
    for j in range(i + 1, nums):
       xor += a[i] ^ a[j]

print(xor)

Submission status: Wrong Answer

Solution code:
import sys
mod = int(1e9+7)
input=sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2


for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*pow(2, idx, mod)%mod

        else:
            ans += S[i+1][idx]*pow(2, idx, mod)%mod

        idx += 1
        tmp //= 2
        ans %= mod
    for x in S[i+1][idx:]:
        ans += x*pow(2, x, mod)%mod
        idx += 1
        ans %= mod

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
mod = 10**9+7
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
bi = [0]*60
for i in range(n):
  k = Base_10_to_n(L[i], 2).zfill(60)
  for j in range(60):
    if k[j] == '1':
      bi[j] += 1
ans = 0
for i in range(60):
  ans += ((2**i)*(bi[59-i]*(n-bi[59-i])))
  ans %= mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
mod = 10**9+7
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
bi = [0]*60
for i in range(n):
  k = Base_10_to_n(L[i], 2).zfill(60)
  for j in range(60):
    if k[j] == '1':
      bi[j] += 1
ans = 0
for i in range(60):
  ans += ((2**i)*(bi[59-i]*(n-bi[59-i])))
  ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
mod = 10**9+7
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
bi = [0]*60
for i in range(n):
  k = Base_10_to_n(L[i], 2).zfill(60)
  for j in range(60):
    if k[j] == '1':
      bi[j] += 1
ans = 0
for i in range(60):
  ans += ((2**i)*(bi[59-i]*(n-bi[59-i])))
  ans %= mod
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a=list(map(int,input().split()))
ma=len(bin(max(a)))-2
b=np.array(a)
zero=0
one=0
ans=0
for i in range(ma):
  one=np.count_nonzero((b&1)==1)
  zero=n-one
  ans+=one*zero*(2**i)
  b=b//2
print(ans)

Submission status: Wrong Answer

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

bin_a = [bin(x)[2:] for x in a]

max_length = len(max(bin_a, key=len))

for ind, num in enumerate(bin_a):
    if len(num) < max_length:
        bin_a[ind] = '0' * (max_length - len(num)) + bin_a[ind]

# print(bin_a, max_length)

result = 0
for i in range(max_length-1, -1, -1):
    oc = sum([int(x[i]) for x in bin_a])
    zc = n - oc
    # print(oc, zc)
    # print(no_of_ones)
    result += oc * zc * (2 ** (max_length - i - 1))


print(result)

Submission status: Wrong Answer

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

mm0 = [0 for i in range(61)]
mm1 = [0 for i in range(61)]

for i in range(n):
    for j in range(61):
        if (a[i]>>j)<0:
            break
        if (a[i]>>j)&1:
            mm1[j] += 1

for i in range(61):
    mm0[i] = n-mm1[i] 

ans = 0

for i in range(61):
    ttl = mm0[i]*mm1[i]
    ans += (1<<i)*ttl

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())

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

m = len(bin(max(a))) - 2

b = []
for i in range(n):
    b.append(list(map(int,list(bin(a[i])[2:].zfill(m)))))

c = list(itertools.combinations(b,2))

xor = []
for d in c:
    count = []
    for i in range(m):
        if d[0][i] != d[1][i]:
            count.append(1)
        else:
            count.append(0)
    xor.append(count)        

ans = 0
for e in xor:
    for k in range(m):
        ans += (2**k) * e[k] % (10**9 + 7)

print(ans)

Submission status: Wrong Answer

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

mod = 10**9+7

array = [0] * 60

for a in A:
    for j in range(len(bin(a))-2):
        print(a, j, a >> j, (a >> j) & 1)
        array[j] += (a >> j) & 1
ans = 0
for i in range(60):
    ans += array[i] * (n-array[i]) * 2**i
print(ans % mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
a = []
s = 0
for i in d:
  a.append((i, d[i]))
n = len(a)
for i in range(n -1):
  for j in range(i + 1, n):
    s += ((a[i][0] ^ a[j][0]) * (a[i][1] *a[j][1])) % 1000000007

Submission status: Wrong Answer

Solution code:
import numpy as np

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

result = 0
for b in np.arange(60):
  bs = int(((A >> b) & 1).sum())
  result = (result + bs * (N - bs) * (1 << b)) % 1000000007
print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

result = 0
for b in range(60):
  bs = ((A >> b) & 1).sum()
  result = (result + bs * (N - bs) * (1 << b)) % 1000000007
print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

result = 0
for b in range(60):
  bs = ((A >> b) & 1).sum()
  result = (result + bs * (N - bs) * (1 << b)) % 1000000007
print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

result = 0
for b in range(60):
  bs = ((A >> b) & 1).sum()
  result = (result + bs * (N - bs) * (1 << b)) % 1000000007
print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np
M = 10**9+7
N = int(input())
A = np.array(list(map(int,input().split())),dtype='int64')
ans = 0

maxA = np.amax(A)
K = len(str(bin(maxA)))-2

for k in range(K):
    N1 = 0
    N1 = np.sum((A >> k) & 1)
    N0 = N-N1
    ans += (1<<k) *N0 *N1
    ans %= M

print(ans)

Submission status: Wrong Answer

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

maxA = np.amax(A)
K = len(str(bin(maxA)))-2

for k in range(K):
    N1 = 0
    N1 = np.sum((A >> k) & 1)
    N0 = N-N1
    ans += (((1<<k)%M) *N0 *N1) % M
    ans %= M

print(ans)

Submission status: Wrong Answer

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

maxA = np.amax(A)
K = len(str(bin(maxA)))-2

for k in range(K):
    N1 = 0
    N1 = np.sum((A >> k) & 1)
    N0 = N-N1
    ans += (((1<<k)) *N0 *N1)
    ans %= M

print(ans)

Submission status: Wrong Answer

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

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

for k in range(K):
    N1 = 0
    for i in range(N):
        N1 += ( (A[i] >> k) & 1)
    N0 = N-N1
    ans += (((1<<k)) *(N-N1) *N1)
    ans %= M

print(ans)

Submission status: Wrong Answer

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

ans = 0
m = 1
for _ in range(60):
    bits = sum((a & m for a in A))
    print(bits)
    bits //= m
    ans += (bits * (N - bits) * m)
    ans %= MOD
    m <<= 1
print(ans % MOD)

Submission status: Wrong Answer

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

#output
import numpy as np
A = np.array(A, int)

answer = 0
for a in A:
    answer += sum(a^A)

answer //= 2

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

Submission status: Wrong Answer

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

#output
import numpy as np
A = np.array(A, int)

answer = 0
for a in A:
    answer += np.sum(a^A)

answer //= 2

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

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False

# xor
# n + i = n ^ i implies n & i = 0


def sumXOR(arr,  n):
    _sum = 0
    for i in range(0, 64):
        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] = arr[j] >> 1

        # calculating individual bit sum
        idsum = oc * zc * (1 << i)
        print(zc, oc, idsum)

        # final sum
        _sum = _sum + idsum
        _sum %= MOD

    return _sum


def main():
    N = I()
    A = list(MI())
    BIT = 61
    C = [[0] * (N+1) for i in range(BIT)]
    AC = [None for i in range(BIT)]
    ans = 0

    for i in range(N):
        for j in range(BIT):
            bit = 1 << j
            if A[i] & bit:
                C[j][i+1] = C[j][i] + 1

    for i in range(N):
        for j in range(BIT):
            oc = C[j][N] - C[j][i]
            bit = 1 << j
            # print('b', ans, i, j, bit, oc)
            if A[i] & bit:
                zc = N - i - oc
                ans += bit * zc
            elif oc != 0:
                ans += bit * oc
            ans %= MOD
            # print('a', ans, i, j, bit, oc)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False

# xor
# n + i = n ^ i implies n & i = 0


def sumXOR(arr,  n):
    _sum = 0
    for i in range(0, 64):
        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] = arr[j] >> 1

        # calculating individual bit sum
        idsum = oc * zc * (1 << i)
        print(zc, oc, idsum)

        # final sum
        _sum = _sum + idsum
        _sum %= MOD

    return _sum


def main():
    N = I()
    A = list(MI())
    BIT = 60
    C = [[0] * N for i in range(BIT)]
    AC = [None for i in range(BIT)]
    ans = 0

    for i in range(N):
        for j in range(BIT):
            bit = 1 << j
            if A[i] & bit:
                C[j][i] = 1

    for j in range(BIT):
        AC[j] = list(accumulate([0] + C[j]))

    for i in range(N):
        for j in range(BIT):
            oc = AC[j][N] - AC[j][i]
            zc = N - i - oc
            bit = 1 << j
            bit %= MOD
            # print('b', ans, i, j, bit, oc)
            if A[i] & bit:
                ans += bit * zc
            elif oc != 0:
                ans += bit * oc
            ans %= MOD
            # print('a', ans, i, j, bit, oc)

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


length = int(fetch_one_line())
nums = fetch_int_input()

bit_nums = [bin(i)[2:] for i in nums]
max_length = max([len(i) for i in bit_nums])

def bai(i):
    i[0] *= 2
    return i[0]

tmp = [1/2]
bit_nums = list(zip(*[list(i.zfill(max_length)) for i in bit_nums]))
sum_ones = [lst.count("1") for lst in bit_nums]
multiples = [i * (length - i) for i in sum_ones]

result = sum([bai(tmp) * m for m in reversed(multiples)])
print(result % (pow(10, 9) + 7))

Submission status: Wrong Answer

Solution code:

def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    mod = 10 ** 9 + 7

    sum = 0

    for i in range(60):
        count_1 = 0
        for a in a_list:
            try:
                if format(a, "b")[59-i] == "1":
                    count_1 += 1
            except:
                pass

        sum += 2 ** i * count_1 * (N - count_1)

    print(sum % mod)


if __name__ == '__main__':
    main()

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

answer = 0
for i in range(60):
    n_ones = (A & 1).sum()
    answer += 2 ** i * (n - n_ones) * n_ones
    A >>= 1

print(answer % MOD)

Submission status: Wrong Answer

Solution code:
import numpy as np

if __name__ == '__main__':
    n = int(input())
    A = np.array(list(map(int, input().split())))

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

    print(ans % mod)

Submission status: Wrong Answer

Solution code:
import numpy as np

mod = 10 ** 9 + 7
ans = 0
if __name__ == '__main__':
    n = int(input())
    A = np.array(list(map(int, input().split())))

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

    print(ans % mod)

Submission status: Wrong Answer

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

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

bit_zero = [0]*L
bit_one = [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] == "0":
			bit_zero[j] += 1
		else:
			bit_one[j] += 1

ans = 0
for i in range(L):
	zero = bit_zero[i] % mod
	one = bit_one[i] % mod
	c = (zero * one) % mod
	t = 1
	for _ in range(L-i-1):
		t *= 2
		t %= mod
	ans += (c*t) % mod
	ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ma=max(a)
ct=0
while ma>0:
  ma//=2
  ct+=1
lis=[0 for _ in range(ct)]

for i in range(n):
  digit=ct
  while digit>0:
    if a[i] >= 2**(digit-1):
      a[i]-=2**(digit-1)
      lis[digit-1]+=1
    digit-=1

lis2=[n-x for x in lis]
ans=0
for i in range(ct):
  ans+=lis[i]*lis2[i]*2**i
print(ans)

Submission status: Wrong Answer

Solution code:
#147d
import itertools

N = int(input())
A_list = [int(e) for e in input().split()]

MOD_BY = 7 + 10**9

#愚直解
ans = 0

for i in range(len(A_list)-1):
    temp_ans = 0
    for j in range(i + 1,len(A_list)):
        temp_ans += A_list[i]^A_list[j]
    
print(ans%MOD_BY)

Submission status: Wrong Answer

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

ans = 0
i = 0

for i in range(N-1):
  j = i+1
  for j in range(i+1,N):
    ans += A[i] ^ A[j]
    print(ans)
    
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())))

ans=0

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

print(ans%10**9+7)

Submission status: Wrong Answer

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

ans=0

for i in range(60):
    cnt=len([i for i in range(n) if A[i]&1])
    ans +=2**i*cnt*(n-cnt)
    A=[A[i]>>1 for i in range(n)]

print(ans%10**9+7)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
s=[0]*61
for i in range(n):
  c=format(a[i], 'b')
  L=len(c)
  for j in range(L)[::-1]:
    s[L-j-1]+=int(c[j])
ans=0
for i in range(61)[::-1]:
  ans+=2**(i)*(s[L-i-1])*(n-s[L-i-1])
  ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])
inf = 10**9+7

ans = 0
p = 1
for i in range(61):
    a, b = a//2, a%2
    key = np.sum(b)
    ans += p*(n-key)*key
    ans = ans%inf
    p *= 2
    p %= inf
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])
inf = 10**9+7

ans = 0
p = 1
for i in range(60):
    a, b = divmod(a, 2)
    key = np.sum(b)
    ans += p*(n-key)*key
    ans = ans%inf
    p *= 2
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])
inf = 10**9+7

ans = 0
p = 1
for i in range(62):
    a, b = divmod(a, 2)
    key = np.sum(b)
    ans += p*(n-key)*key
    ans = ans%inf
    p *= 2
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])
inf = 10**9+7

ans = 0
p = 1
for i in range(61):
    a, b = divmod(a, 2)
    key = np.sum(b)
    ans += p*(n-key)*key
    ans = ans%inf
    p *= 2
print(ans)

Submission status: Wrong Answer

Solution code:
N = 60
MOD = 10**9 + 7
n = int(input())
c0 = [0 for _ in range(N)]
c1 = [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:
            c1[j] -=1
    for j in range(N):
        if a[i] & (1 << j) == 0:
            ans += (1<<j) * c0[j]
        else:
            ans += (1<<j) * c1[j]

print(ans % MOD)