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:
N = int(input())
num_list = list(map(int, input().split()))

length = N
amount = 0
for i in range(length-1):
  for j in range(i+1, length):
    num1 = num_list[i]
    num2 = num_list[j]
    bit_num1 = format(num1, "b")
    bit_num2 = format(num2, "b")
    length_num1 = len(bit_num1)
    length_num2 = len(bit_num2)
    max_length = max(length_num1, length_num2)
    bit_num1 = bit_num1.zfill(max_length)
    bit_num2 = bit_num2.zfill(max_length)       
    num = ""
    for k in range(1, max_length+1):
      if int(bit_num1[-k]) and not int(bit_num2[-k]):
        num = "1" + num
      elif not int(bit_num1[-k]) and int(bit_num2[-k]):
        num = "1" + num
      else:
        num = "0" + num
    amount += int(num, 2)

L = 10**9 + 7
print(amount % L)

Submission status: Time Limit Exceeded

Solution code:
def run():
  b = 10**9+7
  bit = 60
  N = int(input())
  a_li = list(map(int, input().split()))
  ans = 0
  dp = [[0]*bit for i in range(N)]
  for i in range(bit):
    dp[0][i] = (a_li[0] >> i) & 1
  for i in range(1, N):
    tem = 0
    for j in range(bit):
      a_j = (a_li[i] >> j) & 1
      dp[i][j] = dp[i-1][j] + a_j
      if a_j == 1:
        tem += (i-dp[i-1][j]) << j
      else:
        tem += dp[i-1][j] << j
    #print(ans, tem)
    ans += tem
  #print(dp)
  print(ans%b)

if __name__ == '__main__':
  run()

Submission status: Time Limit Exceeded

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

length = N
amount = 0
for i in range(length-1):
  for j in range(i+1, length):
    num1 = num_list[i]
    num2 = num_list[j]
    bit_num1 = format(num1, "b")
    bit_num2 = format(num2, "b") 
    length_num1 = len(bit_num1)
    length_num2 = len(bit_num2)
    max_length = max(length_num1, length_num2)
    bit_num1 = bit_num1.zfill(max_length)
    bit_num2 = bit_num2.zfill(max_length)       
    num = ""
    for k in range(1, max_length+1):
      if int(bit_num1[-k]) + int(bit_num2[-k]) == 1:
        num = "1" + num
      else:
        num = "0" + num
    amount += int(num, 2)

L = 10**9 + 7
print(amount % L)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
  run()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(N) for N in input().split()]
max_size = len(format(max(A),"b"))
A_bin = list(map(lambda x: format(x,"b").zfill(max_size), A))
result = 0
for i in range(max_size):
    zero = 0
    one = 0
    for j in A_bin:
        if j[max_size-1-i] == "0":
            zero += 1
        else:
            one += 1
    result+= ((2**i) * zero * one)
    if result>1000000007:

      result =result%1000000007
print(result%1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(N) for N in input().split()]
max_size = len(format(max(A),"b"))
A_bin = list(map(lambda x: format(x,"b").zfill(max_size), A))
result = 0
for i in range(max_size):
    zero = 0
    one = 0
    for j in A_bin:
        if j[max_size-1-i] == "0":
            zero += 1
        else:
            one += 1
    result += ((2**i) * zero * one) %1000000007
print(result%1000000007)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
n_integer = int(input())
integers = [int(x) for x in input().split(' ')]


exclusiveor_list = [integers[i] ^ integers[i+j+1] for i in range(n_integer - 1) for j in range(n_integer - 1 - i)]
        
print(sum(exclusiveor_list) % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
n_integer = int(input())
integers = [int(x) for x in input().split(' ')]
sum_of_exclusiveor = 0

for i in range(n_integer - 1):
    for j in range(n_integer - 1 - i):
        sum_of_exclusiveor += integers[i] ^ integers[i+j+1]
        
print(sum_of_exclusiveor % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
mod = 10 ** 9 + 7

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

ans = 0
for i in range(60):
    cnt = sum((A_i >> i) & 1 for A_i in A)
    ans += (1 << i) * cnt * (N - cnt)

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N = int(f_i.readline())
    A = tuple(map(int, f_i.readline().split()))
    
    ans = 0
    for i in range(60):
        cnt = sum((A_i >> i) & 1 for A_i in A)
        ans += (1 << i) * cnt * (N - cnt)
    
    print(ans % mod)

solve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int, input().split()))
modNum = 10**9 + 7
sum = 0
for d in range(60):
	n1 = 0
	for A in As:
		if (A >> d) & 1 == 1:
			n1 += 1
	sum += (2 ** d) * n1 * (N - n1)
print(sum % modNum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int, input().split()))
modNum = 10**9 + 7
sum = 0
for d in range(60):
	n0 = 0
	n1 = 0
	for A in As:
		if (A >> d) & 1 == 1:
			n1 += 1
		else:
			n0 += 1
	sum += (1 << d) * n1 * n0
print(sum % modNum)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N = int(f_i.readline())
    A = map(int, f_i.readline().split())
    
    bit_count = [0] * 60
    for A_i in A:
        b = 0
        while A_i:
            bit_count[b] += A_i & 1
            A_i >>= 1
            b += 1
    
    ans = 0
    bit = (1 << i for i in range(60))
    for b, c in zip(bit, bit_count):
        ans += b * c * (N - c)
    
    print(ans % mod)

solve()

Submission status: Time Limit Exceeded

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

result %= 10 ** 9 + 7

print(result)

Submission status: Time Limit Exceeded

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

result %= 10 ** 9 + 7

print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(N) for N in input().split()]
max_size = len(format(max(A),"b"))
A_bin = list(map(lambda x: format(x,"b").zfill(max_size), A))

result = 0

for i in range(max_size):
    zero = 0
    one = 0
    for j in A_bin:
        if j[max_size-1-i] == "0":
            zero += 1
        else:
            one += 1
    result += ((2**i) * zero * one) %1000000007

print(result%1000000007)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !

#def change_bin(data):
#    return format(data,"b").zfill(64)
#A_bin = list(map(change_bin, A))
    
N = int(input())
A = [int(N) for N in input().split()]
max_size = len(format(max(A),"b"))
A_bin = list(map(lambda x: format(x,"b").zfill(max_size), A))


bin2dec = 1
result = 0


for i in range(max_size):
    zero = 0
    one = 0
    for j in A_bin:
        if j[max_size-1-i] == "0":
            zero += 1
        else:
            one += 1
    result += bin2dec * zero %1000000007* one %1000000007
    bin2dec *= 2 %1000000007


print(result%1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(N) for N in input().split()]
max_size = len(format(max(A),"b"))
A_bin = list(map(lambda x: format(x,"b").zfill(max_size), A))


bin2dec = 1
result = 0


for i in range(max_size):
    zero = 0
    one = 0
    for j in A_bin:
        if j[max_size-1-i] == "0":
            zero += 1
        else:
            one += 1
    result += (bin2dec * zero * one) %1000000007
    bin2dec *= 2 %1000000007


print(result%1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(N) for N in input().split()]
max_size = len(format(max(A),"b"))
A_bin = list(map(lambda x: format(x,"b").zfill(max_size), A))


result = 0
for i in range(max_size):
    zero = 0
    one = 0
    for j in A_bin:
        if j[i] == "0":
            zero += 1
        else:
            one += 1
    result += (2**(max_size-1-i) * zero * one) %1000000007

print(result%1000000007)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N = int(f_i.readline())
    A = list(map(int, f_i.readline().split()))
    
    ans = 0
    b = 1
    while A:
        next_A = []
        
        bit_cnt = 0
        
        for A_i in A:
            if A_i & 1:
                bit_cnt += 1
            A_i >>= 1
            if A_i:
                next_A.append(A_i)
        
        ans += b * bit_cnt * (N - bit_cnt)
        ans %= mod
        
        b *= 2
        A = next_A[:]
        
    print(ans)

solve()

Submission status: Time Limit Exceeded

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N = int(f_i.readline())
    A = list(map(int, f_i.readline().split()))
    A_max = max(A)
    
    ans = 0
    b = 1
    while A_max:
        next_A = []
        
        bit_cnt = 0
        
        for A_i in A:
            if A_i & 1:
                bit_cnt += 1
            A_i >>= 1
            if A_i:
                next_A.append(A_i)
        
        ans += b * bit_cnt * (N - bit_cnt)
        ans %= mod
        
        b *= 2
        A_max >>= 1
        A = next_A[:]
        
    print(ans)

solve()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !

#def change_bin(data):
#    return format(data,"b").zfill(64)
    
N = int(input())
A = [int(N) for N in input().split()]
#A_bin = list(map(change_bin, A))
max_size = len(format(max(A),"b"))
A_bin = list(map(lambda x: format(x,"b").zfill(max_size), A))


result = 0
for i in range(max_size):
    zero = 0
    one = 0
    for j in A_bin:
        if j[i] == "0":
            zero += 1
        else:
            one += 1
    result += 2**(max_size-1-i) * zero * one

print(result%1000000007)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N = int(f_i.readline())
    A = list(map(int, f_i.readline().split()))
    A_max = max(A)
    
    ans = 0
    b = 1
    while A_max:
        next_A = []
        
        zero_cnt = 0
        one_cnt = 0
        
        for A_i in A:
            if A_i & 1:
                one_cnt += 1
            else:
                zero_cnt += 1
            next_A.append(A_i >> 1)
        
        ans += b * one_cnt * zero_cnt
        ans %= mod
        
        b *= 2
        A_max >>= 1
        A = next_A[:]
        
    print(ans)

solve()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !

def change_bin(data):
    return format(data,"b").zfill(64)
    
N = int(input())
A = [int(N) for N in input().split()]
A_bin = list(map(change_bin, A))

result = 0
for i in range(64):
    zero = 0
    one = 0
    for j in A_bin:
        if j[i] == "0":
            zero += 1
        else:
            one += 1
    result += 2**(63-i) * zero * one

print(result%1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(60):
    czero = 0
    cone = 0
    for j in range(n):
        if (lis[j] >> i) & 1 == 0:
            czero += 1
        else:
            cone += 1
    ans += czero * cone * 2**i
ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
def main():
    MOD = 10**9+7
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    count = [0] * 61

    for a in A:
        for i, c in enumerate(format(a, '061b')):
            if c == '1':
                count[i] += 1
    ans = 0
    for j, a in enumerate(A):
        for i, c in enumerate(format(a, '061b')):
            if c == '1':
                count[i] -= 1
                ans = (ans + pow(2, 60-i, MOD) * (N-1-j-count[i]))%MOD
            else:
                ans = (ans + pow(2, 60-i, MOD) * count[i])%MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

cnt = [0] * 62

for index in range(N):
    temp = A[index]
    keta = 0
    while (temp > 0):
        cnt[keta] += temp & 1

        keta += 1
        temp >>= 1

# print(cnt)
ans = 0
keta = 1
for kaku in cnt:
    ans += (kaku * (N - kaku)) * keta
    keta *= 2

print(ans % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

cnt = [0] * 62

for index in range(N):
    temp = A[index]
    keta = 0
    while (temp > 0):
        cnt[keta] += temp & 1

        keta += 1
        temp >>= 1

# print(cnt)
ans = 0
keta = 1
for kaku in cnt:
    ans = (ans + (kaku * (N - kaku)) * keta) % 1000000007
    keta *= 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

cnt = [0] * 62

for index in range(N):
    temp = A[index]
    keta = 0
    while (temp > 0):
        cnt[keta] += temp % 2

        keta += 1
        temp //= 2

# print(cnt)
ans = 0
keta = 1
for kaku in cnt:
    ans = (ans + (kaku * (N - kaku)) * keta) % 1000000007
    keta *= 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


trash = input()
nums = [int(i) for i in input().split(" ")]

s = 0
for pair in combinations(nums, 2):
    s += pair[0] ^ pair[1]
print(s % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
zero_count = 0
one_count = 0
xor_bit = 0
xor = 0

A_bin = list(map(lambda x: str(format(x,"060b")),A))

for i in range(60):
    zero_count = 0
    one_count = 0

    for j in range(N):
        if A_bin[j][i] == "0":
            zero_count += 1
        else:
            one_count += 1
    
    xor_bit = zero_count * one_count * (2**(59-i))
    xor += xor_bit

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = list(map(lambda x: (str(bin(x))[2:]).zfill(60), a))
mod = 10**9 + 7
ans = 0
for i in range(60):
    cnt = 0
    for j in a:
        cnt += int(j[-1*(i+1)])
    ans += cnt * (n-cnt) * pow(2, i, mod) % mod
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = list(map(lambda x: (str(bin(x))[2:]).zfill(65), a))
mod = 10**9 + 7
ans = 0
for i in range(65):
    cnt = 0
    for j in a:
        if j[-1*(i+1)] == "1": cnt += 1
    ans += cnt * (n-cnt) * pow(2, i, mod) % 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
keta = 0
while a != [0]*n:
    b = list(map(lambda x: x % 2, a))
    a = list(map(lambda x: x//2, a))
    num_1 = b.count(1)
    ans += (num_1 * (n-num_1) * pow(2, keta, mod)) % mod
    ans %= mod
    keta += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
ans = 0
keta = 0
while a != [0]*n:
    b = list(map(lambda x: x % 2, a))
    a = list(map(lambda x: x//2, a))
    ans += b.count(0) * b.count(1) * 2**keta
    ans %= mod
    keta += 1
print(ans)

Submission status: Time Limit Exceeded

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

r = []
for i in range(N - 1):
  for j in range(i+1, N):
    #r += (A[i]) ^ (A[j])
    r.append((A[i]) ^ (A[j]))

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

#print(bin(10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
m=math.ceil(math.log(max(1,max(a)),2))

ans=0
for i in range(m):
  sum1=sum((a[j]>>i)&1 for j in range(n))
  sum0=n-sum1
  ans+=2**i*sum1*sum0

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

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
m=math.ceil(math.log(max(1,max(a)),2))

ans=0
for i in range(m):
  sum0=0
  sum1=0
  for j in range(n):
    if (a[j]>>i)&1:
      sum1+=1
    else:
      sum0+=1
  ans+=2**i*sum1*sum0
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

input = stdin.buffer.readline

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

cnt = [0] * 65
ans = 0
p = 0
for x in a:
    for i in range(60):
        pos = (x >> i) & 1
        if pos:
            ans += pow(2, i, mod) * (p - cnt[i])
        else:
            ans += pow(2, i, mod) * cnt[i]
        # print(x, i, pos, ans, cnt[:3])
        ans %= mod
        cnt[i] += pos
    p += 1

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

input = stdin.readline

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

cnt = [0] * 65
ans = 0
for p, x in enumerate(a):
    for i in range(60):
        pos = (x >> i) & 1
        if pos:
            ans += pow(2, i) * (p - cnt[i])
        else:
            ans += pow(2, i) * cnt[i]
        # print(x, i, pos, ans, cnt[:3])
        ans %= mod
        cnt[i] += pos

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

input = stdin.readline

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

cnt = [0] * 65
ans = 0
for p, x in enumerate(a):
    for i in range(60):
        pos = (x >> i) & 1
        if pos:
            ans += (1 << i) * (p - cnt[i])
        else:
            ans += (1 << i) * cnt[i]
        # print(x, i, pos, ans, cnt[:3])
        ans %= mod
        cnt[i] += pos

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

input = stdin.readline

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

cnt = [0] * 65
ans = 0
for p, x in enumerate(a):
    for i in range(61):
        pos = (x >> i) & 1
        if pos:
            ans += (1 << i) * (p - cnt[i])
        else:
            ans += (1 << i) * cnt[i]
        # print(x, i, pos, ans, cnt[:3])
        ans %= mod
        cnt[i] += pos

print(ans % mod)

Submission status: Time Limit Exceeded

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):
        ans <<= 1
        s = sum(d)
        ans += s * (n - s) % m
        ans %= m
    return str(ans)


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

Submission status: Time Limit Exceeded

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 i, d in enumerate(zip(*a)):
        s = sum(d)
        ans += ((s * (n - s)) % m) * pow(2, 59 - i, m) % m
        ans %= m
    return str(ans)


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

Submission status: Time Limit Exceeded

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 i, d in enumerate(zip(*a)):
        s = sum(d)
        ans += s * (n - s) * pow(2, 59 - i, m) % m
        ans %= m
    return str(ans)


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

Submission status: Time Limit Exceeded

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 i, d in enumerate(zip(*a)):
        ans += sum(d) * (n - sum(d)) * pow(2, 59 - i, m) % m
        ans %= m
    return str(ans)


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

Submission status: Time Limit Exceeded

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

ans=0
MOD=10**9+7

for k in range(60):
    x0=0
    x1=0
    for i in range(n):
        cnt=(a[i]>>k)&1
        if cnt==0:
            x0+=1
        else:
            x1+=1

    tmp=1
    for j in range(k):
        tmp*=2
        tmp%=MOD

    su=(x0*x1)*tmp%MOD
    ans+=su
    ans%=MOD

print(ans)

Submission status: Time Limit Exceeded

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

def main():
    n = int(input())
    a = list(map(int,input().split()))

    mod = 10 ** 9 + 7

    a_bin = [format(i, 'b') for i in a]

    m = len(max(a_bin, key = len))

    ans = 0

    for i in range(n):
        a_bin[i] = '0' * (m - len(a_bin[i])) + a_bin[i]

    for i in range(1, m+1):
        count = [0, 0]
        for j in a_bin:
            count[int(j[-i])] += 1
        ans += count[0] * count[1] * 2 ** (i-1)

    print(ans % mod)

if __name__ == '__main__':
    main()

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_bin = [format(i, 'b') for i in a]

m = len(max(a_bin, key = len))

ans = 0

for i in range(n):
    a_bin[i] = '0' * (m - len(a_bin[i])) + a_bin[i]

for i in range(1, m+1):
    count = [0, 0]
    for j in a_bin:
        count[int(j[-i])] += 1
    ans += count[0] * count[1] * 2 ** (i-1)

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
MOD = 10**9 + 7
def solve(n, a, p=60):
    b = [np.asarray(list(bin(x)[2:].zfill(p)), dtype=int) for x in a]
    b = np.asarray(b, dtype=int)
    s = np.sum(b, axis=0)
    res = sum(int(s[i]) * int(n - s[i]) * (2**(p-1-i)) for i in range(p))
    return res % MOD

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

MOD = 10**9 + 7
def solve(n, a, p=60):
    s = np.zeros(p, dtype=int)
    t = np.zeros(p, dtype=int)
    a = a[::-1]
    for i in range(n):
        mask = bin(a[i])[2:].zfill(p)
        mask = np.asarray(list(mask), dtype=int)
        s += mask
        t += mask * (i+1-s) + (1-mask) * s
    res = 0
    for j in range(p):
        res += int(t[j]) * (2**(p-1-j))
    return res % MOD

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

MOD = 10**9 + 7
def solve(n, a, p=60):
    s = np.zeros(p, dtype=int)
    t = np.zeros(p, dtype=int)
    a = a[::-1]
    for i in range(n):
        mask = bin(a[i])[2:].zfill(p)[::-1]
        mask = np.asarray(list(mask), dtype=int)
        s += mask
        t += mask * (i+1-s) + (1-mask) * s
    res = 0
    for j in range(p):
        res += int(t[j]) * (2**j)
    return res % MOD

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

MOD = 10**9 + 7
def solve(n, a, p=60):
    s = np.zeros(p, dtype=int)
    t = np.zeros(p, dtype=int)
    a = a[::-1]
    for i in range(n):
        mask = bin(a[i])[2:].zfill(p)[::-1]
        mask = np.asarray(list(map(int, mask)), dtype=int)
        s += mask
        t += mask * (i+1-s) + (1-mask) * s
    res = 0
    for j in range(p):
        res += int(t[j]) * (2**j)
    return res % MOD

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

MOD = 10**9 + 7
def solve(n, a, p=64):
    s = np.zeros(p, dtype=int)
    t = np.zeros(p, dtype=int)
    a = a[::-1]
    for i in range(n):
        mask = bin(a[i])[2:].zfill(p)[::-1]
        mask = np.asarray(list(map(int, mask)), dtype=int)
        s += mask
        for j in range(p):
            if mask[j] == 1:
                t[j] += i - s[j] + 1
            else:
                t[j] += s[j]
    res = 0
    for j in range(p):
        res += int(t[j]) * (2**j)
    return res % MOD

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

MOD = 10**9 + 7
def solve(n, a, p=64):
    s = np.zeros(p, dtype=int)
    a = a[::-1]
    res = 0
    for i in range(n):
        mask = bin(a[i])[2:].zfill(p)[::-1]
        mask = np.asarray(list(map(int, mask)), dtype=int)
        s += mask
        for j in range(p):
            if mask[j] == 1:
                res += (i - int(s[j]) + 1) * (2**j)
            else:
                res += int(s[j]) * (2**j)
        res %= MOD
    return res % MOD

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
def solve(n, a, p=64):
    s = [0] * p
    a = a[::-1]
    res = 0
    for i in range(n):
        mask = bin(a[i])[2:][::-1]
        c = [0] * p
        for j, b in enumerate(map(int, mask)):
            s[j] += b
            c[j] = b
        for j in range(p):
            if c[j] == 1:
                res += (i - s[j] + 1) * (2**j)
            else:
                res += s[j] * (2**j)
    return res % MOD

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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_0 = 0
    for j in range(N):
        if ((A[j] >> i) & 1) == 0:
            tmp_0 += 1
    tmp += ((tmp_0)*(N - tmp_0)*(2**i)) % mod
print(tmp % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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

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

dst = xor_sum % (10**9+7)
print(dst)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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:
        if bin(s>>i)[-1] == "1":c1 += 1
        else: c0 += 1
    ans += (c1*c0)*(2**i)
print(ans%((10**9)+7))

Submission status: Time Limit Exceeded

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

Solution code:
import itertools
n=input()
print(sum(a^b for a,b in list(itertools.combinations(map(int,input().split()),2)))%(10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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:
def calc(N, A):
    Z = 10 ** 9 + 7
    A.sort(key=lambda a: -a)
    B = [
        [1 if c == '0' else 0, 1 if c == '1' else 0]
        for c in list(bin(A[0])[2:])
    ]
    M = len(B)
    for a in A[1:]:
        b = bin(a)[2:]
        m = len(b)
        for i in range(M):
            c = int(b[i - M + m]) if i - M + m > -1 else 0
            B[i][c] += 1
    x = 0
    for p in B:
        x = x * 2 + p[0] * p[1]
        x = x % Z
    return x


N = int(input())
A = [int(s) for s in input().split()]
print(calc(N, A))

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(61):
    cnt = 0
    for j in range(N):
        cnt += A[j] % 2
        A[j] >>= 1
    ans += (2 ** i) * cnt * (N - cnt)

print(ans % MOD)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

mod = 10 ** 9 + 7

cnt = [0] * 60
for i in range(n):
    for j in range(60):
        cnt[j] += a[i] % 2
        a[i] = a[i] // 2

ans = 0
for i in range(60):
    ans = (ans + (2 ** i) * cnt[i] * (n - cnt[i])) % mod

print(ans)

Submission status: Time Limit Exceeded

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

K = [0] * 61
for a in A:
    L = list(format(a, 'b').zfill(61))
    M = list(int(s) for s in L)
    for i in range(61):
        K[i] += M[i]

ans = 0
for i in range(61):
    ans += (2 ** (60 - i)) * K[i] * (N - K[i]) % MOD

print(ans % MOD)