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: Runtime Error

Solution code:
N=int(input())
import math
A=list(map(int,input().split()))
b=math.ceil(math.log2(max(A))) 
B=[0 for i in range(b)] #0のリスト
C=[0 for i in range(b)] #1のリスト
for i in A:
  for j in range(b):
    if ((i>>j) & 1):
      C[j]+=1
    else:
      B[j]+=1
 # print(B,C,i)
mod =10**9+7
ans=[(B[i]*C[i])*2**i % mod for i in range(b)]
print(sum(ans)%mod)

Submission status: Runtime Error

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

n = int(input())
a = np.array(read().split(), np.int64)

mod = 10 ** 9 + 7
ans = 0
b = [0] * len(a)

for i in range(61):
    for j in range(n):
        b[j] = (a[j] >> i) & 1
    x = len(b) - sum(b)
    y = n - x
    z = x * y
    z *= 2 ** i
    z %= mod
    ans += z
ans %= mod

print(ans)

Submission status: Runtime Error

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

N=int(input())
A=list(map(int,input().split()))
B=[x for x in set(A)]
ans=0
mod=(10**9)+7
if len(B)==N:
    for i in range(N-1):
        for j in range(i+1,N):
            ans+=A[i]^A[j]
else:
    C=[x for x in set(A) if A.count(x) > 1]
    for i in range(len(B)-1):
        for j in range(i+1,len(B)):
            if B[i] in C:
                if B[j] in C:
                    ans+=((A.count(B[i]))*(A.count(B[j])))*(B[i]^B[j])
                else:
                    ans+=(A.count(B[i]))*(B[i]^B[j])
            else:
                if B[j] in C:
                    ans+=(A.count(B[j]))*(B[i]^B[J])
                else:
                    ans+=B[i]^B[j]
ans=ans%mod
print(ans)

Submission status: Runtime Error

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

N=int(input())
A=list(map(int,input().split()))
B=[x for x in set(A)]
C=[x for x in set(A) if A.count(x) > 1]
ans=0
mod=(10**9)+7
if len(B)==N:
    for i in range(N-1):
        for j in range(i+1,N):
            ans+=A[i]^A[j]
else:
    for i in range(len(B)-1):
        for j in range(i+1,len(B)):
            if B[i] in C:
                if B[j] in C:
                    ans+=((A.count(B[i]))*(A.count(B[j])))*(B[i]^B[j])
                else:
                    ans+=(A.count(B[i]))*(B[i]^B[j])
            else:
                if B[j] in C:
                    ans+=(A.count(B[j]))*(B[i]^B[J])
                else:
                    ans+=B[i]^B[j]
ans=ans%mod
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[x for x in set(A)]
C=[x for x in set(A) if A.count(x) > 1]
ans=0
mod=(10**9)+7
if len(B)==N:
    for i in range(N-1):
        for j in range(i+1,N):
            ans+=A[i]^A[j]
else:
    for i in range(len(B)-1):
        for j in range(i+1,len(B)):
            if B[i] in C:
                if B[j] in C:
                    ans+=((A.count(B[i]))*(A.count(B[j])))*(B[i]^B[j])
                else:
                    ans+=(A.count(B[i]))*(B[i]^B[j])
            else:
                if B[j] in C:
                    ans+=(A.count(B[j]))*(B[i]^B[J])
                else:
                    ans+=B[i]^B[j]
ans=ans%mod
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[x for x in set(A)]
C=[x for x in set(A) if A.count(x) > 1]
ans=0
mod=(10**9)+7
for i in range(len(B)-1):
    for j in range(i+1,len(B)):
        if B[i] in C:
            if B[j] in C:
                ans+=((A.count(B[i]))*(A.count(B[j])))*(B[i]^B[j])
            else:
                ans+=(A.count(B[i]))*(B[i]^B[j])
        else:
            if B[j] in C:
                ans+=(A.count(B[j]))*(B[i]^B[J])
            else:
                ans+=B[i]^B[j]
ans=ans%mod
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[x for x in set(A)]
C=[x for x in set(A) if A.count(x) > 1]
ans=0
mod=(10**9)+7
for i in range(len(B)-1):
    for j in range(i+1,len(B)):
        if B[i] in C:
            if B[j] in C:
                ans+=4*(B[i]^B[j])
            else:
                ans+=2*(B[i]^B[j])
        else:
            if B[j] in C:
                ans+=2*(B[i]^B[J])
            else:
                ans+=B[i]^B[j]
ans=ans%mod
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
 
mod = 10**9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   
    n_1 = np.count_nonzero((A >> n)&1)   
    n_0 = N - num_1                       
    ans += ((2 ** n)*n_1*n_0) % mod

print(ans%mod)

Submission status: Runtime Error

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

MOD = 10**9 + 7

dig = 60
Abn = [[0]*dig for _ in range(n)]

for i in range(n):
  for j in range(dig):
    if A[i]>>j&1:
      Abn[i][j] = 1
      

Cbn = [[[0]*2 for j in range(dig)] for i in range(n)]

for j in range(dig):
  if Abn[n-1][j]==1:
    Cbn[n-1][j][1] = 1
  else:
    Cbn[n-1][j][0] = 1
    
for i in range(n-2, 0, -1):
  for j in range(dig):
    if Abn[i][j]==1:
      Cbn[i][j][0] = Cbn[i+1][j][0]
      Cbn[i][j][1] = Cbn[i+1][j][1] + 1
    else:
      Cbn[i][j][0] = Cbn[i+1][j][0] + 1
      Cbn[i][j][1] = Cbn[i+1][j][1]

ans = 0
two = [pow(2, i, MOD) for i in range(dig)]

for i in range(n-1):
  for j in range(dig):
    if Abn[i][j] == 1:
      ans += Cbn[i+1][j][0] * two[i] % MOD
    else:
      ans += Cbn[i+1][j][1] * two[i] % MOD
    ans %= MOD
    
print(ans)

Submission status: Runtime Error

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

MOD = 10**9 + 7

dig = 60
Abn = [[0]*dig for _ in range(n)]

for i in range(n):
  for j in range(dig):
    if A[i]>>j&1:
      Abn[i][j] = 1
      

Cbn = [[[0]*2 for j in range(dig)] for i in range(n)]

for j in range(dig):
  if Abn[n-1][j]==1:
    Cbn[n-1][j][1] = 1
  else:
    Cbn[n-1][j][0] = 1
    
for i in range(n-2, 0, -1):
  for j in range(dig):
    if Abn[i][j]==1:
      Cbn[i][j][0] = Cbn[i+1][j][0]
      Cbn[i][j][1] = Cbn[i+1][j][1] + 1
    else:
      Cbn[i][j][0] = Cbn[i+1][j][0] + 1
      Cbn[i][j][1] = Cbn[i+1][j][1]

ans = 0
two = [pow(2, i, MOD) for i in range(dig)]

for i in range(n-1):
  for j in range(dig):
    if Abn[i][j] == 1:
      ans += Cbn[i+1][j][0] * two[i] % MOD
    else:
      ans += Cbn[i+1][j][1] * two[i] % MOD
    ans %= MOD
    
print(ans)

Submission status: Runtime Error

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

cnt=0
for i in range(60):
    now=g[i].count(1)
    cnt+=now*(n-now)*(2**i)
    cnt%=mod

print(cnt)

Submission status: Runtime Error

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

cnt=0
for i in range(60):
    now=g[i].count(1)
    cnt+=now*(n-now)*(2**i)
    cnt%=mod

print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
from math import ceil,log2
N = int(input())
a = np.array(list(map(int,input().split())),dtype=np.int64)
ans = 0
count = 1
for i in range(ceil(log2(max(a)))):
    b = a%2
    s = np.count_nonzero(b==1)*np.count_nonzero(b==0)*count
    ans +=s
    count *= 2
    a = a//2
    ans %= 10**9+7
print(ans)

Submission status: Runtime Error

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

for i in range(60):
    ones = np.count_nonzero(A>>i&1)
    #Aのうち2進法でi桁目が1である物の数
    zeros = n - ones
    #Aのうち2進法でi桁目が0である物の数
    ans += ones * zeros * 2**(i) % mod
    #xorの結果i桁目が0と1の時なので、zeros*ones
    #10進法の数に戻すために2**iを掛ける
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [ int(x) for x in input().split()]

mx = max(a)
k= len(bin(mx))-2

a = [ f'{x:0>{k}b}'  for x in a]

#print(a)

total = 0
for i in range(k-1,-1,-1):
    ones = 0
    for j in range(n):
      	if(a[j][i]=='1'):
            ones+=1
           
    zeroes=n-ones
    #print(ones)
    total+= ones*zeroes*(2**(k-i-1))       
         
print(total%(10**9+7))

Submission status: Runtime Error

Solution code:
import math
import fractions
import sys
import itertools
import numpy as np
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))


N=input1()
A=np.array(input_array())
mod=10**9-7
s=0

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

print(s % mod)

Submission status: Runtime Error

Solution code:
import math
import fractions
import sys
import itertools
import numpy as np
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))


N=input1()
A=np.array(input_array())
mod=10**9-7
s=0

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

print(s % mod

Submission status: Runtime Error

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

    M = max(A)
    L = M.bit_length()
    ans = 0
    mod = 10**9 + 7
    k = [0]*L
    k[0] = 1
    for i in range(1, L):
        k[i] = k[i-1]*2
    for j in range(L):
        count = 0
        for x in A:
            if (x >> j) % 2 == 1:
                count += 1
        ans += count*(N - count)*k[j]
    ans %= mod
    print(ans)


main()

Submission status: Runtime Error

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

M = max(A)
L = M.bit_length()
ans = 0
mod = 10**9 + 7
k = [0]*L
k[0] = 1
for i in range(1, L):
    k[i] = k[i-1]*2
for j in range(L):
    count = 0
    for x in A:
        if (x >> j) % 2 == 1:
            count += 1
    ans += count*(N - count)*k[j]
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
result = [0 for _ in range(120)]
for i in a:
    x = format(i, "060b")[::-1]
    for j in range(60):
        result[j] = result[j]+(x[j]=="1")
result = [(n-i)*i for i in result]
for i in range(70):
    result[i+1] += result[i]//2
    result[i] = result[i]%2    
print(int("".join(map(str, result[::-1])), 2)%mod)

Submission status: Runtime Error

Solution code:
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 = np.count_nonzero(arr & 1)
    s += 2 ** i * c1 * (n - c1)
    arr = arr >> 1

print(s % mod)

Submission status: Runtime Error

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

def to_bit(n):
    res = np.zeros(60, dtype=int)
    for digit in range(59, -1, -1):
        res[digit] = n % 2
        n >>= 1
    return res

nums = np.array([to_bit(a) for a in As])
num1 = nums.sum(axis=0)
num0 = N - num1

res = 0
for prod in num0 * num1:
    res <<= 1
    res += prod
    res = int(res % P)
print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
mod = 10**9+7
a = np.array(list(map(int,input().split())))
ans = 0
for i in range(60):
    #aをiビット右にずらす、iは60桁目まで、&1で対象のビットが1のもの以外を0にその数をカウントする。
    b = np.count_nonzero(a >>i&1)
    ans += ((2**i)*(n-b)*b)%mod
print(ans)

Submission status: Runtime Error

Solution code:
MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        if isinstance(x, str):
            x = int(x)
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )

def encode(N, A, max_k):
    bits = [0 for _ in range(max_k)]
    for i in range(N):
        a = format(A[i], 'b')
        for k in range(max_k):
            bits[max_k - 1 - k] += int(a[k])
    return bits

def decode(N, bits):
    ret = ModInt(0)
    for k, counter in enumerate(bits):
        ret += 2 ** k * (counter * (N - counter))
    return ret

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

print(decode(N, encode(N, A, max_k)))

Submission status: Runtime Error

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
import numpy as np
alis = np.array(alis,dtype=np.int64)
b = [0] * 61
count = 0
while True:
    if np.all(alis== 0):
        break
    c = (alis % 2 == 0)
    b[count] = sum(c)
    count += 1
    alis //= 2
mod = 10 ** 9 + 7
ans = 0
for i in range(61):
    tmp = (1<<i) % mod
    k = (b[i] * (n-b[i]))  % mod
    k = k*tmp % mod
    ans += k
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [0]*64
for i in range(n):
    c = bin(a[i])[2:]
    for j, q in enumerate(c):
        if q == '1':
            b[i] += 1
c = 0
b = b[::-1]
for i in range(64):
    c += b[i]*(n-b[i])*2**i
print(c % (10**9+7))

Submission status: Runtime Error

Solution code:
from math import ceil, log2
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(ceil(log2(a[i]))):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=b[i]*(n-b[i])*2**i
print(c%(10**9+7))

Submission status: Runtime Error

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

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


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

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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


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

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = lmi()
    m = max(a)
    ans = 0
    for shift in range(int(math.log2(m)+1)):
        mask = 0b1 << shift
        # print(tuple(map(lambda x: (x&mask)>>shift, a)))
        count_one = tuple(map(lambda x: (x&mask)>>shift, a)).count(1)
        ans = (ans + int(pow(2, shift, mod)) * count_one * (n - count_one)) % mod
        # print(ans)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(60):
    c = sum([1 for ai in a if (a >> i) & 1])
    ans += (1 << i) * c * (n-c)
    ans % = mod
print(ans)

Submission status: Runtime Error

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

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

inf = pow(10, 9)+7
key = max(a)

k = 1
while key > 1:
  k += 1
  key //= 2
sub = [0]*k

ans = 0
for i in range(n):
  value = a[i]
  value_bin = [0]*k
  q = 0
  p = 0
  while value > 0:
    if value%2 == 1:
      value_bin[p] += 1
    p += 1
    value //= 2
  if p > q:
    q = p
  if i == 0:
    for j in range(q):
      if value_bin[p] == 1:
        sub[p] = 1
  r = 1
  for j in range(q):
    if value_bin[j] == 1:
      ans += (r*(i-sub[j]))%inf
      sub[j] += 1
    else:
      ans += (r*sub[j])%inf
    r *= 2
    ans %= inf

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

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

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

print(answer%MOD)

Submission status: Runtime Error

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

# def myinput():
#     return map(int,input().split())

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

m = math.floor(math.log(max(a),2))+1

if max(a)==0:
  print(0)
  exit()

for j in range(m):
    one = 0
    zero = 0
    for i in range(n):
        b = str(bin(a[i]))[2:]
        c = b.zfill(m)
        s = int(c[m-j-1])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**j) 
    ans %= mod
print(ans%mod)

Submission status: Runtime Error

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

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

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

m = math.floor(math.log(max(a),2))+1

if max(a)==0:
  print(0)
  exit()

for j in range(m):
    one = 0
    zero = 0
    for i in range(n):
        b = str(bin(a[i]))[2:]
        c = b.zfill(m)
        s = int(c[m-j-1])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**j) 
    ans %= mod
print(ans%mod)

Submission status: Runtime Error

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

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

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

m = math.floor(math.log(max(a),2))+1

if max(a)==0:
  print(0)
  exit()

for j in range(m):
    one = 0
    zero = 0
    for i in range(n):
        b = str(bin(a[i]))[2:]
        c = b.zfill(m)
        s = int(c[m-j-1])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**j) 
    ans %= mod
print(ans%mod)

Submission status: Runtime Error

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

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

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

import math
m = math.floor(math.log(max(a),2))+1

if max(a)==0:
  print(0)
  exit()

for j in range(m):
    one = 0
    zero = 0
    for i in range(n):
        b = str(bin(a[i]))[2:]
        c = b.zfill(m)
        s = int(c[m-j-1])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**j) 
    ans %= mod
print(ans%mod)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
ans = 0

for j in reversed(range(61)):
    one = 0
    zero = 0
    for i in range(n):
        b = str(bin(a[i]))[2:]
        c = b.zfill(60)
        s = int(c[j])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**(60-j)) % mod
print(ans%mod)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

#k=len(str(bin(max(nums))))-2
k=int(math.log2(max(nums)))+1

mat=[]
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    mat.append(list(num))
 
mat=list(zip(*mat))
ans=0
 
for i in range(k):
    b=mat[i].count("1")
    ans+=b*(N-b)*pow(2,(k-i-1),l)
print(ans%l)

Submission status: Runtime Error

Solution code:
import math

N=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=int(math.log2(max(nums)))+1
mat=[]
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    mat.append(list(num))
 
mat=list(zip(*mat))
ans=0
 
for i in range(k):
    b=mat[i].count("1")
    ans+=b*(N-b)*pow(2,(k-i-1),l)
print(ans%l)

Submission status: Runtime Error

Solution code:
import math

N=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=math.log2(max(nums))+1
mat=[]
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    mat.append(list(num))
 
mat=list(zip(*mat))
ans=0
 
for i in range(k):
    b=mat[i].count("1")
    ans+=b*(N-b)*pow(2,(k-i-1),l)
print(ans%l)

Submission status: Runtime Error

Solution code:
import math 

N=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=int(math.log2(max(nums)))+1
mat=[0]*k
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    for i in range(k):
        if num[i]=="1":
            mat[i]+=1

ans=sum([ (N-mat[i])*mat[i]*pow(2,(k-i-1),l) for i in range(k)])
print(ans%l)

Submission status: Runtime Error

Solution code:
import math 

N=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=int(math.log2(max(nums)))+1
mat=[0]*k
for each in nums:
    num=(str(bin(each))[2:])[::-1]
    kk=len(num)
    for i in range(kk):
        if num[i]=="1":
            mat[i]+=1

ans=sum([ (N-mat[i])*mat[i]*pow(2,i,l) for i in range(k)])
print(ans%l)

Submission status: Runtime Error

Solution code:
=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=len(str(bin(max(nums))))-2
mat=[]
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    mat.append(list(num))

mat=list(zip(*mat))
ans=0

for i in range(k):
    b=mat[i].count("1")
    
    ans+=b*(N-b)*(2**(k-i-1))
print(ans)