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: Time Limit Exceeded

Solution code:
MOD = 1000000007
n = int(input())
aas = list(map(int, input().split()))
KET = 60
arr_0 = [0]*KET
arr_1 = [0]*KET
for i in aas:
    bits = format(i,'060b')
    for j in reversed(range(KET)):
        if bits[j] == '0':
            arr_0[KET-j-1] += 1
        else:
            arr_1[KET-j-1] += 1
res = 0
for i in range(KET):
    res += (arr_0[i]%MOD * arr_1[i]%MOD)%MOD * pow(2,i,MOD)
    res %= MOD
print(res)

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007
n = int(input())
aas = list(map(int, input().split()))
KET = 62
arr_0 = [0]*KET
arr_1 = [0]*KET
for i in aas:
    bits = format(i,'062b')
    for j in reversed(range(KET)):
        if bits[j] == '0':
            arr_0[KET-j-1] += 1
        else:
            arr_1[KET-j-1] += 1
res = 0
for i in range(KET):
    res += (arr_0[i]%MOD * arr_1[i]%MOD)%MOD * pow(2,i,MOD)
    res %= MOD
print(res)

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007
n = int(input())
aas = list(map(int, input().split()))
KET = 62
arr_0 = [0]*KET
arr_1 = [0]*KET
for i in aas:
    bits = format(i,'062b')
    for j in reversed(range(KET)):
        if bits[j] == '0':
            arr_0[KET-j-1] += 1
        else:
            arr_1[KET-j-1] += 1
res = 0
for i in range(KET):
    res += (arr_0[i] * arr_1[i])%MOD * pow(2,i,MOD)
    res %= MOD
print(res)

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007
n = int(input())
aas = list(map(int, input().split()))
res = 0
for i in range(n-1):
    for j in range(i,n):
        res += (aas[i]^aas[j]) % MOD
        res %= MOD
print(res)

Submission status: Time Limit Exceeded

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

mod=10**9+7

ans=0
for i in range(60):
  on=0
  off=0
  for j in a:
    if (j>>i)&1:
      on+=1
    else:
      off+=1
  ans+=(on*off)*(2**i)
  ans%=mod

print(ans)

Submission status: Time Limit Exceeded

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

N=int(input().rstrip('\n'))
A=[int(x) for x in input().rstrip('\n').split()]
res = 0
t=1
for _ in range(60):
  n = sum(x%2 for x in A)
  A = [x//2 for x in A]
  res += n*(N-n)*t
  t = t*2
  res = res%(7+10**9)
  if all(x==0 for x in A):
    break
print(res)

Submission status: Time Limit Exceeded

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

N=int(input().rstrip('\n'))
A=[int(x) for x in input().rstrip('\n').split()]
res = 0
t=1
for i in range(60):
  if i ==0:
    A =[divmod(x,2) for x in A]
    n = sum(y for x,y in A)
    res += n*(N-n)
  else:
    A = [divmod(x,2) for x,y in A]
    n = sum(y for x,y in A)
    t = t*2
    res += n*(N-n)*t
    if all(x==0 for x in A):
      break
print(res%(7+10**9))

Submission status: Time Limit Exceeded

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

N=int(input().rstrip('\n'))
A=[int(x) for x in input().rstrip('\n').split()]
res = 0
t=1
for i in range(60):
  n = sum([x%2 for x in A])
  A = [x//2 for x in A]
  res += n*(N-n)*t
  t = t*2
  if all(x==0 for x in A):
    break
print(res%(7+10**9))

Submission status: Time Limit Exceeded

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

N=int(input().rstrip('\n'))
A=[int(x) for x in input().rstrip('\n').split()]
res = 0
for i in range(60):
  n = len([x for x in A if x % 2 ==1])
  A = [x//2 for x in A]
  t = 2**i
  res += n*(N-n)*t
  res = res%(7+10**9)
  if all(x==0 for x in A):
    break
print(res)

Submission status: Time Limit Exceeded

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

N=int(input().rstrip('\n'))
A=[int(x) for x in input().rstrip('\n').split()]
res = 0
for i in range(60):
  n = len([x for x in A if x % 2 ==1])
  A = [x//2 for x in A ]
  t = 2**i
  res += n*(N-n)*t
  if all(x==0 for x in A):
    break
print(res%(7+10**9))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
import numpy as np
MAX = max(A)
BIG = 10**9+7
L = len(bin(MAX)[2:])
ans = 0
for j in range(L):
    zero = 0
    one = 0
    for i in range(N):
        if (A[i] >> j) & 1:
            one+=1
        else:
            zero+=1
    ans += ((zero*one)%BIG)*pow(2,j,BIG)
    ans = ans%BIG
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
import numpy as np
MAX = max(A)
BIG = 10**9+7
L = len(bin(MAX)[2:])
ans = 0
for j in range(L):
    zero = 0
    one = 0
    for i in range(N):
        if (A[i] >> j) & 1:
            one+=1
        else:
            zero+=1
    ans += ((zero*one)%BIG)*2**j 
    ans = ans%BIG
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
import numpy as np
MAX = max(A)
BIG = 10**9+7
L = len(bin(MAX)[2:])
ans = 0
for j in range(L):
    zero = 0
    one = 0
    for i in range(N):
        if (A[i] >> j) & 1:
            one+=1
        else:
            zero+=1
    ans += zero*one*2**j
    ans = ans%BIG
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for j in range(digit):
  o = 0
  for i in a:
    if (i >> j) & 1:
      o += 1
  ans += (o*(n-o)*2**j)
  ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
digit = 60
o=[0]*digit
z=[0]*digit

ans = 0
for j in range(digit):
  for i in a:
    if (i >> j) & 1:
      o[j] += 1
    else:
      z[j] += 1
  ans += (o[j]*z[j]*2**j)
  ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
digit = 60
o=[0]*digit
z=[0]*digit

for i in a:
  for j in range(digit):
    if (i >> j) & 1:
      o[j] += 1
    else:
      z[j] += 1
ans = 0
for j in range(digit):
  ans += (o[j]*z[j]*2**j)
  ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
digit = 60
o=[0]*digit
z=[0]*digit

for i in a:
  for j in range(digit):
    if (i >> j) & 1:
      o[j] += 1
    else:
      z[j] += 1
ans = 0
for j in range(digit):
  ans += (o[j]*z[j]*2**j)
print(ans % MOD)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
digit = 60
o=[0]*digit
z=[0]*digit

for i in a:
  for j in range(digit):
    if (i >> j) & 1:
      o[j] += 1
    else:
      z[j] += 1
ans = 0    
for j in range(digit):
  ans += (o[j]*z[j]*pow(2,j,MOD))
print(ans % MOD)

Submission status: Time Limit Exceeded

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	lzero = [0]*62
	lone = [0]*62
	for v in al:
		for i in range(62):
			if v & (2**i) > 0:
				lone[i] += 1
			else:
				lzero[i] += 1
	ret = 0
	for i, (n_one, n_zero) in enumerate(zip(lone, lzero)):
		t = pow(2, i, mod) * n_one * n_zero
		ret += t
		ret %= mod
		
	print(ret)
		
			
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    A = NLI()
    B = [[0]*2 for _ in range(62)]
    for a in A:
        for i in range(62):
            B[i][(a >> i) & 1] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += b[0] * b[1] * pow(2, i, MOD)
    print(ans % MOD)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    A = NLI()
    B = [[0]*2 for _ in range(62)]
    for a in A:
        for i in range(62):
            B[i][(a >> i) & 1] += 1
    ans = 0
    for i, b in enumerate(B):
        ans += b[0] * b[1] * 2**i % MOD
    print(ans % MOD)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for x in A:
  for i in range(60):
    B[i] += (x >> i) & 1

ans = 0
p = 1

for i in range(60):
  if i >= 1:
    p *= 2
    p %= mod
  ans += (N-B[i])*B[i]*p
  ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
A = list(map(int, input().split()))
B = [0]*60
mod = 10 ** 9 + 7

for x in A:
  temp = bin(x)[2:]
  for i in range(len(temp)):
    if temp[-1-i] == "1":
      B[i] += 1

ans = 0

for i in range(60):
  ans += (N-B[i])*B[i]*pow(2, i, mod)
  ans %= mod

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
two_exp = 1
for i in range(60):
    one_cnt = 0
    zero_cnt = 0
    for a in A:
        if a >> i & 1:
            one_cnt += 1
        else:
            zero_cnt += 1
    ans += one_cnt * zero_cnt * two_exp
    ans %= MOD
    two_exp <<= 1
    two_exp %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin

N = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().split()))
mod = 10**9+7
ans = 0
for i in range(61):
    bits = 0
    for x in A:
        if (x>>i)&1:
            bits += 1
    ans += ((bits*(N-bits))* 2**i) %mod
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
N = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().split()))
mod = 10**9+7
ans = 0
for i in range(61):
    bits = 0
    for x in A:
        if (x>>i)&1:
            bits += 1
    ans += ((bits*(N-bits))* 2**i) %mod
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import log2,floor
stdin = sys.stdin
N = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().split()))
mod = 10**9+7
ans = 0
for i in range(61):
    bits = 0
    for x in A:
        if (x>>i)&1:
            bits += 1
    ans += ((bits*(N-bits))* 2**i) %mod
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import log2,floor
N = int(sys.stdin.readline().rstrip())
A = list(map(int,sys.stdin.readline().split()))
mod = 10**9+7
ans = 0
for i in range(61):
    bits = 0
    for x in A:
        if (x>>i)&1:
            bits += 1
    ans += ((bits*(N-bits))* 2**i) %mod
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import log2,floor
N = int(sys.stdin.readline().rstrip())
A = list(map(int,sys.stdin.readline().split()))
mod = 10**9+7
ans = 0
for i in range(61):
    bits = 0
    for x in A:
        if (x>>i)&1:
            bits += 1
    s = (bits*(N-bits))%mod
    t = (2**i)%mod
    ans += ((bits*(N-bits))* 2**i) %mod
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import log2,floor
N = int(sys.stdin.readline().rstrip())
A = list(map(int,sys.stdin.readline().split()))
mod = 10**9+7
ans = 0
for i in range(61):
    bits = 0
    for x in A:
        if (x>>i)&1:
            bits += 1
    s = (bits*(N-bits))%mod
    t = (2**i)%mod
    ans = (ans+s*t)%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import log2,floor
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(61):
    bits = 0
    for x in A:
        if (x>>i)&1:
            bits += 1
    s = (bits*(N-bits))%mod
    t = (2**i)%mod
    ans = (ans+s*t)%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import log2,floor
N = int(input())
A = list(map(int,input().split()))
L = max([len(bin(x)) for x in A])
mod = 10**9+7
ans = 0
for i in range(L):
    bits = 0
    for x in A:
        if (x>>i)&1:
            bits += 1
    s = (bits*(N-bits))%mod
    t = (2**i)%mod
    ans = (ans+s*t)%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import log2,floor
N = int(input())
A = list(map(int,input().split()))
L = max([len(bin(x)) for x in A])
mod = 10**9+7
ans = 0
for i in range(L):
    bits = 0
    for x in A:
        if (x>>i)&1:
            bits += 1
    ans = (ans+(bits*(N-bits)%mod)*((2**i)%mod))%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import log2,floor
N = int(input())
A = list(map(int,input().split()))
L = max([len(bin(x)) for x in A])
bits = [0]*L
for x in A:
    for i in range(L):
        if (x>>i)&1:
            bits[i] += 1
mod = 10**9+7
ans = 0
for i in range(L):
    b = bits[i]
    ans = (ans+b*(N-b)*(2**i))%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

N = 10
ARR = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]

N = 10
ARR = [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]

# N = 3
# ARR = [1, 2, 3]

# N = 5
# ARR = [3, 6, 8, 9, 10]

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


def calculate(n, arr):
    if max(arr) == 0:
        mathNum = 1
    else:
        mathNum = math.ceil(math.log(max(arr), 2)) + 1
    result = 0
    for i in range(mathNum):

        oneSum = 0
        zeroSum = 0

        for j in range(n):
            if ((arr[j] >> i) & 1) == 0:
                zeroSum += 1
            else:
                oneSum += 1

        result += (2 ** i) * (zeroSum * oneSum)

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


calculate(N, ARR)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

bit = [0] * 60
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    c = 0
    for x in a:
        if x >> i & 1:
            c += 1
    ans = (ans + c * (n - c) * (2 ** i)) % mod

print(ans)

Submission status: Time Limit Exceeded

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

bit = [0] * 60
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    c = 0
    for x in a:
        if x >> i & 1:
            c += 1
    ans = (ans + c * (n - c) * (2 ** i)) % mod

print(ans)

Submission status: Time Limit Exceeded

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

bit = [0] * 60
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    c = 0
    for j in range(n):
        if a[j] & 1:
            c += 1
        a[j] //= 2
    ans = (ans + c * (n - c) * (2 ** i)) % mod

print(ans)

Submission status: Time Limit Exceeded

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

bit = [0] * 60
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    c = 0
    for j in range(n):
        c += int(a[j] & 1)
        a[j] //= 2
    ans = (ans + c * (n - c) * (2 ** i)) % mod

print(ans)

Submission status: Time Limit Exceeded

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

bit = [0] * 60
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    c = 0
    for j in range(n):
        c += int(a[j] & 1)
        a[j] >>= 1
    ans = (ans + c * (n - c) * (1 << i)) % mod

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
from itertools import combinations
AA = list(combinations(A,2))
ans = 0
for a,b in AA:
    ans += a^b
print(ans%mod)

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(len(bin(A[i])) - 2):
        if A[i] & (1 << j):
            frag[j] += 1

print(sum([(frag[i] * (N - frag[i]) * 2 ** i) % mod for i in range(60)]) % mod)

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(len(bin(A[i])) - 2):
        if A[i] & (1 << j):
            frag[j] += 1

print(sum([(frag[i] * (N - frag[i]) * 2 ** i) for i in range(60)]) % mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
c=[0]*60
for aa in a:
  for i in range(60):
    if aa&(1<<i):c[i]+=1
ans=0
for i,cc in enumerate(c):
  ans+=cc*(n-cc)*2**i
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(60):
  n1,n0 = 0,0
  for a in A:
    if a>>i & 1: n1+=1
    else: n0+=1
  ans += (2**i)*n1*n0 % mod
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt=[0]*60
for a in A:
    for j in range(60):
        cnt[j]+=a&1
        a>>=1

ans=0
b=1
for c in cnt:
    ans+=b*c*(n-c)
    ans%=mod
    b=b*2%mod

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(N-1):
  for j in range(i+1,N):
    ans += A[i]^A[j]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,*a=map(int,open(0).read().split())
mod=10**9+7
ans=0
for j in range(60):
  cnt=0
  for i in range(n):
    cnt+=a[i]&1
    a[i]=(a[i]>>1)
  ans+=(cnt*(n-cnt)%mod)*pow(2,j,mod)
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
ans = 0
for j in range(60):
    count = 0
    for i in range(len(a)):
        a[i], pre = divmod(a[i], 2)
        count += pre
    ans += count*(N-count)*2**j
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

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

a.sort(reverse = True)

#l = len(bin(a[0])[2:])

ans  = 0
for b in range(60+1):
    count_1 = 0
    count_0 = 0
    for i in range(n):
        if (a[i] >> b) & 1:
            count_1 += 1
        else:
            count_0 += 1
    count_1 %= mod
    count_0 %= mod
    ans += (count_1 * count_0 * pow(2,b))%mod


print(ans%mod)

Submission status: Time Limit Exceeded

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

a.sort(reverse = True)

l = len(bin(a[0])[2:])

ans  = 0
for b in range(l):
    count_1 = 0
    count_0 = 0
    for i in range(n):
        if (a[i] >> b) & 1:
            count_1 += 1
        else:
            count_0 += 1
    count_1 %= mod
    count_0 %= mod
    ans += (count_1 * count_0 * pow(2,b))%mod


print(ans%mod)

Submission status: Time Limit Exceeded

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

a.sort(reverse = True)

l = len(bin(a[0])[2:])

ans  = 0
for b in range(l):
    count_1 = 0
    count_0 = 0
    for i in range(n):
        if (a[i] >> b) & 1:
            count_1 += 1
        else:
            count_0 += 1
    ans += (count_1 * count_0 * 2**b)%mod


print(ans%mod)

Submission status: Time Limit Exceeded

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

max_bit_length = len(format(2**60-1, "b"))
one_list = [[] for i in range(max_bit_length)]
zero_list = [[]for i in range(max_bit_length)]
for i in num_list:
  num = i
  bit_num = format(num, "b")
  for j in range(1, len(bit_num)+1):
    check_num = int(bit_num[-j])
    if check_num:
      one_list[j-1].append(1)
    else:
      zero_list[j-1].append(1)
  for k in range(1, (max_bit_length-len(bit_num))+1):
    zero_list[-k].append(1)
ans = 0
radix = 1
for k,l in zip(one_list, zero_list):
  ans += radix*(len(k)*len(l))
  radix *= 2
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = list(map(int,input().split()))
counter = 0

for i in range(0,N-1):
    for j in range(i+1,N):
        counter += A[i] ^ A[j]

print(counter%(pow(10,9)+7))

Submission status: Time Limit Exceeded

Solution code:
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()

n=ii()
a=lmi()
INF=10**9+7
ans=0
for i in range(60):
  x=0
  for j in range(n):

    if (a[j]>>i)&1:
      x+=1

  num=x*(n-x)*2**i
  ans+=num

print(ans%INF)

Submission status: Time Limit Exceeded

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

s = 0
for i in range(n - 1):
    for j in range(i, n):
        k = a[i] ^ a[j]
        s += k
        s %= 10**9 + 7

print(s)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(60):
  c=0
  for j in A:
    if j>>i&1:
      c+=1
  ans+=pow(2,i,mod)*c*(N-c)
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(60):
  c=0
  for j in A:
    if j>>i&1==1:
      c+=1
  ans+=pow(2,i,mod)*c*(N-c)
  ans=ans%mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

mod=10**9+7
ans=0

for i in range(60):
    a=0
    for x in A:
        if x>>i&1:
            a+=1
    ans+=a*(N-a)*pow(2,i,mod)
    ans%=mod

    
print(ans)

Submission status: Time Limit Exceeded

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

MOD = 10**9+7
ans = 0

for i in range(60):
    cnt = 0
    for a in A:
        cnt += a>>i&1
    ans += cnt*(n-cnt)*2**i
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=[format(A[i],'b').rjust(61,'0') for i in range(N)]
zero=[0 for i in range(61)]

for i in range(N):
   for j in range(61):
       if A[i][j]=='0':
         zero[60-j]+=1

mod=10**9+7       
ans=0
for i in range(61):
   ans+=(zero[i]*(N-zero[i]))%mod*pow(2,i,mod)
   ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=[format(A[i],'b').rjust(61,'0') for i in range(N)]
zero=[0 for i in range(61)]
one=[0 for i in range(61)]
for i in range(N):
   for j in range(61):
       if A[i][j]=='0':
         zero[60-j]+=1
       if A[i][j]=='1':
         one[60-j]+=1
mod=10**9+7       
ans=0
for i in range(61):
   ans+=zero[i]*one[i]*pow(2,i,mod)
   ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    MOD = 10**9 + 7

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

    num1s = [0] * 60
    for A in As:
        for d in range(60):
            if (A>>d) & 1:
                num1s[d] += 1

    ans = 0
    for d in range(60):
        ans += num1s[d] * (N-num1s[d]) * pow(2, d, MOD)
        ans %= MOD

    print(ans)


solve()

Submission status: Time Limit Exceeded

Solution code:
def solve():
    MOD = 10**9 + 7

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

    ans = 0
    for d in range(60):
        nums = [0, 0]
        for A in As:
            b = (A>>d) & 1
            nums[b] += 1
        v = nums[0]*nums[1]
        v *= pow(2, d, MOD)
        ans += v
        ans %= MOD

    print(ans)


solve()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)
    dig = len(bin(M)) - 2
    MOD = 10 ** 9 + 7
    ans = 0
    d = {i: 0 for i in range(dig)}
    for a in A:
        a = bin(a)[2:]
        for i in range(len(a)):
            if a[-(i+1)] == '1':
                d[i] += 1
    for i in range(dig):
        ans += d[i] * (n - d[i]) * pow(2, i, MOD)
        ans %= MOD
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
M = max(A)
dig = len(bin(M)) - 2
MOD = 10 ** 9 + 7
ans = 0
d = {i: [0, 0] for i in range(dig)}
for a in A:
    a = bin(a)[2:].zfill(dig)
    for i in range(len(a)):
        if a[-(i+1)] == '0':
            d[i][0] += 1
        else:
            d[i][1] += 1
for i in range(dig):
    ans += d[i][0] * d[i][1] * pow(2, i, MOD)
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ans = 0

for i in range(60):
    cnt = 0
    for a in A:
        cnt += a>>i&1
    ans += cnt*(N-cnt)*2**i
    ans %= mod
    # print(ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9+7
    # Aの中でd桁目が0,1であるものの個数を求める(p,qとする)
    # 全部のd桁目についてループして、ans+=(2**d)*(p*q)
    ans = 0
    for d in range(60):
        p,q = 0,0
        for i in range(N):
            if A[i]%2==0: p+=1
            else: q+=1
            A[i] //= 2
        ans += ((2**d)*p*q)%MOD
        ans %= MOD
    print(ans)

main()

Submission status: Time Limit Exceeded

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

bits = [[0] * 60 for _ in range(N)]

for i, a in enumerate(A):
    if i != 0:
        for j in range(60):
            bits[i][j] += bits[i - 1][j]
    cnt = 0
    while a != 0:
        if a & 1:
            bits[i][cnt] += 1

        cnt += 1
        a >>= 1


all_sum = 0
two_exp = [pow(2, i, MOD) for i in range(60)]

for i, a in enumerate(A):
    temp_sum = 0
    cnt = 0
    while cnt < 60:
        ones = bits[-1][cnt] - bits[i][cnt]
        zeros = N - (i + 1) - ones

        if a & 1:
            temp_sum += (two_exp[cnt] * zeros) % MOD
        else:
            temp_sum += (two_exp[cnt] * ones) % MOD

        temp_sum %= MOD

        a >>= 1
        cnt += 1

    all_sum += temp_sum
    all_sum %= MOD


print(all_sum)

Submission status: Time Limit Exceeded

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

sum_all = 0
p = 1
for i in range(60):
    ones = 0
    zeros = 0

    x = 1 << i
    for a in A:
        if a & x:
            ones += 1
        else:
            zeros += 1

    sum_all += p * ones * zeros % MOD
    p *= 2 % MOD


print(sum_all % MOD)

Submission status: Time Limit Exceeded

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

sum_all = 0
for i in range(60):
    ones = 0
    zeros = 0

    for a in A:
        if a & (1 << i):
            ones += 1
        else:
            zeros += 1

    sum_all += pow(2, i, MOD) * ones * zeros % MOD


print(sum_all % MOD)