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:
import sys
from collections import deque


input = sys.stdin.readline

def main():
    N = int(input().rstrip())
    A = list(map(int, input().rstrip().split()))
    M = max(max(A), 1).bit_length()
    B = [0] * M
    p = 10 ** 9 + 7
    ans = 0

    for n in range(N):
        a = deque(bin(A[n])[2:])
        for i in range(len(a)):
            B[i] += int(a.pop())

    for i, b in enumerate(B):
        tmp = b * (N - b) * 2 ** i
        tmp %= p
        ans = ans + tmp
        ans %= p

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys


input = sys.stdin.readline

def main():
    N = int(input().rstrip())
    A = list(map(int, input().rstrip().split()))
    M = max(A).bit_length()
    B = [0] * (M + 1)
    p = 10 ** 9 + 7
    ans = 0

    for n in range(N):
        a = bin(A[n])
        l = len(a)
        for i, j in enumerate(reversed(a[2:])):
            B[i] += int(j)

    for i, b in enumerate(B):
        tmp = b * (N - b) * 2 ** i
        tmp %= p
        ans = ans + tmp
        ans %= p

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

N = iin()
A = iln()

ans = 0
two_factor = 1
for i in range(60):
    zero_cnt = one_cnt = 0
    for j in range(N):
        if (A[j]>>i & 1): zero_cnt += 1
        else: one_cnt += 1
    zeroone_cmb = zero_cnt*one_cnt % MOD
    ans = (ans + (zeroone_cmb*two_factor) % MOD) % MOD
    two_factor = ((two_factor *2) % MOD)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

N = iin()
A = iln()

ans = 0
two_factor = 1
for i in range(60):
    zero_cnt = one_cnt = 0
    for j in range(N):
        if (A[j]>>i & 1): zero_cnt += 1
        else: one_cnt += 1
    zeroone_cmb = zero_cnt*one_cnt
    ans = (ans + (zeroone_cmb*two_factor) % MOD) % MOD
    two_factor *= 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

N = iin()
A = iln()

ans = 0
for i in range(60):
    odd = even = 0
    for j in range(N):
        if (A[j]>>i & 1): odd += 1
        else: even += 1
    ans = (ans+(odd*even)*pow(2,i,MOD))%MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')

N = iin()
A = iln()

ans = 0
for i in range(60):
    odd = even = 0
    for j in range(N):
        if (A[j]>>i & 1): odd += 1
        else: even += 1
    ans = (ans+(odd*even)*(2**i)%MOD)%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 range(n-1):
  for j in range(i+1,n):
    ans+=a[i]^a[j]
    ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, *a = map(int, open(0).read().split())
ans = 0
mod = 10 **9 + 7
for k in range(61):
	m = 1 << k
	c = 0
	for x in a:
		if m & x:
			c += 1
	ans +=c * (n - c) * m
	ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    A = [format(a, "b")[::-1] for a in A]
    a_sum = [int()]*60

    for a in A:
        for i, r_a in enumerate(a):
            if r_a == "1":
                a_sum[i] += 1

    a_sum = [a_s_*(2**i)%MOD for i, a_s_ in zip(range(60), a_sum)]
    a_acc_sum = [_ for _ in a_sum]
    for x in range(1,60):
        a_acc_sum[x] = a_acc_sum[x-1] + a_acc_sum[x] 
    
    ans = 0
    for a in A:
        for i, r_a in enumerate(a):
            if r_a == "0":
                ans += a_sum[i]
        
        ans += a_acc_sum[59] - a_acc_sum[i]

        # for ic in range(i+1,60):
            # ans+=a_sum[ic]
            # ans%=MOD

    print(ans%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:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    a_sum = [int()]*60

    for a in A:
        for i, r_a in enumerate(format(a, "b")[::-1]):
            if r_a == "1":
                a_sum[i] += 1

    a_sum = [a_s_*(2**i)%MOD for i, a_s_ in zip(range(60), a_sum)]
    a_acc_sum = [_ for _ in a_sum]
    for x in range(1,60):
        a_acc_sum[x] = a_acc_sum[x-1] + a_acc_sum[x] 
    
    ans = 0
    for a in A:
        for i, r_a in enumerate(format(a, "b")[::-1]):
            if r_a == "0":
                ans += a_sum[i]
        
        ans += a_acc_sum[59] - a_acc_sum[i]

        # for ic in range(i+1,60):
            # ans+=a_sum[ic]
            # ans%=MOD

    print(ans%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:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    a_sum = [int()]*60

    for a in A:
        for i, r_a in enumerate(format(a, "b")[::-1]):
            if r_a == "1":
                a_sum[i] += 1

    a_sum = [a_s_*(2**i)%MOD for i, a_s_ in zip(range(60), a_sum)]
    a_acc_sum = a_sum.copy()
    for x in range(1,60):
        a_acc_sum[x] = a_acc_sum[x-1] + a_acc_sum[x] 
    
    ans = 0
    for a in A:
        for i, r_a in enumerate(format(a, "b")[::-1]):
            if r_a == "0":
                ans += a_sum[i]
        
        ans += a_acc_sum[59] - a_acc_sum[i]

        # for ic in range(i+1,60):
            # ans+=a_sum[ic]
            # ans%=MOD

    print(ans%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:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    a_sum = [int()]*60

    for a in A:

        for i, r_a in enumerate(format(a, "b")[::-1]):
            if r_a == "1":
                a_sum[i] += 1

    a_sum = [a_s_*(2**i)%MOD for i, a_s_ in zip(range(60), a_sum)]

    ans = 0
    for a in A:
        for i, r_a in enumerate(format(a, "b")[::-1]):
            if r_a == "0":
                ans += a_sum[i]
        
        for ic in range(i+1,60):
            ans+=a_sum[ic]
            ans%=MOD

    print(ans%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:
from collections import Counter
MOD = 10**9+7
n = int(input())
A = ['{:060b}'.format(a)[::-1] for a in map(int, input().split())]
A_d = []
for col in zip(*A):
    c = Counter(map(int, col))
    A_d.append(c[0]*c[1])

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
MOD = 10**9+7
n = int(input())
A = ['{:060b}'.format(a)[::-1] for a in map(int, input().split())]

A_d = []
for col in zip(*A):
    c = Counter(map(int, col))
    A_d.append(c[0]*c[1])

ans = 0
for d in range(60):
    ans = ans + A_d[d]*pow(2, d, MOD) % 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
b = [0] * len(a)

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

print(ans)

Submission status: 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-1):
    for j in range(i+1,N):
        ans+=A[i]^A[j]
ans=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(len(A)-1):
    for j in range(i+1,len(A)):
        ans+=(A[i]^A[j])
ans=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(len(A)-1):
    for j in range(i+1,len(A)):
        ans+=(A[i]^A[j])%mod
ans=ans%mod
print(ans)

Submission status: Time Limit Exceeded

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

tmpsum = 0

for i in range(N):
  for j in range(i,N):
    tmpsum += A[i]^A[j]

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

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(len(A)-1):
    for j in range(i+1,len(A)):
        a=A[i]
        b=A[j]
        ans+=(a^b)
ans=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(len(A)-1):
    for j in range(i+1,len(A)):
        ans+=(A[i]^A[j])%mod
ans=ans%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def powmod(x, y, mod):
    if y == 0:
        return 1
    return (((powmod(x, y >> 1, mod) ** 2) % mod) * x ** (y & 1)) % mod


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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
M = list(map(int, input().split()))
M = [bin(m)[2:] for m in M]
max_len = max([len(m) for m in M])
M = ["0"*(max_len-len(m))+m for m in M]
MOD = 10**9+7
result = 0
for i in range(1, max_len+1):
  zero = len([m[-i] for m in M if m[-i]=="0"])
  one = len(M) - zero
  #print(one, zero, i)
  result += (((one * zero) % MOD) * ((2 ** (i-1)) % MOD) % MOD)
  result %= MOD
print(result)

Submission status: Time Limit Exceeded

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

MOD = 10**9 + 7

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

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

Cbn0 = [[0]*dig for i in range(n)]
Cbn1 = [[0]*dig for i in range(n)]

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

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

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

Submission status: Time Limit Exceeded

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

MOD = 10**9 + 7

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

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

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

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

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

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

Submission status: Time Limit Exceeded

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

MOD = 10**9 + 7

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

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def main():
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    mod = 10**9+7
    point = 0
    for i in range(61):
        now = sum(1 for j in a if(j >> i)&1)
        point += now*(n-now)*(2**i)
        point %= mod
    print(point)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
point = 0
kai = [2**i%mod for i in range(61)]
for i in range(61):
    now = sum(1 for j in a if(j >> i)&1)
    point += now*(n-now)*kai[i]
    point %= mod
print(point)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def main():
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    mod = 10**9+7
    point = 0
    kai = [2**i%mod for i in range(61)]
    for i in range(61):
        now = sum(1 for j in a if(j >> i)&1)
        point += now*(n-now)*kai[i]
        point %= mod
    print(point)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def main():
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    mod = 10**9+7
    point = 0
    kai = [2**i%mod for i in range(61)]
    for i in range(61):
        now = (sum(1 for j in a if(j >> i)&1))
        point += now*(n-now)*kai[i]%mod
    print(point%mod)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def main():
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    mod = 10**9+7
    point = 0
    kai = [2**i%mod for i in range(61)]
    for i in range(61):
        now = (sum(1 for j in a if(j >> i)&1))
        now *= (n-now)*kai[i]
        now %= mod
        point += now
    print(point%mod)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def main():
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    mod = 10**9+7
    point = 0
    kai = [2**i%mod for i in range(61)]
    for i in range(61):
        now = sum(1 for j in a if(j >> i)&1)
        now *= n-now
        now *= kai[i]
        point += now
    print(point%mod)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def main():
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    mod = 10**9+7
    point = 0
    kai = [2**i%mod for i in range(61)]
    for i in range(61):
        now = 0
        for j in a:
            now += (j >> i)&1
        now *= n-now
        now *= kai[i]
        point += now
    print(point%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
point = 0
for i in range(61):
    now = 0
    for j in a:
        now += (j >> i&1)
    now *= n-now
    now *= 2**i
    now %= mod
    point += now
print(point%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
point = 0
for i in range(61):
    now = 0
    for j in a:
        now += (j >> i&1)
    now *= n-now
    now %= mod
    for k in range(i):
        now *= 2
        now %= mod
    point += now
    point %= mod
print(point)

Submission status: Time Limit Exceeded

Solution code:
mod = 1000000007

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

print(s)

Submission status: Time Limit Exceeded

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

zero = [0] * 60
one = [1] * 60
pow2 = [2 ** i % M for i in range(60)]


def bitcnt(a):
    j = 0
    bits = [0] * 60
    while a:
        bits[j] = a & 1
        a >>= 1
        j += 1
    return bits


ans = 0
a1 = bitcnt(A[0])
a0 = [(x + 1) % 2 for x in a1]
for i in range(1, N):
    a = A[i]
    for j in range(60):
        b1 = a & 1
        a >>= 1
        b0 = (b1 + 1) % 2
        ans += pow2[j] * (a0[j] * b1 % M) % M
        ans += pow2[j] * (a1[j] * b0 % M) % M
        ans %= M
        a1[j] = (a1[j] + b1) % M
        a0[j] = (a0[j] + b0) % M

print(ans)

Submission status: Time Limit Exceeded

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

zero = [0] * 60
one = [1] * 60
pow2 = [2 ** i % M for i in range(60)]


def bitcnt(a):
    j = 0
    bits = [0] * 60
    while a:
        bits[j] = a & 1
        a >>= 1
        j += 1
    return bits


ans = 0
a1 = bitcnt(A[0])
a0 = [(x + 1) % 2 for x in a1]
for i in range(1, N):
    for j, b1 in enumerate(bitcnt(A[i])):
        b0 = (b1 + 1) % 2
        ans += pow2[j] * (a0[j] * b1 % M) % M
        ans += pow2[j] * (a1[j] * b0 % M) % M
        ans %= M
        a1[j] = (a1[j] + b1) % M
        a0[j] = (a0[j] + b0) % M

print(ans)

Submission status: Time Limit Exceeded

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

zero = [0] * 60
one = [1] * 60
pow2 = [2 ** i % M for i in range(60)]


def bitcnt(a):
    j = 0
    bits = [0] * 60
    while a:
        bits[j] = a & 1
        a >>= 1
        j += 1
    return bits


ans = 0
a1 = bitcnt(A[0])
a0 = [(x + 1) % 2 for x in a1]
for i in range(1, N):
    bits1 = bitcnt(A[i])
    bits0 = [(x + 1) % 2 for x in bits1]
    ans += sum(pow2[i] * (a0[i] * bits1[i] % M) % M for i in range(60))
    ans %= M
    ans += sum(pow2[i] * (a1[i] * bits0[i] % M) % M for i in range(60))
    ans %= M
    a1 = [(a1[i] + bits1[i]) % M for i in range(60)]
    a0 = [(a0[i] + bits0[i]) % M for i in range(60)]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

zero = np.zeros(60, dtype=np.int64)
one = np.ones(60, dtype=np.int64)
pow2 = (2 ** np.arange(60, dtype=np.int64)) % M


def bitcnt(a):
    j = 0
    bits = np.zeros(60, dtype=np.int64)
    while a:
        bits[j] = a & 1
        a >>= 1
        j += 1
    return bits


ans = 0
a1 = bitcnt(A[0])
a0 = one - a1
for i in range(1, N):
    bits1 = bitcnt(A[i])
    bits0 = one - bits1
    ans += np.sum(pow2 * (a0 * bits1 % M) % M) % M
    ans %= M
    ans += np.sum(pow2 * (a1 * bits0 % M) % M) % M
    ans %= M
    a1 += bits1
    a1 %= M
    a0 += bits0
    a0 %= M

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

zero = np.zeros(62, dtype=np.int64)
one = np.ones(62, dtype=np.int64)
pow2 = (2 ** np.arange(62, dtype=np.int64)) % M


def bitcnt(a):
    j = 0
    bits = np.zeros(62, dtype=np.int64)
    while a:
        bits[j] = a & 1
        a >>= 1
        j += 1
    return bits


ans = 0
a1 = bitcnt(A[0])
a0 = one - a1
for i in range(1, N):
    bits1 = bitcnt(A[i])
    bits0 = one - bits1
    ans += np.sum(pow2 * (a0 * bits1 % M) % M) % M
    ans %= M
    ans += np.sum(pow2 * (a1 * bits0 % M) % M) % M
    ans %= M
    a1 += bits1
    a1 %= M
    a0 += bits0
    a0 %= M

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

zero = np.zeros(62, dtype=np.int64)
one = np.ones(62, dtype=np.int64)
pow2 = (2 ** np.arange(62, dtype=np.int64)) % M


def bitcnt(a):
    j = 0
    bits = np.zeros(62, dtype=np.int64)
    while a:
        bits[j] = a & 1
        a >>= 1
        j += 1
    return bits


ans = 0
a1 = bitcnt(A[0])
a0 = one - a1
for i in range(1, N):
    bits1 = bitcnt(A[i])
    bits0 = one - bits1
    ans += np.sum(pow2 * (a0 * bits1 % M) % M) % M
    ans %= M
    ans += np.sum(pow2 * (a1 * bits0 % M) % M) % M
    ans %= M
    a1 += bits1
    a0 += bits0

print(ans)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
p = 1000000007
max_n = len(bin(max(A)))-2
mask = 1
s = 0
for i in range(max_n):
  s0 = 0
  s1 = 0
  for j in range(N):
    s0 += (A[j] & (mask << i)) >> i
    s1 += (~(A[j] | ~(mask << i))) >> i
  s += ((2**i)*s0*s1)%p
print(s%p)

Submission status: Time Limit Exceeded

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

mod = 10 ** 9 + 7
digits = [0] * 60
ans = 0
for ai in a:
    temp = ai
    num = len(bin(temp)) - 2
    for i in range(num):
        if (temp >> i) & 1:
            digits[i] += 1
    ans += (n - 1) * temp
    ans = ans % mod

for i in range(60):
    digit = digits[i]
    temp = digit * (digit - 1) * pow(2, i, mod)
    ans -= temp % mod
print(ans % mod)
#print(digits)

Submission status: Time Limit Exceeded

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

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

    now = x*(n-x) % mod

    for j in range(i):
        now = now*2 % mod
    ans += now
    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())))

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

    now = x*(n-x) % mod

    for j in range(i):
        now = now*2 % mod
    ans += now
    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())))

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

    now = x*(n-x)

    for j in range(i):
        now = now*2
    ans += now
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,*l=map(int,open(0).read().split());a=0;M=10**9+7
for i in range(60):t=sum(j>>i&1 for j in l);a+=t*(n-t)*pow(2,i,M)
print(a%M)

Submission status: Time Limit Exceeded

Solution code:
from itertools import count

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

d_cumsum = [0] * 60
for v in a:
    for i in count():
        d_cumsum[i] += v % 2
        v //= 2
        if v == 0:
            break

res = 0
mod = 10**9 + 7
for i, d in enumerate(d_cumsum):
    res += (2**i * d * (n-d)) % mod
    res %= mod

print(res)

Submission status: Time Limit Exceeded

Solution code:
#xorの性質
#AxorA=0、交換法則、結合法則が成立、bitごとに独立して考える！

import numpy as np

n=int(input())
a=np.array(list(map(int,input().split())))
res=0
for j in range(60):
  s=0 #1の数
  for i in a:
    if (i>>j & 0b1)==0b1:
      s+=1
  r=2**j*(n-s)*s
  res=(res+r)%(10**9+7)
print(res)