Problem:


Score : 400 points

Problem Statement

We have N integers. The i-th integer is A_i.

Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

What is \mbox{ XOR }?

The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:

When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.

For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Constraints

2 \leq N \leq 3 \times 10^5

0 \leq A_i < 2^{60}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

Sample Input 1

3
1 2 3

Sample Output 1

6

We have (1\mbox{ XOR } 2)+(1\mbox{ XOR } 3)+(2\mbox{ XOR } 3)=3+2+1=6.

Sample Input 2

10
3 1 4 1 5 9 2 6 5 3

Sample Output 2

237

Sample Input 3

10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820

Sample Output 3

103715602

Print the sum modulo (10^9+7).



Sample input:
3
1 2 3


Sample output:
6

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=len(str(bin(max(nums))))-2
mat=[]
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    mat.append(list(num))
 
mat=list(zip(*mat))
ans=0
 
for i in range(k):
    b=mat[i].count("1")
    ans+=b*(N-b)*pow(2,(k-i-1),l)
print(ans%l)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=len(str(bin(max(nums))))-2
mat=[]
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    mat.append(list(num))

mat=list(zip(*mat))
ans=0

for i in range(k):
    b=mat[i].count("1")
    ans+=b*(N-b)*pow(2,(k-i-1),l)
print(ans%l)

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]
print(sum%1000000007)

Submission status: Time Limit Exceeded

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

d0 = [0]*100
d1 = [0]*100
for i in range(n):
    for j in range(61):
        if a[i] & (1<<j):
            d1[j] += 1
        else:
            d0[j] += 1

x = 1
ans = 0
mod = 10**9+7
for i in range(100):
    ans += x * d0[i] * d1[i] %mod
    x = x * 2 % mod
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

n = iip()
al = iip()

mod = 10**9 + 7
num1 = [0 for i in range(60)]

for a in al:
    b = bin(a)[2:].zfill(60)
    #print(b)
    for i in range(60):
        if b[i] == "1":
            num1[i] += 1

result = 0
for i, a in enumerate(num1):
    a1 = 2**(59-i) % mod
    a2 = (a * (n-a)) % mod
    result += a1*a2 % mod
    result = result % mod


#print(num1)
print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
# input = sys.stdin.buffer.readline
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

MOD = 10**9+7

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

ans = 0
for i in range(60):
    zero, one = 0, 0
    for j in range(N):
        if A[j]>>i&1:
            one += 1
        else:
            zero += 1
    ans += (one * zero)<<i
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7
N = int(input())
L = list(map(lambda x: bin(int(x))[2:], input().split()))
max_len = max([len(v) for v in L])
padL = ["0"*(max_len-len(v))+v for v in L]
cnt = [0]*max_len
for i in range(max_len):
    for l in padL:
        cnt[i] += 1 if l[i] == "1" else 0

ans = 0
v = 1
for i in range(max_len):
    ans += v*cnt[max_len-1-i]*(N-cnt[max_len-i-1])
    ans %= MOD
    v *= 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    ans = 0
    for i, a in enumerate(A[:-1]):
        ans += sum([a ^ b for b in A[i+1:]]) % MOD
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

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

ans = 0
two  = 1
for i in range(61):
  n = sum([int(bin(a>>i)[-1]) for a in A])
  ans += (n * (N - n) * two % MOD)
  two *= 2 
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

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

ans = 0
for i in range(61):
  n = sum([int(bin(a>>i)[-1]) for a in A])
  ans += (n * (N - n) * pow(2, i) % MOD)
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

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

ans = 0
for i in range(61):
  n = sum([int(bin(a>>i)[-1]) for a in A])
  ans += (n * (N - n) * (2 ** i) % MOD)
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)

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

ans = 0
for i in range(61):
  n = sum([int(bin(a>>i)[-1]) for a in A])
  ans += (n * (N - n) * (2 ** i) % MOD)
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)

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

ans = 0
for i in range(61):
  n = sum([int(bin(a>>i)[-1]) for a in A])
  ans += n * (N - n) * (2 ** i)
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(61):
  n = sum([int(bin(a>>i)[-1]) for a in A])
  ans += n * (N - n) * (2 ** i)
print(ans%MOD)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
from bisect import insort
sys.setrecursionlimit(10**9)

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

    ans = 0
    for mask in range(60): # 各桁ごとに、1を持つ数を探す
        one_sum = 0
        for a in A:
            one_sum += (a >> mask) & 1

        ans += one_sum * (N - one_sum) * 2**mask

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

if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
mod = 10**9 + 7

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

ans = 0
for i in range(n):
    a[i] = bin(a[i])[2:].zfill(60)

for i in range(60):
    count = 0
    for j in range(n):
        count += 1 if a[j][i] == '1' else 0

    ans += (pow(2, 59-i, mod) * count * (n-count)) % mod

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
mod = 10**9 + 7

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

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

Submission status: Time Limit Exceeded

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

n = int(input())
alist = tuple(map(int,input().split()))
anslist =[]
for i in range(n):
  for j in range(i+1,n):
    anslist.append((alist[i]^alist[j]))
s = sum(anslist)
print(s%(10**9+7))

Submission status: Time Limit Exceeded

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

n = int(input())
alist = tuple(map(int,input().split()))
anslist = tuple(alist[i]^alist[j] for i in range(n) for j in range(i+1,n))
s = sum(anslist)
if s < 10**9+7:
  print(s)
else:
  print(s%(10**9+7))

Submission status: Time Limit Exceeded

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

n = int(input())
alist = list(map(int,input().split()))
anslist = list(alist[i]^alist[j] for i in range(n) for j in range(i+1,n))
s = sum(anslist)
if s < 10**9+7:
  print(s)
else:
  print(s%(10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
bit=[[0]*60 for i in range(N+1)]
for i in range(1,N+1):
    for j in range(60):
        if(A[i-1]>>j&1):
            bit[i][j]=bit[i-1][j]+1
        else:
            bit[i][j]=bit[i-1][j]
res=0
for i in range(N):
    for j in range(60):
        if not (A[i]>>j&1):
            res=(res+(2**j)*bit[i][j])%MOD
        else:
            res=(res+(2**j)*(i-bit[i][j]))%MOD
print(res)

Submission status: Time Limit Exceeded

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

for i in range(60):
    s = sum([(a >> i) & 1 for a in A])
    ans = (ans + s * (n-s) * pow(2,i,mod)) % mod
print(ans)

Submission status: Time Limit Exceeded

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

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

mod = 10 ** 9 + 7
ans = 0
ni = 1

for i in range(60):
    x = sum([1 for j in range(N) if (A[j] >> i) & 1])
    buff = x * (N - x) * ni
    ans += buff
    ni = ni * 2

print(ans % mod)

Submission status: Time Limit Exceeded

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

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

mod = 10 ** 9 + 7
ans = 0
ni = 1

for i in range(60):
    x = sum([1 for j in range(N) if (A[j] >> i) & 1])
    buff = x * (N - x) % mod
    buff = buff * ni % mod
    ans += buff
    ans %= mod
    ni = ni * 2 % mod

print(ans)

Submission status: Time Limit Exceeded

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

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

mod = 10 ** 9 + 7
ans = 0

for i in range(60):
    x = 0
    for j in range(N):
        if (A[j] >> i) & 1:
            x += 1
    buff = x * (N - x) % mod
    for j in range(i):
        buff = buff * 2 % mod
    ans += buff
    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
    for j in range(N):
        if (A[j] >> i) & 1:
            x += 1
    buff = x * (N - x) % mod
    for j in range(i):
        buff = buff * 2 % mod
    ans += buff
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = list(map(int,input().split()))
t = max(L)
maxstr = ''
cur = 1
while t >= cur:
    if t&cur != 0:
        maxstr = '1'+maxstr
    else:
        maxstr = '0'+maxstr
    cur *= 2
calc = [0]*len(maxstr)
for i in range(n):
    cur = 1
    temp = len(maxstr)-1
    while L[i] >= cur:
        if L[i]&cur != 0:
            calc[temp] += 1
        cur *= 2
        temp -= 1
ans = 0
cur = 1
for i in range(len(maxstr)):
    ans += cur*calc[len(maxstr)-i-1]*(n-calc[len(maxstr)-i-1])
    ans %= 10**9+7
    cur *= 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    MOD=10**9+7
    n=int(input())
    x=[0 for i in range(60)]
    a=list(map(int,input().split()))

    for i in range(n):
        k=0
        while a[i]>0:
            if a[i]&1:
                x[k]+=1
            a[i]>>=1
            k+=1
    ans=0
    b=1
    for i in range(60):
        ans+=x[i]*(n-x[i])*b
        ans%=MOD
        b=(b*2)%MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
MOD=10**9+7
n=int(input())
x=[0 for i in range(60)]
a=list(map(int,input().split()))

for i in range(n):
    k=0
    while a[i]>0:
        if a[i]&1:
            x[k]+=1
        a[i]>>=1
        k+=1
ans=0
for i in range(60):
    ans+=x[i]*(n-x[i])*(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
p = [pow(2, i, mod) for i in range(60)]
ans = 0
for i in range(60):
    c = 0
    for j in a:
        if (j >> i) & 1:
            c += 1
    ans += (c * (n - c) * p[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
p = [pow(2, i, mod) for i in range(60)]
l0 = [n] * 60
l1 = [0] * 60
for i in a:
    t = list(format(i, "b"))
    for j in range(len(t)):
        if int(t[j]) == 1:
            l0[len(t) - 1 - j] -= 1
            l1[len(t) - 1 - j] += 1
ans = 0
for i in range(60):
    ans += (l0[i] * l1[i] * p[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
p = [pow(2, i, mod) for i in range(60)]
l0 = [0] * 60
l1 = [0] * 60
for i in a:
    t = list(format(i, "b"))
    for j in range(len(t)):
        if int(t[j]) == 0:
            l0[len(t) - 1 - j] += 1
        else:
            l1[len(t) - 1 - j] += 1
    for j in range(len(t), 60):
        l0[j] += 1
ans = 0
for i in range(60):
    ans += (l0[i] * l1[i] * p[i]) % mod
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

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

print(sum % 1000000007)

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys 
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int,input().split()))
    c1 = [0]*60
    c0 = [0]*60
    mod = 10**9+7

    for i in l:
        for j in range(60):
            if (i >> j) & 1:
                c1[j] += 1
            else:
                c0[j] += 1

    ans = 0
    ni = 1
    for i in range(60):
        ans += (c1[i]*c0[i]*ni)%mod
        ans %= mod
        ni = ni*2%mod
    print(ans%mod)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
c1 = [0]*70
c0 = [0]*70
mod = 10**9+7

for i in l:
    for j in range(60):
        if (i >> j) & 1:
            c1[j] += 1
        else:
            c0[j] += 1

ans = 0
ni = 1
for i in range(70):
    ans += (c1[i]*c0[i]*ni)%mod
    ans %= mod
    ni = ni*2%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
lim = 10**9+7
n=int(input())
A=[int(i) for i in input().split()]
binary = [bin(i)[2:].zfill(60)[::-1] for i in A]

ans=0
for i in range(60):
    l = [s[i] for s in binary]
    #print(i,l.count("0") * l.count("1"))
    ans = (ans+ ((l.count("0") * l.count("1"))% lim * 2**i )% lim)% lim
print(ans % lim)

Submission status: Time Limit Exceeded

Solution code:
lim = 10**9+7
n=int(input())
A=[int(i) for i in input().split()]
binary = [bin(i)[2:].zfill(60)[::-1] for i in A]

ans=0
for i in range(60):
    l = [s[i] for s in binary]
    #print(i,l.count("0") * l.count("1"))
    ans +=  l.count("0") * l.count("1") * 2**i 
print(ans % lim)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10 ** 9 + 7
N = int(input())
l_in = list(map(int, input().split()))
d_ans = {}
sum = 0
for i in range(N - 1):
  if i in d_ans:
    sum = (sum + d_ans[i]) % MOD
    continue
  d_ans[i] = 0
  for j in range(i, N):
    a = l_in[i] ^ l_in[j]
    d_ans[i] = (d_ans[i] + a) % MOD
    sum = (sum + a) % MOD
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def xor_sum(a):
    sum = 0
    d = 10**9+7
    for i in range(60):
        n_0 = 0
        n_1 = 0
        for j in a:
            if str(format(j, 'b')).zfill(60)[i] == '0':
                n_0 += 1
            else:
                n_1 += 1
        sum += (pow(2, 59-i)*(n_0*n_1))%d
    print(sum%d)

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

xor_sum(a)

Submission status: Time Limit Exceeded

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

k=len(bin(max(l)))-2

for i in range(n):
    l[i]=bin(l[i])[2:]

ll=[[0,0] for i in range(k)]
for i in range(n):
    for j in range(k):
        try:
            if l[i][-1-j]=="1":
                ll[j][1]+=1
            if l[i][-1-j]=="0":
                ll[j][0]+=1
        except IndexError:
            ll[j][0]+=1

m=0
for i in range(k):
    m+=ll[i][0]*ll[i][1]*(2**i)
print(m%(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):
  one=0
  for j in range(N):
    one += A[j]&1
    A[j] = A[j]>>1
  zero = N - one
  ans += one*zero*pow(2,i)
  ans %= mod
  #print(one,zero)

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):
  one=0
  for a in  A:
    one += a>>i&1
  zero = N - one
  ans += one*zero*pow(2,i)
  ans %= mod
  #print(one,zero)

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):
  one=0
  for j in map(lambda x:x%pow(2,(i+1))//pow(2,i), A):
    one += j
  zero = N - one
  ans += one*zero*pow(2,i)
  ans %= mod
  #print(one,zero)

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):
  B = [0]*N
  one = 0
  for j in range(N):
    B[j] = A[j]%pow(2,(i+1))//pow(2,i)
    one += B[j]
  zero = N - one
  ans += one*zero*pow(2,i)
  ans %= mod
  #print(one,zero)

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):
  B = list(map(lambda x:x%pow(2,(i+1))//pow(2,i), A))
  one = sum(B)
  zero = N - one
  ans += one*zero*pow(2,i)
  ans %= mod
  #print(one,zero)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

total = 0
mod = 10 ** 9 + 7
ls = []
max_length = len(bin(max(A))) - 2
for i in range(max_length+1):
    d = {0: 0, 1: 0}
    ls.append(d)
for i in range(N):
    idx = 0
    for j in range(max_length + 1):
        try:
            b = int(bin(A[i])[-j - 1])
        except Exception:
            b = 0
        ls[j][b] += 1
        idx += 1

ans = 0
for i in range(len(ls)):
    zero = ls[i][0]
    one = ls[i][1]
    ans += zero*one * 2**i
    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())))

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
N %= mod

for i in range(K):
    bit = sum(list(A >> i & 1)) % mod
    ans += pow(2, i, mod) * bit * (N - bit)
    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())))

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
N %= mod

for i in range(K):
    bit = sum(A >> i & 1) % mod
    ans += pow(2, i, mod) * bit * (N - bit)
    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())))

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
power = 1
N %= mod

for i in range(K):
    bit = sum(A >> i & 1) % mod
    ans += power * bit * (N - bit)
    ans %= mod
    power *= 2
    power %= 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())))

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
power = 1

for i in range(K):
    bit = sum(A >> i & 1)
    ans += power * bit * (N - bit)
    ans %= mod
    power *= 2
    power %= 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())))

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7

for i in range(K):
    bit = sum(A >> i & 1)
    ans += pow(2, i, mod) * bit * (N - bit)
    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())))
K = 60

ans = 0
mod = 10 ** 9 + 7

for i in range(K):
    bit = sum(A >> i & 1)
    ans += pow(2, i, mod) * (bit * (N - bit))
    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())))
K = 60

ans = 0
mod = 10 ** 9 + 7

for i in range(K):
    bit = sum(A >> i & 1)
    ans += pow(2, i, mod) * (bit * (N - bit))

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
K = 60

ans = 0
mod = 10 ** 9 + 7
power = 1

for i in range(K):
    bit = sum(A >> i & 1)
    ans += power * (bit * (N - bit))
    power *= 2
    power %= mod

print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
K = 60

ans = 0
mod = 10 ** 9 + 7
power = 1

for i in range(K):
    bit = sum(A >> i & 1)
    ans += power * ((bit * (N - bit)) % mod)
    power *= 2
    power %= mod
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

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

bit_nums = [0 for _ in range(K)]
ans = 0
mod = 10 ** 9 + 7

for i in range(K):
    bit_nums[i] = sum([1 if a >> i & 1 == 1 else 0 for a in A])

ans = 0
for i in range(K):
    ans += (2 ** i) * (bit_nums[i] * (N - bit_nums[i]))
    ans %= mod
    
print(ans)

Submission status: Time Limit Exceeded

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

bit_nums = [0 for _ in range(K)]
ans = 0
mod = 10 ** 9 + 7

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

ans = 0
for i in range(K):
    ans += (2 ** i) * (bit_nums[i] * (N - bit_nums[i]))
    ans %= mod
    
print(ans)

Submission status: Time Limit Exceeded

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

total = 0
combo = list(itertools.combinations(A,2))
mod = 10**9+7
for x,y in combo:
    total += x^y
    total %= mod
print(total)

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007

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

ans = 0
for k in range(60):
    cnt1 = 0
    for x in a:
        if ((x>>k)&1) == 1:
            cnt1 += 1
    ans += cnt1*(n-cnt1)*(1<<k)
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007

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

ans = 0
for k in range(60):
    cnt1 = 0
    for x in a:
        if ((x>>k)&1) == 1:
            cnt1 += 1
    ans += cnt1*(n-cnt1)*(1<<k)
    if ans > MOD:
        ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

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

one_count = [0] * 61
for v in a:
  count = 0
  while v != 0:
    if v % 2 == 1:
      one_count[count] += 1
      
    count += 1
    v //= 2
  

ans = 0
for i in range(len(one_count)):
  ans += (one_count[i] * (n - one_count[i]) * (2 ** i))
  ans %= MOD
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
num0 = 0
num1 = 0
ans = 0
for i in range(61):
    for j in A:
        if(j%(2**(i+1))>=2**i):
            num1 +=1
        else:
            num0 +=1
    ans += num0*num1*(2**i)
    num0,num1 = 0,0
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
cnt = [0 for i in range(60)]
mod = 10 ** 9 + 7

for i in range(60):
    for j in A:
        tmp = format(j, '060b')
        if tmp[i] == "1":
            cnt[i] += 1

ans = 0

lst = [1 for i in range(60)]

for i in range(59):
    lst[58-i] = (lst[59-i] * 2) % mod

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
cnt = [0 for i in range(60)]
mod = 10 ** 9 + 7

for i in A:
    tmp = format(i, '060b')
    for j in range(60):
        if tmp[j] == "1":
            cnt[j] += 1

ans = 0

lst = [1 for i in range(60)]

for i in range(59):
    lst[58-i] = (lst[59-i] * 2) % mod

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

n=int(input())
alst=list(map(int,sys.stdin.readline().strip().split()))

cumsum=[[0]*(n+1) for i in range(60)]

md=10**9+7

for i in range(1,n+1):
    a=alst[i-1]
    dig=0
    while dig<60:
        bit=a%2
        cumsum[dig][i]=cumsum[dig][i-1]+bit
        dig+=1
        a//=2

ans=0
ceff=1

for d in range(60):
    ret=0
    for i in range(1,n):
        ret+=(cumsum[d][i]-cumsum[d][i-1])*(n-i-cumsum[d][n]+cumsum[d][i])
        ret+=(1-cumsum[d][i]+cumsum[d][i-1])*(cumsum[d][n]-cumsum[d][i])
    ans=(ans+ceff*ret)%md
    ceff=(2*ceff)%md

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l1=[0]*61
l=list(map(int,input().split()))
for j in range(n):
  s=list(str(bin(l[j])))
  for i in range(61):
    if i==len(s)-2:
      break
    if s[-i-1]=='1':
      l1[i]+=1
c=0
for i in range(61):
  c+=pow(2,i,10**9+7)*(n-l1[i])*l1[i]%(10**9+7)
print(c%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0
    for i in range(60):
        # count = 0
        # b = []
        b = [1 if a[j] & (1 << i) == 2 ** i else 0 for j in range(n)]
        count = sum(b)
        # for j in range(n):
        #     b = [1 if a[j] & (1 << i) == 2**i else 0 for j in range(n)]
        #     if a[j] & (1 << i) == 2**i:
        #         count += 1
        ans += (2**i) * (count * (n - count))

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

Submission status: Time Limit Exceeded

Solution code:
M=10**9+7
N=int(input())
la=list(map(int,input().split()))
ans=0
for i in range(60):
    n0=0
    n1=0
    for j in range(N):
        if la[j]&1:
            n1+=1
        else:
            n0+=1
        la[j]>>=1
    ans=(ans+n0*n1%M*(2**i%M))%M
print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0
    for i in range(60):
        count = 0
        for j in range(n):
            if a[j] & (1 << i) == 2**i:
                count += 1
        ans += (2**i) * (count * (n - count))

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

Submission status: Time Limit Exceeded

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

len_max = len(list(format(max(a), 'b')))

bin_list = [0]*len_max

for a_ in a:
    for i in range(1,len_max+1):
        if a_ & (1<<(i-1)):
            bin_list[-i] += 1

ans = 0
for i in range(1,len_max+1):
    num_1 = bin_list[-i]%p
    ans += 2**(i-1)%p * num_1 * (n-num_1)%p

print(ans%p)

Submission status: Time Limit Exceeded

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

len_max = len(list(format(max(a), 'b')))

bin_list = [0]*len_max

def python_list_add(in1, in2):
    return [a + b for a, b in zip(in1, in2)]

for a_ in a:
    a_bin = list(map(int ,list(format(a_,'b').zfill(len_max))))
    bin_list = python_list_add(bin_list, a_bin)


ans = 0
for i in range(1,len_max+1):
    num_1 = bin_list[-i]%p
    ans += 2**(i-1)%p * num_1 * (n-num_1)%p

print(ans%p)

Submission status: Time Limit Exceeded

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

len_max = len(list(format(max(a), 'b')))

bin_list = np.array([0]*len_max)

for a_ in a:
    a_bin = np.array( list(map(int ,list(format(a_,'b').zfill(len_max)))))
    bin_list += a_bin


ans = 0
for i in range(1,len_max+1):
    num_1 = bin_list[-i]%p
    ans += 2**(i-1)%p * num_1 * (n-num_1)%p

print(ans%p)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
ans = 0
for i in range(61):
	x = 0
	for j in a:
		if j >> i & 1:
			x += 1
	z = x*(n-x)%mod
	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()))
law = 10 ** 9 + 7

bitsum = [0 for _ in range(60)]
for x in a:
    for i in range(60):
        bitsum[i] += bool(x & (1 << i))

ans = 0
for x in a:
    for i in range(60):
        k = bitsum[i]
        if (x & (1 << i)):
            k = n - k
        ans += k << i
        ans %= law
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + law) // 2)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().strip().split()]
MOD = 10 ** 9 + 7
ans = 0

for i in range(60+1):
    zero = 0
    one = 0
    m = 1 << i
    for a in A:
        if a & m:
            one += 1
        else:
            zero += 1
    ans += (one * zero) * m
    ans = ans % MOD
print(ans % MOD)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().strip().split()]
MOD = 10 ** 9 + 7
ans = 0

for i in range(60+1):
    zero = 0
    one = 0
    for a in A:
        if a >> i & 1 == 1:
            one += 1
        else:
            zero += 1
    ans += (one * zero) * 2 ** i
    ans = ans % MOD
print(ans % MOD)