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:
#!/usr/bin/env python3

import itertools

mod = 10**9+7

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

count_0 = [0 for _ in range(61)]
count_1 = [0 for _ in range(61)]

for i in range(len(a)):
    num_str = "%061d" % int(bin(a[i])[2:])
    # print(num_str)
    for j in range(len(num_str)):
        if num_str[j] == "0":
            count_0[j] += 1
        else:
            count_1[j] += 1

# print(count_0)
# print(count_1)

ans = 0
count = 1
for i in range(61):
    tmp = count_0[-i-1]*count_1[-i-1]
    ans += tmp*count
    count = (count*2) % mod
print(ans % mod)


# ans = 0
# for x, y in itertools.combinations(a, 2):
#     # print(x ^ y)
#     ans += (x ^ y)

# print(ans % mod)

Submission status: Time Limit Exceeded

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

import itertools

mod = 10**9+7

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

ans = 0
for x, y in itertools.combinations(a, 2):
    # print(x ^ y)
    ans += (x ^ y)

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
#標準入力の受け取り
N = int(input())
A = list(map(int, input().split()))

#Aの各値を二進数にした時の桁ごとに配列にまとめる
bit_lis = [0] * 61
for i in range(N):
    tmp = A[i]
    for j in range(61):
        bit_lis[j] += tmp % 2
        tmp = tmp // 2
        if tmp == 0:
            break
        
#各桁について値を計算する
ans = 0
bit_1 = 0
mod = 10 ** 9 + 7
for i in range(61):
    bit_1 = bit_lis[i]
    if bit_1 == 0:
        continue
    ans += pow(2, i, mod) * bit_1 * (N-bit_1) 
    ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#標準入力の受け取り
N = int(input())
A = list(map(int, input().split()))

#Aの各値を二進数にした時の桁ごとに配列にまとめる
bit_lis = [0] * 61
for i in range(N):
    tmp = A[i]
    for j in range(61):
        bit_lis[j] += tmp % 2
        tmp = tmp // 2
        if tmp == 0:
            break
        
#各桁について値を計算する
ans = 0
bit_1 = 0
mod = 10 ** 9 + 7
for i in range(61):
    bit_1 = bit_lis[i]
    if bit_1 == 0:
        continue
    ans += (2 ** i) * bit_1 * (N-bit_1) % mod
    ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#標準入力の受け取り
N = int(input())
A = list(map(int, input().split()))

#Aの各値を二進数にした時の桁ごとに配列にまとめる
bit_lis = [0] * 61
for i in range(N):
    tmp = A[i]
    for j in range(61):
        bit_lis[j] += tmp % 2
        tmp = tmp // 2
        
#各桁について値を計算する
ans = 0
bit_1 = 0
mod = 10 ** 9 + 7
for i in range(61):
    bit_1 = bit_lis[i]
    ans += (2 ** i) * bit_1 * (N-bit_1) % mod
    ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#標準入力の受け取り
N = int(input())
A = list(map(int, input().split()))

#Aをbitに表記し直して二次元配列に格納
bit_lis = []
for i in range(N):
    mini_bit_lis = []
    tmp = A[i]
    for j in range(61):
        mini_bit_lis.append(tmp % 2)
        tmp = tmp // 2
    bit_lis.append(mini_bit_lis)

#各桁について値を計算する
ans = 0
bit_1 = 0
mod = 10 ** 9 + 7
for i in range(61):
    for j in range(N):
        if bit_lis[j][i] == 1:
            bit_1 += 1
    if bit_1 == 0:
        continue
    ans += (2 ** i) * bit_1 * (N-bit_1)
    bit_1 = 0
    ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int,input().split())))
bit = []
ans = 0
mod = 10**9+7
# for i in a:
#     cnt = 1
#     while i:
#         bit[-cnt] += i%2
#         i //= 2
#         cnt += 1
for i in range(60):
    bit.append(sum(a&1))
    a >>= 1
# print(bit)
for i in range(60):
    ans += ((n-bit[i])*bit[i]) % mod * pow(2,i,mod)
    ans %= mod
print(ans%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
bit = [0]*60
ans = 0
mod = 10**9+7
for i in a:
    cnt = 1
    while i:
        bit[-cnt] += i%2
        i //= 2
        cnt += 1
for i in range(60):
    ans += (n-bit[-1-i])*bit[-1-i] * (2**i) % mod
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
MOD=10**9+7

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

abi=[0]*61
aze=[0]*61

for item in a:
    j=0
    #print(bin(item))
    while j<len(str(bin(item)))-2:
        #print(j)
        if item>>j & 1:
            abi[j]+=1
        else:
            aze[j]+=1
        j+=1
    k=len(str(bin(item)))-2
    while k<61:
        aze[k]+=1
        k+=1


        #print(abi)

result=0
i=0
while i<61:
    result+=(2**i)%MOD*abi[i]%MOD*(aze[i])%MOD

    i+=1

#print(abi[:4])

#print(aze[:4])
print(result%MOD)


"""
01
10
11
"""



"""
0001
0010
0011
0100
0101
0110
0111
"""

Submission status: Time Limit Exceeded

Solution code:
import sys
MOD=10**9+7

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

abi=[0]*61
aze=[0]*61

for item in a:
    j=0
    #print(bin(item))
    while j<len(str(bin(item)))-2:
        #print(j)
        if item>>j & 1:
            abi[j]+=1
        else:
            aze[j]+=1
        j+=1
    k=len(str(bin(item)))-2
    while k<61:
        aze[k]+=1
        k+=1


        #print(abi)

result=0
i=0
while i<61:
    result+=(2**i)%MOD*abi[i]*(aze[i])%MOD

    i+=1

#print(abi[:4])

#print(aze[:4])
print(result%MOD)


"""
01
10
11
"""



"""
0001
0010
0011
0100
0101
0110
0111
"""

Submission status: Time Limit Exceeded

Solution code:
import sys
MOD=10**9+7

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

abi=[0]*61
aze=[0]*61

for item in a:
    j=0
    #print(bin(item))
    while j<len(str(bin(item)))-2:
        #print(j)
        if item>>j & 1:
            abi[j]+=1
        else:
            aze[j]+=1
        j+=1
    k=len(str(bin(item)))-2
    while k<61:
        aze[k]+=1
        k+=1


        #print(abi)

result=0
i=0
while i<61:
    result+=(2**i)*abi[i]*(aze[i])%MOD

    i+=1

#print(abi[:4])

#print(aze[:4])
print(result%MOD)

Submission status: Time Limit Exceeded

Solution code:
import sys
MOD=10**9+7

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

abi=[0]*64
aze=[0]*64

for item in a:
    j=0
    #print(bin(item))
    while j<len(str(bin(item)))-2:
        #print(j)
        if item>>j & 1:
            abi[j]+=1
        else:
            aze[j]+=1
        j+=1
    k=len(str(bin(item)))-2
    while k<64:
        aze[k]+=1
        k+=1


        #print(abi)

result=0
i=0
while i<64:
    result+=(2**i)*abi[i]*(aze[i])%MOD

    i+=1

#print(abi[:4])

#print(aze[:4])
print(result%MOD)


"""
01
10
11
"""



"""
0001
0010
0011
0100
0101
0110
0111
"""

Submission status: Time Limit Exceeded

Solution code:
M = 1000000007
def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans %= M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
M = 1000000007

def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans % M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    M = 1000000007
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)
        
    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += (2**(bit_size - i - 1) % M) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mod = (10 ** 9) + 7
max_a = max(a)
ans = 0
for j in range(len(bin(max(a))) - 2):
    t = sum([1 & i for i in a]) 
    ans += (2 ** j) * t * (n - t)
    a = [i >> 1 for i in a]
    ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    M = 1000000007
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    bit_size = len(bin(a[-1])[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += (2**(bit_size - i - 1) % M) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
t = []
mod = (10 ** 9) + 7
count = 0
max_a = max(a)
for _ in range(len(bin(max(a))) - 2):
    t.append(sum([1 & i for i in a]))
    a = [i >> 1 for i in a]
    count += 1
ans = 0
for i, j in zip(t, range(count)):
    ans += i * (n - i) * (2 ** j)
    ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
t = []
mod = (10 ** 9) + 7
count = 0
while sum(a) > 0:
    t.append(sum([1 & i for i in a]))
    a = [i >> 1 for i in a]
    count += 1
ans = 0
for i, j in zip(t, range(count)):
    ans += i * (n - i) * (2 ** j)
    ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    M = 1000000007
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    bit_size = len(bin(a[-1])[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += 2**(bit_size - i - 1) * one * zero
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ans = 0
mod = 1000000007

for i in range(60):
    one_count =0
    zero_count = 0
    for j in range(N):
        if A[j] >> i & 1 == 1:
            one_count+=1
        else:
            zero_count+=1
    ans += (one_count % mod) *(zero_count%mod) * (2**i) % mod
    ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
bin_a = []
for i in a:
    bin_a.append(bin(i)[2::])
maxlen = 0
for i, j in enumerate(bin_a):
    maxlen = max(maxlen, len(j))

for i, j in enumerate(bin_a):
    while len(bin_a[i]) < maxlen:
        bin_a[i] = "0" + bin_a[i]
bin_a.sort()
ans = 0
mod = 10**9+7
for i in range(maxlen):
    zerocnt = 0
    onecnt = 0
    for j in range(len(bin_a)):
        if bin_a[j][i] == "0":
            zerocnt += 1
        else:
            onecnt += 1
    ans += zerocnt * onecnt * pow(2, (maxlen-i-1), mod)
    ans %= mod
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
bin_a = []
for i in a:
    bin_a.append(bin(i)[2::])
maxlen = 0
for i, j in enumerate(bin_a):
    maxlen = max(maxlen, len(j))

for i, j in enumerate(bin_a):
    while len(bin_a[i]) < maxlen:
        bin_a[i] = "0" + bin_a[i]
bin_a.sort()
ans = 0
mod = 10**9+7
for i in range(maxlen):
    zerocnt = 0
    onecnt = 0
    for j in range(len(bin_a)):
        if bin_a[j][i] == "0":
            zerocnt += 1
        else:
            onecnt += 1
    ans += zerocnt * onecnt * (2 ** (maxlen-i-1))
    ans %= mod
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
for i in a:
    for j in a:
        ans += i ^ j
print(ans // 2 % mod)

Submission status: Time Limit Exceeded

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

MOD = 10**9 + 7

ans = 0
two_factor = 1
for d in range(60):
    n0 = 0
    n1 = 0
    for i in range(N):
        if A[i] & (1<<d):
            n1 += 1
        else:
            n0 += 1
    tmp = (1<<d) % MOD
    n = n0 * n1 % MOD
    tmp = tmp * n % MOD
    ans = (ans + tmp) % MOD

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

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

for a in a:
    temp = bin(a)[2:][::-1]
    for i in range(len(temp)):
        l[i] += int(temp[i])

ans = 0
mod = 10**9 + 7

for i in range(max_len):
    ans += pow(2, i, mod) * l[i] * (N-l[i])

print(ans % mod)

Submission status: Time Limit Exceeded

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

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

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

for a in a:
    temp = bin(a)[2:][::-1]
    for i in range(len(temp)):
        l[i] += int(temp[i])

ans = 0
mod = 10**9 + 7

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

print(ans)

Submission status: Time Limit Exceeded

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

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

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

for a in a:
    temp = bin(a)[2:][::-1]
    # print(temp)
    for i in range(max_len):
        if i < len(temp):
            l[i] += int(temp[i])
        else:
            l[i] += 0

# print(l)

ans = 0
mod = 10**9 + 7

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

print(ans)

Submission status: Time Limit Exceeded

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

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

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

for a in a:
    temp = bin(a)[2:][::-1]
    # print(temp)
    for i in range(max_len):
        if i < len(temp):
            l[i] += int(temp[i])
        else:
            l[i] += 0

# print(l)

ans = 0
mod = 10**9 + 7

for i in range(max_len):
    ans += ((2**i) % mod) * l[i] * (N-l[i])
    ans = ans % mod

print(ans)

Submission status: Time Limit Exceeded

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

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

l = [0] * 60

for a in a:
    temp = bin(a)[2:][::-1]
    # print(temp)
    for i in range(60):
        if i < len(temp):
            l[i] += int(temp[i])
        else:
            l[i] += 0

# print(l)

ans = 0
mod = 10**9 + 7

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    g = []
    ans = 0
    for j in range(60):
        d = 0
        for i in range(n):
            d += a[i]&1
            a[i] >>= 1
        g.append(d)
    for i in range(60):
        ans += g[i]*(n-g[i])*(pow(2,i,1000000007))
        ans = ans % (1000000007)
    print(ans%(1000000007))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

box = [0] * 61
for i in range(n):
    s = bin (a[i])
    for j in range(len(s)-1):
        if s[-j] == '1':
            box[j] += 1
ans = 0
for i in range(1,61):
    ans += box[i] * (n - box[i]) * pow(2,i-1,10**9+7)
print(ans % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
g = []
ans = 0
for j in range(60):
    d = 0
    for i in range(n):
        d += a[i]&1
        a[i] >>= 1
    g.append(d)
for i in range(60):
    ans += g[i]*(n-g[i])*(pow(2,i,1000000007))
    ans = ans % (1000000007)
print(ans%(1000000007))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
g = []
ans = 0
for j in range(60):
    d = 0
    for i in range(n):
        if a[i]&1:
            d += 1
        a[i] >>= 1
    g.append(d)
for i in range(60):
    ans += g[i]*(n-g[i])*(pow(2,i,1000000007))
    ans = ans % (1000000007)
print(ans%(1000000007))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
g = []
ans = 0
for j in range(60):
    d = 0
    for i in range(n):
        if a[i]&(2**j) == 2**j:
            d += 1
    g.append(d)
for i in range(60):
    ans += g[i]*(n-g[i])*(pow(2,i,10**9+7))
    ans = ans % (10**9+7)
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    sum = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            sum += A[i] ^ A[j]
    print(sum % MOD)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i] = list(format(a[i],'0b').zfill(60))
g = [0 for i in range(60)]
for i in range(60):
    for j in range(n):
        if a[j][i] == '1':
            g[i] += 1
ans = 0
for i in range(len(g)):
    ans += g[i]*(n-g[i])*(pow(2,59-i,10**9+7))
    ans = ans%(10**9+7)
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i] = list(format(a[i],'0b').zfill(60))
g = [0 for i in range(60)]
for i in range(60):
    for j in range(n):
        if a[j][i] == '1':
            g[i] += 1
ans = 0
for i in range(len(g)):
    ans += g[i]*(n-g[i])*(pow(2,59-i,10**9+7))
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i] = list(format(a[i],'0b').zfill(65))
g = [0 for i in range(65)]
for i in range(65):
    for j in range(n):
        if a[j][i] == '1':
            g[i] += 1
ans = 0
for i in range(len(g)):
    ans += g[i]*(n-g[i])*(pow(2,64-i,10**9+7))
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i] = list(format(a[i],'0b').zfill(65))
g = [0 for i in range(65)]
for i in range(65):
    for j in range(n):
        if a[j][i] == '1':
            g[i] += 1
ans = 0
for i in range(len(g)):
    ans += g[i]*(n-g[i])*(pow(2,64-i,10**9+7))
    ans = ans%(10**9+7)
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i] = list(format(a[i],'0b').zfill(65))
g = [0 for i in range(65)]
for i in range(65):
    for j in range(n):
        if a[j][i] == '1':
            g[i] += 1
ans = 0
for i in range(len(g)):
    ans += g[i]*(n-g[i])*(2**(64-i))
    ans = ans%(10**9+7)
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def main():
    MOD = 10**9 + 7
    A_UB = 2**60  # upper bound
    MAX_BIN_LENGTH = len('{:b}'.format(A_UB))

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

    bit = 1
    answer = 0
    for b in range(MAX_BIN_LENGTH):
        a_bits = A & 1
        one_num = sum(a_bits)
        answer += (one_num * (N - one_num) * bit) % MOD
        answer %= MOD
        bit *= 2
        bit %= MOD
        A >>= 1
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    MOD = 10**9 + 7
    A_UB = 2**60  # upper bound
    MAX_BIN_LENGTH = len('{:b}'.format(A_UB))

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

    bit = 1
    answer = 0
    for b in range(MAX_BIN_LENGTH):
        a_bits = [a & 1 for a in A]
        one_num = sum(a_bits)
        answer += (one_num * (N - one_num) * bit) % MOD
        answer %= MOD
        bit *= 2
        bit %= MOD
        for i in range(N):
            A[i] >>= 1
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    MOD = 10**9 + 7
    A_UB = 2**60  # upper bound
    MAX_BIN_LENGTH = len('{:b}'.format(A_UB))
    BIN_FORMAT = '{{:0{}b}}'.format(MAX_BIN_LENGTH)

    N = int(input())
    A = list(map(int, input().split(' ')))
    rev_bin_A = [BIN_FORMAT.format(a)[::-1] for a in A]

    bit_coef = [0 for _ in range(MAX_BIN_LENGTH)]
    for b in range(MAX_BIN_LENGTH):
        bit_list = [int(rev_bin_a[b]) for rev_bin_a in rev_bin_A]
        one_num = sum(bit_list)
        zero_num = N - one_num
        bit_coef[b] = one_num * zero_num

    answer = 0
    for b in range(MAX_BIN_LENGTH):
        pow_2 = (2**b) % MOD
        answer += (pow_2 * bit_coef[b]) % MOD
    answer %= MOD
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# sys.stdin.readline()
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    a = tuple(map(int,input().split()))
    b = []

    for i in range(n-1):
        for j in range(i+1,n):
            b.append(a[i]^a[j])

    ans = sum(b)%(10**9+7)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = tuple(map(int,input().split()))
    b = [a[i]^a[j] for i in range(n-1) for j in range(i+1,n)]

    ans = sum(b)%(10**9+7)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [a[i]^a[j] for i in range(n-1) for j in range(i+1,n)]

ans = sum(b)%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    for j in range(i+1,n):
        b.append(a[i]^a[j])

ans = sum(b)%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

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

mod = 1000000007
bit = pow(2, 59)
ans = 0
while bit != 0:
    cnt = 0
    for i in range(len(a)):
        if a[i] // bit == 1:
            cnt += 1
        a[i] %= bit
    ans += (cnt * (n-cnt) * bit)
    ans %= mod
    bit //= 2

print(ans)

Submission status: Time Limit Exceeded

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

mod = 1000000007
bit = pow(2, 59)
ans = 0
while bit != 0:
    cnt = 0
    for i in range(len(a)):
        if a[i] // bit == 1:
            cnt += 1
        a[i] %= bit
    ans += ((cnt * (n-cnt)) % mod * bit) % mod
    ans %= mod
    bit //= 2

print(ans)

Submission status: Time Limit Exceeded

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

bit = [0] * 61
for i in range(N):
    for x in range(61):
        if 2**x > A[i]:
            break
        elif (1<<x) & A[i] > 0:
            bit[x] += 1

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

bit = [0] * 61
for i in range(N):
    for x in range(61):
        if 2**x > A[i]:
            break
        elif 2**x & A[i] > 0:
            bit[x] += 1

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

bit = [0] * 61
for i in range(N):
    for x in range(61):
        if 2**x & A[i] > 0:
            bit[x] += 1

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

print(ans)

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)
ans = 0
POW = 1
for j in range(60):
  tmp = A & 1
  one = sum(tmp)
  zero = N - one
  ans = (ans + one * zero * POW) % MOD
  A >>= 1
  POW = (POW*2)%MOD
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
bit = [0] * 60
for i in range(N):
  n = A[i]
  cnt = 0
  while(n>=1):
    bit[cnt] += n%2
    n = n//2
    cnt += 1
ans = 0
POW = 1
for j in range(60):
  ans = (ans +bit[j]*(N-bit[j])*POW)%MOD
  POW = (POW * 2)%MOD
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
bit = [0] * 60
for i in range(N):
  n = A[i]
  cnt = 0
  while(n>=1):
    bit[cnt] += n%2
    n = n//2
    cnt += 1
ans = 0
POW = 1
for j in range(60):
  ans += (bit[j]*(N-bit[j])*POW)%MOD
  POW = (POW * 2)%MOD
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
# Problem D - Xor Sum 4

# input
N = int(input())
a_nums = list(map(int, input().split()))

# initialization
ans = 0
MOD = 10**9 + 7

# count
two_factor = 1
for i in range(60):
    tmp_count = 0
    one_count = 0
    zero_count = 0
    for j in range(N):
        if (a_nums[j]>>i)&1==1:
            one_count += 1
        else:
            zero_count += 1
    tmp_count = (one_count * zero_count)%MOD
    ans += (tmp_count * two_factor)%MOD
    two_factor = (two_factor * 2)%MOD

# output
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
# Problem D - Xor Sum 4

# input
N = int(input())
a_nums = list(map(int, input().split()))

# initialization
ans = 0
MOD = 10**9 + 7

# count
for i in range(60):
    tmp_count = 0
    one_count = 0
    zero_count = 0
    for a in a_nums:
        if (a>>i)&1==1:
            one_count += 1
        else:
            zero_count += 1
    tmp_count = one_count * zero_count
    ans += (tmp_count * (2**i))%MOD

# output
print(ans%MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lis=list(map(lambda x:format(int(x),'b'),input().split()))
l=0
for i in range(n):
    l=max(l,len(lis[i]))

d=[[0]*2 for _ in range(60)]

for i in range(n):
    lis[i]=lis[i].zfill(l)
    for j in range(l):
        d[j][int(lis[i][-j-1])]+=1

ans=0
for i in range(60):
    ans+=(d[i][0]*d[i][1]*2**i)%(10**9+7)
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lis=list(map(lambda x:format(int(x),'b'),input().split()))
l=0
for i in range(n):
    l=max(l,len(lis[i]))
    
for i in range(n):
    lis[i]=lis[i].zfill(l)

d=[[0]*2 for _ in range(60)]

for i in range(n):
    l=len(lis[i])
    for j in range(l):
        d[j][int(lis[i][-j-1])]+=1

ans=0
for i in range(60):
    ans+=(d[i][0]*d[i][1]*2**i)%(10**9+7)
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

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

MOD = 1000000007
n, *a = map(int, open(0).read().split())

ans = 0
w = 1
for i in range(61):
    zero = one = 0
    for j in range(n):
        if a[j]&1: one += 1
        else: zero += 1
        a[j] >>= 1;
    ans += w * zero * one
    ans %= MOD
    w *= 2
print(ans)