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:
from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0

    for i in range(n - 1):
        for j in range(i + 1, n):
            ans += a[i] ^ a[j]
            ans %= mod

    print(ans % mod)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy
from collections import deque
import bisect
import fractions
import math
import itertools

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

sum = 0
for a in list(itertools.combinations(A,2)):
    sum += a[0] ^ a[1]
    sum = sum%(10**9+7)

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
mod = 10 ** 9 + 7
N = int(input())
A = [int(i) for i in sys.stdin.readline().rstrip().split()]
ans = 0
for i in range(60):
  count = sum(1 for data in A if data & (1<<i))
  ans += count * (N-count) * pow(2,i,mod)
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import sys
mod = 10 ** 9 + 7
N = int(input())
A = [int(i) for i in sys.stdin.readline().rstrip().split()]
ans = 0
for i in range(60):
  count = 0
  for data in A:
    if data & (1<<i):
      count += 1
  ans += ((count % mod) * ((N-count) % mod) * pow(2,i,mod)) % mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

div = pow(10,9)+7

print(sum%div)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
#import bisect
#from collections import deque
import math

#############################
#         59 58 57     1
# Ai = 0xbi bi bi ... bi
# 
#############################

#############################
#   N-1 N
#   Σ   Σ     (Ai xor Aj)
#   i=1 j=i+1
#
#   59  N-1 N       d      d
# = Σ   Σ   Σ     (bi xor bj) * 2^(d-1)
#   d=1 i=1 j=i+1
#############################

#############################
#   N-1 N       d      d
#   Σ   Σ     (bi xor bj)
#   i=1 j=i+1
#
# = (bx のうち 1 の数) * (bx のうち 0 の数)
#############################

def input():
    return sys.stdin.readline().rstrip('\n')

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

s = 0 #sum

for d in range(60):
    B = [1 & (a >> d) for a in A]
    s += B.count(1) * B.count(0) * (2**d)
    #print(d,B,B.count(1),B.count(0),2**(d-1),s)

#print(s)
print(s % (10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
a = [int(i) for i in sys.stdin.readline().rstrip().split()]
mod = 10 ** 9 + 7

ans=0
for i in range(n):
  for j in range(i+1,n):
    ans += a[i]^a[j]
print(ans % mod)

Submission status: Time Limit Exceeded

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

mod=10**9+7
ans=0

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

    
print(ans)

Submission status: Time Limit Exceeded

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

mod=10**9+7
ans=0

for i in range(60):
    a=b=0
    for x in A:
        if x>>i&1:
            a+=1
        else:
            b+=1
    ans+=(a*b%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
ans=0
cnt=[[0]*2 for _ in range(60)]

for x in A:
    for i in range(60):
        a=x%2
        x//=2
        cnt[i][a]+=1

for p,q in enumerate(cnt):
    i,j=q
    ans+=((i*j)%mod)*pow(2,p,mod)
    ans%=mod
    
print(ans)

Submission status: Time Limit Exceeded

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

mod=10**9+7
ans=0
cnt=[[0]*2 for _ in range(60)]

for x in A:
    c=0
    for i in range(60):
        a=x%2
        x//=2
        cnt[i][a]+=1

for p,q in enumerate(cnt):
    i,j=q
    ans+=(i*j)*pow(2,p,mod)
    ans%=mod
    
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = [0 for i in range(n)]
a = [int(s) for s in input().split()]
res = 0

dig_0 = [0 for i in range(60)]
dig_1 = [0 for i in range(60)]

for i in range(n):
    #print("----")
    for j in range(60):
        #print(bin(a[i]>>j))
        s = bin(a[i]>>j)[-1]
        if(s == "1"):
            dig_1[j] += 1
        else:
            dig_0[j] += 1

#print(dig_1)
for i in range(60):
    #print(dig_0[i],dig_1[i])
    res += dig_0[i]*dig_1[i]*2**i
    #print(res)
md = 10**9 + 7
print(res%md)

Submission status: Time Limit Exceeded

Solution code:
def pad(S,N):
    return (N-len(S)) * "0" + S

def xor_sum(A,M):
    N = len(A)
    bit_count = [0 for _ in range(60)]
    #bit_count[i]:iビット目が1であるa in Aの個数

    for i in range(N):
        A[i] = pad(bin(A[i])[2:],60)
        for j in range(60):
            if A[i][60-j-1] == "1":
                bit_count[j] += 1

    output = 0
    for j in range(60):
        tmp1 = (N-bit_count[j])*bit_count[j] % M
        tmp2 = pow(2,j,M)
        tmp = (tmp1 * tmp2) % M
        output += tmp
        output %= M

    return output

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

    print(xor_sum(A,M))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    mod = 10**9 + 7
    b = [0] * 60
    for ai in a:
        for k in range(ai.bit_length()):
            b[k] += ai & 1
            ai //= 2
    c = 0
    for k in range(60):
        c = (c + b[k] * (n - b[k]) * pow(2, k, mod)) % mod
    print(c)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    mod = 10**9 + 7
    b = [0] * 60
    for ai in a:
        for k in range(60):
            if ai == 0:
                break
            b[k] += ai % 2
            ai //= 2
    c = 0
    for k in range(60):
        c = (c + b[k] * (n - b[k]) * pow(2, k, mod)) % mod
    print(c)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = max(a).bit_length()
    mod = 10**9 + 7
    bk = [[0] * n for _ in range(k)]
    for kk in range(k):
        for i in range(n):
            bk[kk][i] = a[i] // 2**kk % 2
    bc = [[bk[kk][-1]] * n for kk in range(k)]
    for kk in range(k):
        for i in range(n - 1, 0, -1):
            bc[kk][i - 1] = bc[kk][i] + bk[kk][i - 1]
    c = 0
    for kk in range(k):
        kc = 0
        for i in range(n - 1):
            if bk[kk][i] == 0:
                kc = (kc + bc[kk][i + 1]) % mod
            else:
                kc = (kc + n - 1 - i - bc[kk][i + 1]) % mod
        kc = kc * pow(2, kk, mod) % mod
        c = (c + kc) % mod
    print(c)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = max(a).bit_length()
    mod = 10**9 + 7
    c = 0
    for kk in range(k):
        h, l = 0, 0
        for ai in a:
            if ai // 2**kk % 2:
                h += 1
            else:
                l += 1
        kc = h * l * pow(2, kk, mod) % mod
        c = (c + kc) % mod
    print(c)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
alist=list(map(int,input().split()))
sosu=10**9+7
tenlist=[0]*60

for a in alist:
    tmp=str(format(a,"b"))
    for i in range(len(tmp)):
        if tmp[-(i+1)]=="1":
            tenlist[i] = tenlist[i]+1

out=0
for i, ten in enumerate(tenlist):
    out += (ten*(n-ten))*pow(2,i,sosu)
    out %= sosu


print(int(out))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    ret = 0
    magni = 1
    for j in range(60):
        bin_cnt = [0, 0]
        for i in range(n):
            a[i], b = divmod(a[i], 2)
            bin_cnt[b] += 1
        x, y = bin_cnt
        ret += x * y * magni % mod
        magni = magni * 2 % mod

    ret %= mod

    print(ret)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

    bin_list = [[0, 0] for _ in range(60)]

    for j in range(60):
        for i in range(n):
            a[i], b = divmod(a[i], 2)
            bin_list[j][b] += 1

    sum_ = 0
    for j in range(60):
        sum_ += bin_list[j][0] * bin_list[j][1] * (2 ** j) % mod
        sum_ %= mod

    print(sum_)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

    bin_list = [[0, 0] for _ in range(60)]

    for num in a:
        for j in range(60):
            b = (num >> j) & 1
            bin_list[j][b] += 1

    sum_ = 0
    for j in range(60):
        sum_ += bin_list[j][0] * bin_list[j][1] * (2 ** j) % mod
        sum_ %= mod

    print(sum_)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9+7
    zero = [0] * 61
    one = [0] * 61
    for i in range(n):
        for j in range(61):
            if a[i]>>j  & 1:
                one[j] += 1
            else:
                zero[j] += 1
    ans = 0
    for i in range(60):
        ans += ((one[i]*zero[i]) * pow(2, i, mod)) % mod
        ans %= mod
    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
L=[0]*60
for i in range(N):
    l=list(map(int,format(A[i],'b')))
    for i in range(len(l)):
        if l[len(l)-i-1]==1:
            L[i]+=1
v=0
sum=0
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
for i in range(60):
    sum+=(L[i]*(N-L[i])*power(2,v))%(10**9+7)
    v+=1
print(sum%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
L=[0]*60
for i in range(N):
    l=list(map(int,format(A[i],'b')))
    for i in range(len(l)):
        if l[len(l)-i-1]==1:
            L[i]+=1
v=0
sum=0
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
for i in range(60):
    sum+=L[i]*(N-L[i])*power(2,v)
    v+=1
print(sum%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys

# import re
# import math
# import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
# import copy
# import heapq
# import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = na()

    lim = 60
    zero = [0 for _ in range(lim)]
    one = [0 for _ in range(lim)]

    for ai in a:
        for i in range(lim):
            if ai >> i & 1:
                one[i] += 1
            else:
                zero[i] += 1

    ans = 0
    for i in range(lim):
        ans += 2 ** i * zero[i] * one[i]
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7
ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
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:
N = int(input())
A = list(map(int, input().split()))

mod = 10**9 + 7
ans = 0

for d in range(60):
    n0, n1 = 0, 0
    for i in range(N):
        if (A[i] >> d) & 1:
            n1 += 1
        else:
            n0 += 1
    ans = (ans + (n0 * n1) * (1 << d))% 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 %= mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=list(map(int,input().split()))
    mod=10**9+7
    C1=[0]*60
    for a in A:
        ax=a
        for i in range(60):
            if ax&1:C1[i]+=1
            ax>>=1
            if ax==0:break
    ans=0
    for i,c in enumerate(C1):
        ans+=c*(n-c)*2**i%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=list(map(int,input().split()))
    mod=10**9+7
    max_n=len(format(max(A),'b'))
    C=[[0,0] for _ in range(max_n)]
    for a in A:
        ax=a
        for i in range(max_n):
            C[i][ax%2]+=1
            ax=ax//2
    ans=0
    for i,c in enumerate(C):
        ans+=c[0]*c[1]*2**i%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,*a=map(int,open(0).read().split())
mod=10**9+7
b0=np.array([0 for i in range(60)])
b1=np.array([0 for i in range(60)])
for i in range(n):
  ai=a[i]
  j=0
  while ai>0:
    if ai&1==1:
      b1[j]+=1
    else:
      b0[j]+=1
    j+=1
    ai>>=1
  b0[j:]+=1
ans=0
for i in range(60):
  ans+=(b0[i]*b1[i]*pow(2,i,mod))
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

MOD = 10**9+7
ans = 0

for i in range(60):
    x = 0 # i桁目が1である数の個数
    for j in range(n):
        if a[j]>>i&1: # "a[j]のi桁目が1である"という意味
            x += 1
    now = x*(n-x)%MOD
    for j in range(i):
        now = now*2%MOD # 2**60をかけると容易にオーバーフローするので、安全に2をかけるごとにMODをとっている
    ans += now
    ans %= MOD
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
"""
ビット演算, XOR

XORは桁ごとに独立して計算できるので、桁ごとに計算する
XORが1になるのは0と1を足した時。2つの数を足す時、一方の数のi桁目が1でもう一方の数のi桁目が0であれば、2つの数を足した時のi桁目が1になる
全部で数がn個あるとき、i桁目が1の数がx個ある場合は、i桁目が0の数がn-x個あることになるので、x*(n-x)個の組み合わせでi桁目のXORが1になる
"""

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

MOD = 10**9+7
ans = 0

for i in range(60):
    x = 0 # i桁目が1である数の個数
    for j in range(n):
        if a[j]>>i&1: # "a[j]のi桁目が1である"という意味
            x += 1
    now = x*(n-x)%MOD
    for j in range(i):
        now = now*2%MOD # 2**60をかけると容易にオーバーフローするので、安全に2をかけるごとにMODをとっている
    ans += now
    ans %= MOD
    
print(ans)

Submission status: Time Limit Exceeded

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

from itertools import combinations

MOD = 10**9+7
ans = 0

for c in combinations(a, 2):
    tmp = c[0]^c[1]
    tmp %= MOD
    ans += c[0]^c[1]
    ans %= MOD

print(ans%MOD)

Submission status: Time Limit Exceeded

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

lb0 = [0]*60
lb1 = [0]*60
for i in range(N):
  bs = format(A[i],"060b")
  for j in range(60):
    if bs[j] == "0":
      lb0[j] += 1
    if bs[j] == "1":
      lb1[j] += 1  
###
ans = 0
for i in range(60):
  ans += ((lb0[i]*lb1[i] %mod)*(2**(59-i) %mod)) %mod
  ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
m2 = [1 for i in range(60)]
for i in range(1,60):
    m2[i] = (m2[i-1]*2)%mod

n1 = np.zeros(60,dtype=int)
for i in a:
    sai = list(map(lambda x:int(x),str(format(i,'060b'))))
    n1 += sai

ans = 0
for i in range(60):
    ans = (ans+((n1[i]*(n-n1[i]))%mod*m2[59-i])%mod)%mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
m2 = [1 for i in range(60)]
for i in range(1,60):
    m2[i] = (m2[i-1]*2)%mod

n1 = np.zeros(60,dtype=int)
for i in a:
    sai = [int(i) for i in str(format(i,'060b'))]
    n1 += sai

ans = 0
for i in range(60):
    ans = (ans+((n1[i]*(n-n1[i]))%mod*m2[59-i])%mod)%mod

print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in range(n-1):
    for j in range(60):
        if al[i][j] == 0:
            ans = (ans+(sa[n-1][j]-sa[i][j])*m2[j])%mod
        else:
            ans = (ans+(n-1-i-sa[n-1][j]+sa[i][j])*m2[j])%mod

print(ans)

Submission status: Time Limit Exceeded

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

mod = 10**9+7

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

max_digit = 61

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

for i in range(len(a)):
    num_str = bin(a[i])[2:]
    # print(num_str)
    for j in range(len(num_str)):
        # print(num_str[-j-1])
        if num_str[-j-1] == "1":
            count_1[-j-1] += 1

# for i in range(max_digit):
#     count_0[i] = n-count_1[i]

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

Submission status: Time Limit Exceeded

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

mod = 10**9+7

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

max_digit = 61

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

for i in range(len(a)):
    num_str = bin(a[i])[2:]
    # print(num_str)
    for j in range(len(num_str)):
        # print(num_str[-j-1])
        if num_str[-j-1] == "1":
            count_1[-j-1] += 1

for i in range(max_digit):
    count_0[i] = n-count_1[i]

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)

Submission status: Time Limit Exceeded

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

ans = 0
for k in range(61):
    num1 = 0
    for a in A:
        if (a >> k) & 1:
            num1 += 1
    ans += (num1 * (N-num1)) << k
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for k in range(60):
    num1 = 0
    num0 = 0
    for a in A:
        if (a >> k) & 1:
            num1 += 1
        else:
            num0 += 1
    ans += num1 * num0 * pow(2, k) % mod
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for k in range(0, 100):
    num1 = 0
    num0 = 0
    for a in A:
        if (a >> k) & 1:
            num1 += 1
        else:
            num0 += 1

    ans += num1 * num0 * pow(2, k) % mod
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
bo=[0]*61
bz=[0]*61
for i in a:
  t=format(i,'061b')
  for j in range(61):
    if t[j]=='0':
      bz[j]+=1
    else:
      bo[j]+=1
bo=bo[::-1]
bz=bz[::-1]
x=0
for i in range(61):
  x+=bo[i]*bz[i]*(2**i)
  x%=m
print(x%m)

Submission status: Time Limit Exceeded

Solution code:
mod=10**9+7
n=int(input())
a=[format(int(i),'b') for i in input().split()]
d0=[0]*60
d1=[0]*60
ans=0
for i in a:
  d=i[::-1]
  l=len(i)
  for j in range(60):
    if j<l and d[j]=='1':
      d1[j]+=1
    else:
      d0[j]+=1
for j in range(60):
  ans+=d0[j]*d1[j]*(2**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=pow(10,9)+7
  ans=0
  bit=[0]*61 #bit[i]:2^iの位が1である物の個数
  for ai in a:
    for j in range(61):
      if ((ai>>j) & 1):
        bit[j]+=1
  for i in range(61):
    ans+=(pow(2,i)%mod)*bit[i]*(n-bit[i])
    ans%=mod
  print(ans)
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
def modpow(a: int, p: int, mod: int) -> int:
    # return a**p (mod MOD) O(log p)
    if p == 0:
        return 1
    if p % 2 == 0:
        half = modpow(a, p//2, mod)
        return half*half % mod
    else:
        return a * modpow(a, p-1, mod) % mod


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

ret = 0
cnt_1 = [0] * 60

for item in a_ls:
    for i in range(60):
        if len(bin(item)) <= i:
            continue
        elif bin(item)[-1-i] == '1':
            cnt_1[i] += 1

for i in range(60):
    tmp = ((n - cnt_1[i]) * cnt_1[i])
    tmp %= 10 ** 9 + 7
    tmp *= modpow(2, i, 10 ** 9 + 7)
    ret += tmp
    ret %= 10 ** 9 + 7

print(ret)

Submission status: Time Limit Exceeded

Solution code:
def modpow(a: int, p: int, mod: int) -> int:
    # return a**p (mod MOD) O(log p)
    if p == 0:
        return 1
    if p % 2 == 0:
        half = modpow(a, p//2, mod)
        return half*half % mod
    else:
        return a * modpow(a, p-1, mod) % mod


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

ret = 0
cnt_0 = [0] * 60
cnt_1 = [0] * 60

for item in a_ls:
    for i in range(60):
        if len(bin(item)) <= i:
            cnt_0[i] += 1
        elif bin(item)[-1-i] == '1':
            cnt_1[i] += 1
        else:
            cnt_0[i] += 1

for i in range(60):
    tmp = (cnt_0[i] * cnt_1[i])
    tmp %= 10 ** 9 + 7
    tmp *= modpow(2, i, 10 ** 9 + 7)
    ret += tmp
    ret %= 10 ** 9 + 7

print(ret)

Submission status: Time Limit Exceeded

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

ret = 0
cnt_0 = [0] * 60
cnt_1 = [0] * 60

for item in a_ls:
    for i in range(60):
        if len(bin(item)) <= i:
            cnt_0[i] += 1
        elif bin(item)[-1-i] == '1':
            cnt_1[i] += 1
        else:
            cnt_0[i] += 1

for i in range(60):
    tmp = (cnt_0[i] * cnt_1[i])
    for _ in range(i):
        tmp *= 2
        tmp %= 10 ** 9 + 7
    ret += tmp
    ret %= 10 ** 9 + 7

print(ret)

Submission status: Time Limit Exceeded

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

ret = 0
cnt_0 = [0] * 60
cnt_1 = [0] * 60

for item in a_ls:
    for i in range(60):
        if len(bin(item)) <= i:
            cnt_0[i] += 1
        elif bin(item)[-1-i] == '1':
            cnt_1[i] += 1
        else:
            cnt_0[i] += 1

for i in range(60):
    ret += (cnt_0[i] * cnt_1[i]) * (2 ** i)
    ret %= 10 ** 9 + 7

print(ret)

Submission status: Time Limit Exceeded

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

ret = 0

for i in range(60):
    cnt_0 = 0
    cnt_1 = 0
    for item in a_ls:
        if len(bin(item)) <= i:
            cnt_0 += 1
        elif bin(item)[-1-i] == '1':
            cnt_1 += 1
        else:
            cnt_0 += 1
    ret += cnt_1 * cnt_0 * (2 ** i)
    ret %= 10 ** 9 + 7

print(ret)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
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 = SUM+(A[i]^A[j])
    SUM %= 10**9+7

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

Submission status: Time Limit Exceeded

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

B=list(itertools.combinations(A, 2))
SUM=0

for b1, b2 in B:
  SUM += b1^b2
  SUM = SUM % (10**9+7)

print(SUM%(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(n - 1):
    for j in range(i,n):
        ans += a[i]^a[j]
        ans %= MOD
print(ans%MOD)

Submission status: Time Limit Exceeded

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

B=list(itertools.combinations(A, 2))
SUM=0

for b1, b2 in B:
  SUM += b1^b2

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

print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
n, *a = map(int, open(0).read().split())
MOD = 10**9 + 7
c = 0
for i in range(61):
  i = 2**i
  t = sum(i & b > 0 for b in a)
  c = (c + t * (n - t) * i) % MOD
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *a = map(int, read().split())
mod = 10 ** 9 + 7
ans = 0
x = 1
for bit in range(60):
    b = 0
    for i, aa in enumerate(a):
        if aa % 2:
            b += 1
        a[i] //= 2
    ans += (x * b * (n - b)) % mod
    ans %= mod
    x *= 2
    x %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *a = map(int, read().split())
mod = 10 ** 9 + 7
bit = [0] * 61
ans = 0
for aa in a:
    for j, check in enumerate(bin(aa)[2:][::-1]):
        if check == '1':
            bit[j] += 1
for i, b in enumerate(bit):
    ans += pow(2, i, mod) * ((n - b) * b % mod)
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = list(map(int, readline().split()))
mod = 10 ** 9 + 7
bit = [0] * 61
ans = 0
for aa in a:
    for j, check in enumerate(bin(aa)[2:][::-1]):
        if check == '1':
            bit[j] += 1
for i, b in enumerate(bit):
    ans += pow(2, i, mod) * ((n - b) * b % mod)
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = list(map(int, readline().split()))
mod = 10 ** 9 + 7
bit = [0] * 61
ans = 0
for aa in a:
    for j, check in enumerate(bin(aa)[2:][::-1]):
        if check == '1':
            bit[j] += 1
for i, b in enumerate(bit):
    ans += 2 ** i * (n - b) * b
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

table = [0] * 60

for a in A:
    for i in range(60):
        if (a>>i) & 1:
            table[i] += 1

ans = 0
for i ,t in enumerate(table):
    ans += t * (N-t) * 2**i
    ans %= MOD
print(ans)