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:
def main():
    length = int(input())
    numbers = list(map(int, input().split()))
    numbers.sort()
    max_digit = len(bin(numbers[-1])[2:])
    count = [[0, 0] for _ in range(60)]
    for n in numbers:
        bin_n = bin(n)[2:].zfill(max_digit)
        for i in range(max_digit):
            count[max_digit - i - 1][int(bin_n[i])] += 1
    answer = 0
    mod = 10 ** 9 + 7
    for i, c in enumerate(count):
        answer = (answer + c[0] * c[1] * pow(2, i)) % mod
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
n = int(input())
a = list(map(int,input().split()))
ans = 0
mod = (10**9 +7)
for j in range(61):# 2**j 桁に対して1なものの数を求める
    num_one = 0
    for i in range(len(a)):
        if a[i] & 2**j: 
            num_one += 1
    #print(j,num_one)
    ans += (2**j % mod) * (n-num_one)*(num_one) % mod
    #print(ans)
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
n = int(input())
a = list(map(int,input().split()))
ans = 0
mod = (10**9 +7)
for j in range(61):# 2**j 桁に対して1なものの数を求める
    num_one = 0
    for i in range(len(a)):
        if a[i] & 2**j: 
            num_one += 1
    #print(j,num_one)
    ans += 2**j * (n-num_one)*(num_one) % mod
    #print(ans)
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from math import log2,ceil
    from collections import defaultdict
    import sys
    input=sys.stdin.readline
    n=int(input())
    a=tuple(map(int,input().split()))
    mod=10**9+7
    cnt=defaultdict(lambda :0)

    for temp in a:
        if temp==0:continue
        digit=len(bin(temp))-2
        for j in range(ceil(digit)+1):
            if (temp>>j)&1:
                cnt[j]=cnt[j]+1

    #print(cnt)
    ans=0
    for digit,count in cnt.items():
        ans=(ans+pow(2,digit)*count*(n-count))%mod
    print(ans)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import log2,ceil
from collections import defaultdict
import sys
input=sys.stdin.readline
n=int(input())
a=tuple(map(int,input().split()))
mod=10**9+7
cnt=defaultdict(lambda :0)

for temp in a:
    if temp==0:continue
    digit=len(bin(temp))-2
    for j in range(ceil(digit)+1):
        if (temp>>j)&1:
            cnt[j]=cnt[j]+1

#print(cnt)
ans=0
for digit,count in cnt.items():
    ans=(ans+pow(2,digit)*count*(n-count))%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
from math import log2,ceil
from collections import defaultdict
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
cnt=defaultdict(lambda :0)

for i in range(n):
    temp=a[i]
    if temp==0:continue
    digit=len(bin(temp))-2
    for j in range(ceil(digit)+1):
        if (temp>>j)&1:
            cnt[j]+=1

#print(cnt)
ans=0
for digit,count in cnt.items():
    ans=(ans+pow(2,digit)*count*(n-count))%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
from math import log2,ceil
from collections import defaultdict
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
cnt=defaultdict(lambda :0)

for i in range(n):
    temp=a[i]
    if temp==0:continue
    digit=log2(temp)
    for j in range(ceil(digit)+1):
        if (temp>>j)&1:
            cnt[j]+=1

#print(cnt)
ans=0
for digit,count in cnt.items():
    ans=(ans+pow(2,digit)*count*(n-count))%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
from math import log2,ceil
from collections import defaultdict
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
cnt=defaultdict(lambda :0)
for i in range(n):
    temp=a[i]
    if temp==0:continue
    digit=log2(temp)
    for j in range(ceil(digit)+1):
        if (temp>>j)&1:
            cnt[j]+=1

#print(cnt)
ans=0
for digit,count in cnt.items():
    ans+=pow(2,digit)*count*(n-count)
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
from math import log2
def main():
    N = int(input())
    A = list(map(int,input().split()))
    mod = 10**9+7
    
    digits_cnt1 = [0]*60
    for ai in A:
        if ai == 0:
            continue
        #2**60-1みたいな時にfloatの桁落ちが生じるが、ai>>dが必ずfalseになるのでlist index out of rangeは生じない
        for d in range(int(log2(ai))+1):
            if ai>>d & 1:
                digits_cnt1[d] += 1
    
    ans = 0
    for i in range(60):
        ans += digits_cnt1[i]*(N-digits_cnt1[i])*pow(2,i,mod)
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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):
    count = sum(1 for j in a if j>>i & 1)
    ans += count * (n-count) * pow(2,i,mod)
print(ans % mod)

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):
    count = 0
    for j in a:
        if j >> i & 1:
            count += 1
    ans += count * (n-count) * pow(2,i,mod)
print(ans % mod)

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):
    count = 0
    for j in a:
        if j >> i & 1:
            count += 1
    ans += count * (n-count) * 2** i
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
tasu=[0 for i in range(60)]
A=list(map(int,input().split()))
for i in range(N):
  j=0
  a=bin(A[i])
  while a[-j-1]!="b":
    tasu[j]+=int(a[-j-1])
    j+=1
INF = 1000000007
ans=sum(tasu[i]*(N-tasu[i])<<i for i in range(60))%INF
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
keta = len(bin(max(A))) - 2
ans = 0
shift = 0
for _ in range(keta):
    num_1 = 0
    for i in range(N):
        if A[i]&1:
            num_1 += 1
        A[i]=A[i]>>1
    ans += num_1 * (N-num_1) * 2 ** shift
    shift += 1
print(ans % INF)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
keta = len(bin(max(A))) - 2
ans = 0
shift = 0
for _ in range(keta):
    num_1=sum([a>>shift&1 for a in A])
    ans += num_1 * ((N-num_1)<<shift%INF)
    shift += 1
print(ans % INF)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
keta = len(bin(max(A))) - 2
ans = 0
shift = 0
for _ in range(keta):
    num_1 = 0
    num_1=sum([a>>shift&1 for a in A])
    ans += num_1 * (N-num_1)<<shift % INF
    shift += 1
print(ans % INF)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
keta = len(bin(max(A))) - 2
ans = 0
shift = 0
for _ in range(keta):
    num_1 = 0
    num_1=sum([a>>shift&1 for a in A])
    ans += num_1 * (N-num_1)<<shift
    shift += 1
print(ans % INF)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
keta = len(bin(max(A))) - 2
ans = 0
shift = 0
for _ in range(keta):
    num_1 = 0
    num_1=sum([a>>shift&1 for a in A])
    ans += num_1 * (N-num_1) * 2 ** shift
    shift += 1
print(ans % INF)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
keta = len(bin(max(A))) - 2
ans = 0
shift = 0
for _ in range(keta):
    num_1 = 0
    for a in A:
        if a>>shift&1:
            num_1 += 1
    ans += num_1 * (N-num_1) * 2 ** shift
    shift += 1
print(ans % INF)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
ans = 0
keta = len(bin(max(A)))-2
shift = 0
while(shift < keta):
    c1 = 0
    c0 = 0
    for a in A:
        if a>>shift &1:
            c1 += 1
        else:
            c0 += 1
    ans += c1 * c0 * 2**shift
    shift += 1
print(ans % INF)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
# 愚直な回答
ans = 0
for i in range(0, N-1):
    for j in range(i+1, N):
        ans += A[i]^A[j]
print(ans % INF)

Submission status: Time Limit Exceeded

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

mod = pow(10,9)+7

K = 60
P = [0]*K
Z = [0]*K
for a in A:
    n = a
    for i in range(K):
        b = n%2
        if b:P[i]+=1
        else:Z[i]+=1
        n//=2
ans = 0
for k in range(K):
    ans+=(pow(2,k,mod)*(P[k]*Z[k]))%mod
print(ans%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

max_length = len("{:b}".format(max(A)))

cnt = [defaultdict(int) for _ in range(max_length)]

for i in range(N):
    num = "{:b}".format(A[i]).zfill(max_length)
    for j in range(len(num)):
        # [i桁目][numのj番目の数，(0 or 1)]
        # 0, 1 の数を数える
        cnt[max_length-1-j][num[j]] += 1

ans = 0

for i in range(max_length):
    # 1を左にiシフト(2 ** i 倍)
    # 桁内で0の個数 * 桁内で1の個数 が，XOR = 1になる数 (0 xor 1 = 1)
    ans = ans + (1 << i) * cnt[i]["0"] * cnt[i]["1"]
ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
	n, *a = map(int, open(0).read().split())
	mod = 10 ** 9 + 7
	l = [[x >> k & 1 for k in range(61)] for x in a]
	ll = [sum(t) for t in zip(*l)]
	ans = sum(s * (n - s) * (1 << i) % mod for i, s in enumerate(ll))
	print(ans % mod)

if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

result = 0
for i in range(62):
    count_one = sum(a%2)
    bina = 1
    for j in range(i):
        bina = bina*2%mod
    result += count_one*(n-count_one)*bina%mod
    a = a >> 1
print(result%mod)

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 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:
binary = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 73741817, 147483634, 294967268, 589934536, 179869065, 359738130, 719476260, 438952513, 877905026, 755810045, 511620083, 23240159, 46480318, 92960636, 185921272, 371842544, 743685088, 487370169, 974740338, 949480669, 898961331, 797922655, 595845303, 191690599, 383381198, 766762396, 533524785, 67049563, 134099126, 268198252, 536396504]

n = int(input())
a = [format(i,"b") for i in map(int, input().split())]
mod = 10**9+7
b = [0 for _ in range(61)]

for i in range(n):
    for j in range(len(a[i])):
        b[j] += int(a[i][-j-1])

result = 0
for i in range(61):
    r = b[i]*(n-b[i])%mod
    r = r*binary[i]%mod
    result += r
print(result%mod)

Submission status: Time Limit Exceeded

Solution code:
binary = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 73741817, 147483634, 294967268, 589934536, 179869065, 359738130, 719476260, 438952513, 877905026, 755810045, 511620083, 23240159, 46480318, 92960636, 185921272, 371842544, 743685088, 487370169, 974740338, 949480669, 898961331, 797922655, 595845303, 191690599, 383381198, 766762396, 533524785, 67049563, 134099126, 268198252, 536396504]

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
max_len = len(format(max(a), "b"))
b = [0 for _ in range(max_len)]

for i in range(n):
    count = 0
    while a[i] > 0:
        b[count] += a[i]%2
        a[i] //= 2
        count += 1

result = 0
for i in range(max_len):
    r = b[i]*(n-b[i])%mod
    r = r*binary[i]%mod
    result += r
print(result%mod)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [format(i, "b") for i in map(int, input().split())]
    mod = 10**9+7
    b = [0 for _ in range(61)]

    for i in range(n):
        for j in range(1, len(a[i])+1):
            b[j-1] += int(a[i][-j])

    result = 0
    for i in range(61):
        r = b[i]*(n-b[i])%mod
        for j in range(i):
            r = r*2 %mod
        result += r
    print(result%mod)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9+7
    max_len = len(format(max(a), "b"))
    b = [0 for _ in range(max_len)]

    for i in range(n):
        count = 0
        while a[i] > 0:
            b[count] += a[i]%2
            a[i] //= 2
            count += 1

    result = 0
    for i in range(max_len):
        r = b[i]*(n-b[i])%mod
        for j in range(i):
            r = r*2 %mod
        result += r
    print(result%mod)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
max_len = len(format(max(a), "b"))
b = [0 for _ in range(max_len)]

for i in range(n):
    count = 0
    while a[i] > 0:
        b[count] += a[i]%2
        a[i] //= 2
        count += 1

result = 0
for i in range(max_len):
    r = b[i]*(n-b[i])%mod
    for j in range(i):
        r = r*2 %mod
    result = result+r % mod
print(result%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
max_len = len(format(max(a), "b"))
b = [0 for _ in range(max_len)]

for i in range(n):
    count = 0
    while a[i] > 0:
        b[count] += a[i]%2
        a[i] //= 2
        count += 1

result = 0
for i in range(max_len):
    r = b[i]*(n-b[i])%mod
    r = (r*2**i) %mod
    result += r
print(result%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
max_len = len(format(max(a), "b"))
a = [format(a[i], "b") for i in range(n)]
b = [0 for _ in range(max_len)]

for i in range(n):
    for j in range(1, 1+len(a[i])):
        b[j-1] += int(a[i][-j])

result = 0
for i in range(max_len):
    r = b[i]*(n-b[i])%mod
    r = (r*2**i) %mod
    result += r
print(result%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
max_len = len(format(max(a), "b"))
a = [format(a[i], "b") for i in range(n)]
b = [0 for _ in range(max_len)]

for i in range(n):
    for j in range(1, 1+len(a[i])):
        if int(a[i][-j]):
            b[j-1] += 1

result = 0
for i in range(max_len):
    r = b[i]*(n-b[i])%mod
    r = (r*2**i) %mod
    result += r
print(result%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
max_len = len(format(max(a), "b"))
a = [format(a[i], "b") for i in range(n)]
b = [0 for _ in range(max_len)]

for i in range(n):
    for j in range(1, 1+len(a[i])):
        if int(a[i][-j]):
            b[j-1] += 1

result = 0
for i in range(max_len):
    r = b[i]*(n-b[i])
    for j in range(i):
        r = r*2 %mod
    result += r
print(result%mod)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7

class ModInt:
    def __init__(self, x):
        if isinstance(x, ModInt):
            self.value = x.value
        else:
            self.value = x % MOD
            if self.value < 0:
                self.value += MOD
    
    def get_mod(self):
        return MOD
    
    # str関数を使用したとき
    def __str__(self):
        return str(self.value)
    
    def __int__(self):
        return self.value
    
    __index__ = __int__
    
    # print関数を使用したとき
    __repr__ = __str__

    ## 四則演算
    def __add__(self, other):
        return ModInt(self.value + ModInt(other).value)
    
    def __sub__(self, other):
        return ModInt(self.value - ModInt(other).value)

    def __mul__(self, other):
        return ModInt(self.value * ModInt(other).value)
    
    def __truediv__(self, other):
        # a * a^(p - 2) ≡ 1 (mod p) 逆元から求める
        return ModInt(self.value * pow(ModInt(other).value, MOD - 2, MOD))

    # 累乗
    def __pow__(self, other):
        return ModInt(pow(self.value, ModInt(other).value, MOD))

    ## 四則演算の順序
    __radd__ = __add__

    def __rsub__(self, other):
        return ModInt(other - self.value)
    
    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return ModInt(other * pow(self.value, MOD - 2, MOD))

    def __rfloordiv__(self, other):
        return ModInt(other // self.value)
    
    # 累乗の順序
    def __rpow__(self, other):
        return ModInt(pow(other, self.value, MOD))
    
    ## 不等号
    def __lt__(self, other):
        return self.value < ModInt(other).value
    
    def __gt__(self, other):
        return self.value > ModInt(other).value

    def __le__(self, other):
        return self.value <= ModInt(other).value
    
    def __ge__(self, other):
        return self.value >= ModInt(other).value
    
    def __eq__(self, other):
        return self.value == ModInt(other).value
    
    def __ne__(self, other):
        return self.value != ModInt(other).value
    
    ## in-place 演算子(+=, -=, *=, /=)
    def __iadd__(self, other):
        self.value += ModInt(other).value
        if self.value >= MOD:
            self.value -= MOD
        return self.value
    
    def __isub__(self, other):
        self.value -= ModInt(other).value
        if self.value < 0:
            self.value += MOD
        return self.value
    
    def __imul__(self, other):
        self.value = ModInt(self.value * ModInt(other).value)
        return self.value

    def __itruediv__(self, other):
        self.value = ModInt(self.value * pow(ModInt(other).value, MOD - 2, MOD))
        return self.value
    
    # 逆元
    def modinv(self):
        return ModInt(pow(self.value, MOD - 2, MOD))

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

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

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 sys
input = sys.stdin.readline

def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
 
  ans = 0
  for i in range(60):
    count_one = sum(a>>i & 1 for a in A)
    ans += count_one * (N - count_one) * pow(2, i)
 
  print(ans%MOD)
  
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

sum = 0

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

Submission status: Time Limit Exceeded

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

b = [format(x,'b').zfill(60) for x in a]

ones = [0 for i in range(60)]
for x in b:
    for i in range(60):
        if x[59-i]=='1':
            ones[i] += 1

pow_two = [pow(2,i,mod) for i in range(60)]

ans = 0
for x in b:
    for i in range(60):
        if x[59-i]=='0':
            ans += ones[i]*pow_two[i]
        else:
            ans += (n-ones[i])*pow_two[i]


print((ans//2)%mod)

Submission status: Time Limit Exceeded

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

b = [format(x,'b').zfill(60) for x in a]
b = [list(reversed(x)) for x in b]


ones = [0 for i in range(60)]
for x in b:
    for i in range(60):
        if x[i]=='1':
            ones[i] += 1

pow_two = [pow(2,i,mod) for i in range(60)]

ans = 0
for i in range(60):
    ans += ones[i]*(n-ones[i])*pow_two[i]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines  

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

ans = 0
for k in range(60):
  x0 = 0 # k桁目のbitが0になる総数
  x1 = 0 # k桁目のbitが1になる総数
  # k桁目が 0, 1 のどちらかを数えておく
  for a in A:
    if a>>k & 1:
      x1 += 1
    else:
      x0 += 1
  p = 1
  for i in range(k):
    p *= 2
    p %= MOD
  # x0 * x1 が 0, 1 の組み合わせ数
  cnt = (x0 * x1) % MOD
  ans += cnt * p
  ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

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


def mod_pow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        half_p = p // 2
        half = mod_pow(a, half_p)
        return half * half % mod
    else:
        return a * mod_pow(a, p - 1) % mod


ans = 0
for i in range(60):
    cnt = 0
    for a in A:
        if a >> i & 1:
            cnt += 1
    now = cnt * (N - cnt) % mod
    ans += now * 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()))
mod = 10 ** 9 + 7


def mod_pow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        half_p = p // 2
        half = mod_pow(a, half_p)
        return half * half % mod
    else:
        return a * mod_pow(a, p - 1) % mod


ans = 0
for i in range(60):
    cnt = 0
    for a in A:
        if a >> i & 1:
            cnt += 1
    ans += cnt * (N - cnt) * mod_pow(2, 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):
    cnt = 0
    for a in A:
        if a >> i & 1:
            cnt += 1
    ans += cnt * (N - cnt) * pow(2, 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):
    cnt = 0
    for a in A:
        x = bin(a)[2:][::-1]
        if not i < len(x):
            continue
        b = int(x[i])
        if b == 1:
            cnt += 1
    ans += cnt * (N - cnt) * pow(2, 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(62):
    cnt=0
    for j in range(n):
        cnt+=A[j]&1 #1とのANDで一番右の桁を抽出
        A[j]>>=1 #ビットシフト
    ans+=cnt*(n-cnt)*(2**i)%mod
    ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#XORはビットごとに独立しているので各ビットで0*1の演算回数を数える
n=int(input())
A=list(map(int,input().split()))
B=[0]*62 #1の個数カウント
mod=10**9+7

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

ans=0
cnt=1 #2の累乗管理
for b in range(len(B)):
    prd=B[-b-1]*(n-B[-b-1])
    ans+=prd*cnt%mod
    cnt*=2
    ans%=mod
    cnt%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#XORはビットごとに独立しているので各ビットで0*1の演算回数を数える
n=int(input())
A=list(map(int,input().split()))
B=[0]*62 #1の個数カウント
mod=10**9+7

for i in range(n):
    a=bin(A[i])[2:]
    for j in range(len(a)):
        if a[-j-1]=="1":
            B[-j-1]+=1
ans=0
cnt=1 #2の累乗管理
for b in range(len(B)):
    prd=B[-b-1]*(n-B[-b-1])
    ans+=prd*cnt%mod
    cnt*=2
    ans%=mod
    cnt%=mod
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
    a=bin(A[i])[2:]
    for j in range(len(a)):
        B[-j-1]+=int(a[-j-1])
ans=0
cnt=1
for b in range(len(B)):
    prd=B[-b-1]*(n-B[-b-1])
    ans+=prd*cnt%mod
    cnt*=2
    ans%=mod
    cnt%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
mod = 10**9 + 7


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


A = [format(a, "060b")[::-1] for a in A]

answer = 0
for i in range(60):
    x, y = 0, 0
    for a in A:
        if a[i] == "0":
            x += 1
        else:
            y += 1
    answer += (x * y) * 2**i
    answer %= mod


print(answer)

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
for i in range(60):
    count_1=len([i for i in A if i%2==1])
    ans +=2**i*count_1*(n-count_1)
    A >>=1

print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
 
for i in range(N): A[i] = format(A[i], "#b") #ここで全て二進数に変換
#print(A)

sum = 0
c1 = [0]*60
for i in range(N):
    for j in range(60):
        #print(i,j,A[i][-(j+1)])
        if A[i][-(j+1)] == "0": #str型であることに注意！
            continue
        elif A[i][-(j+1)] == "1":
            c1[j] += 1
        else:
            break

#print("c1 =",c1)
for i in range(60):
    print
    sum += (c1[i] * (N-c1[i])) << i
    sum %= mod
 
print(sum%mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
 
for i in range(N): A[i] = format(A[i], "#b") #ここで全て60ビットの二進数に変換
#print(A)

sum = 0
c0 = [0]*60
c1 = [0]*60
for i in range(N):
    for j in range(60):
        if A[i][-(j+1)] == "0": #str型であることに注意！
            c0[j] += 1
        elif A[i][-(j+1)] == "1":
            c1[j] += 1
        else:
            break
 
for i in range(60):
    if c1[i] > 0:
        c0[i] = N - c1[i] 
    sum += (c0[i] * c1[i]) << i
    sum %= mod
 
print(sum%mod)

Submission status: Time Limit Exceeded

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

for i in range(N): A[i] = format(A[i], "#062b")

#print(*A,sep="\n")
nijou = 1 #二乗計算を高速化するため
xorsum = 0
for i in range(60):
    count0 = 0
    count1 = 0
    for j in range(N):
        if A[j][-(i+1)] == "0":
            count0 += 1
        else:
            count1 += 1
    xorsum += ((count0*count1)%mod)*nijou%mod
    nijou *= 2

print(xorsum%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
m = len(bin(max(A)))-2
zero = [0]*m
one = [0]*m
for a in A:
  for i in range(m):
    j = (a>>i)&1
    zero[i] += 1-j
    one[i] += j
ans = 0
d = [0]*m
d[0] = 1
for i in range(1,m):
  d[i] = (2*d[i-1])%mod
for i in range(m):
  ans = (ans+(zero[i]%mod)*(one[i]%mod)*d[i])%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
m = len(bin(max(A)))-2
zero = [0]*m
one = [0]*m
for a in A:
  for i in range(m):
    zero[i] += 1-(a>>i)&1
    one[i] += (a>>i)&1
ans = 0
for i in range(m):
  ans = (ans+zero[i]*one[i]*2**i)%mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
cnt0=[0]*60
cnt1=[0]*60
mod=10**9+7
for i in a:
  for j in range(60):
    if (i>>j)&1:
      ans+=(cnt0[j]*(1<<j))%mod
    else:
      ans+=(cnt1[j]*(1<<j))%mod
  for j in range(60):
    if (i>>j)&1:
      cnt1[j]+=1
    else:
      cnt0[j]+=1
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(N):
    for j in range(i+1,N):
        ans += (A[i]^A[j]) % mod
        ans = ans%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# from math import sqrt
# from heapq import heappush, heappop
# from collections import deque
# from functools import reduce

# a, b = [int(v) for v in input().split()]


def main():
    mod = 1000000007
    N = int(input())
    A = [int(v) for v in input().split()]

    total = 0
    for i, ai in enumerate(A):
        for aj in A[i+1:]:
            total += (ai ^ aj) % mod
    print(total % mod)


main()

Submission status: Time Limit Exceeded

Solution code:
# from math import sqrt
# from heapq import heappush, heappop
# from collections import deque
# from functools import reduce

# a, b = [int(v) for v in input().split()]


def main():
    mod = 1000000007
    N = int(input())
    A = [int(v) for v in input().split()]

    total = 0
    for i, ai in enumerate(A):
        for aj in A[i+1:]:
            total += ai ^ aj
    print(total % mod)


main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(_) for _ in input().split()]
const = 10**9 + 7

ans = 0

zero = [0] * 60
one = [0] * 60

for i in range(n):
    for j in range(60):
        if a[i] >> j & 1:
            one[j] += 1
        else:
            zero[j] += 1

ans = 0

for i in range(60):
    ans += one[i] * zero[i] * 2**i
    ans %= const

print(ans)