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())
A = input().split()

xorsum = 0;

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



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

Submission status: Time Limit Exceeded

Solution code:
count = int(input())
waru = 10**9 + 7
intlist = list(map(int,input().split()))
sum = 0
for i in range(len(intlist)):
  for j in range(i+1,len(intlist)):
    sum += intlist[i] ^ intlist[j]
print(sum%waru)

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        sum += int(a[i] ^ a[j])

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

Submission status: Time Limit Exceeded

Solution code:

M = 10 ** 9 + 7
X = 60

N = int(input())

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

total = 0
for i in range(X):
	counts = [0] * (N + 1)
	for j in range(N - 1, -1, -1):
		counts[j] = counts[j + 1] + ((A_list[j] >> i) & 1)
	count = 0
	for j in range(N - 1):
		if ((A_list[j] >> i) & 1) == 1:
			count += N - j - counts[j]
		else:
			count += counts[j]
	total = (total + (1 << i) * count) % M

print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int, input().split()))
r = 0
#for i in range(N):
#  for j in range(i+1, N):
#    r = (r+(As[i]^As[j]))%1000000007
for i in range(64):
  n = 0
  for A in As:
    if A&(1<<i) != 0:
      n += 1
  #print(i, n)
  r = (r+n*(N-n)*2**i)%1000000007
print(r)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]*n
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]
    
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7

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

sum_ = 0
for i in range(n):
    for j in range(i, n):
        sum_ = ((a[i] ^ a[j])% MOD + sum_) % MOD

print(sum_)

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]) % MOD
		ans %= MOD
		
print(ans)

Submission status: Time Limit Exceeded

Solution code:
M = 60
p = [2 ** i for i in range(M)]
dp = [0] * M

res = 0
n = int(input())
for i, x in enumerate(map(int, input().split())):
    for j in range(M):
        b = x & p[j]
        if b:
            cnt = i - dp[j]
            dp[j] += 1
        else:
            cnt = dp[j]
        res += cnt * p[j]
        res %= int(1e9 + 7)
print(res)

Submission status: Time Limit Exceeded

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

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

bt = [0]*60

ans = 0

for i in range(n):
    s = a[i]
    for j in range(60):
        if((s>>j) & 1):
            ans += (i-bt[j])*(2**j)
            ans %= mod
            bt[j] += 1
        else:
            ans += bt[j]*(2**j)
            ans %= mod


print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in itertools.combinations(a,2):
    c += i[0]^i[1]
    
print(c%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int, input().split()))
from itertools import permutations, combinations,combinations_with_replacement,product
L = combinations(range(n), 2)   #nCr
cnt = 0
for i in L:
  cnt += (A[i[0]]^A[i[1]])%(10**9+7)
  cnt = cnt%(10**9+7)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def fastio():
    import sys
    from io import StringIO 
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))

n, = I()
a = I()
ans = 0
for bit in range(64):
    c = [0, 0]
    for i in a:
        c[(i >> bit)&1] += 1
    ans += c[0] * c[1] * 2**bit
    ans %= MOD
    # print(ans, c[0], c[1], 2**i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#D
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 = ans % (10**9 + 7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
'''import math
def count_total(s1,s2):
    f = 0
    s = 0
    cnt = 0
    while s2>0:
        #print(bin(s1).replace("0b",""),bin(s2).replace("0b",""))
        #print(s1,s2)
        f = s1 ^ s2
        s = s1 & s2
        s1 = f
        s2 = s<<1
        cnt+=1
    return cnt
t = int(input())
for _ in range(0,t):
    s1 = int(input(),2)
    s2 = int(input(),2)
    if(len(str(s2))<=500): 
        print(count_total(s1,s2))
    else:
        print(-1)
'''

n=int(input())
a=list(map(int,input().split(' ')))
sum=0
for i in range(0,62):
    z=0
    o=0
    cr=0
    for j in range(0,n):
        if(a[j]%2==0):
            z+=1
        else:
            o+=1
        a[j]//=2
    
    cr = o*z*(1<<i)
    sum+=cr
    if(sum>1000000007):
        sum%=1000000007
print(sum%1000000007)

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007
s = 0
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	for j in range(i+1, n):
		s += a[i]^a[j]
	s = s % MOD
print(s)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = [int(i) for i in input().split()]

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
L=len(format(max(a),"b"))
s=[0]*L
for i in range(n):
  c=format(a[i], 'b').zfill(L)
  for j in range(len(c))[::-1]:
    s[j]+=int(c[j])
ans=0
for i in range(len(s))[::-1]:
  ans+=2**(i)*(s[L-i-1])*(n-s[L-i-1])
  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(N):
    for j in range(i,N):
        sum += A[i]^A[j]
print(sum%1000000007)

Submission status: Time Limit Exceeded

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

counts = [0] * 60
for a in A:
    for i in range(60):
        counts[i] += (a >> i) % 2

ans = sum(c * (N - c) * (2 ** i % MOD) % MOD for i, c in enumerate(counts))

print(ans % MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

B = [bin(a)[2:].zfill(61)[::-1] for a in A]
N1 = []
for i in range(0,61):
    m = 0
    for b in B:
        if b[i] == "1":
            m += 1
    N1.append(m)

ans = 0
for i,n1 in enumerate(N1):
    n0 = N-n1
    m = n0 * n1
    ans += 2**i * m
    ans = ans % MOD
print(ans % MOD)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[16]:


N = int(input())
A = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7


# In[17]:


count = [0] * 60
for i in range(N):
    s = format(A[i], '060b')
    for d in range(60):
        count[d] += int(s[d])


# In[18]:


# print(count)


# In[19]:


ans = 0
for d in range(60):
    ans = (ans + 2 ** (59 - d) * count[d] * (N - count[d])) % MOD


# In[20]:


print(ans)


# In[ ]:

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
'''import math
def count_total(s1,s2):
    f = 0
    s = 0
    cnt = 0
    while s2>0:
        #print(bin(s1).replace("0b",""),bin(s2).replace("0b",""))
        #print(s1,s2)
        f = s1 ^ s2
        s = s1 & s2
        s1 = f
        s2 = s<<1
        cnt+=1
    return cnt
t = int(input())
for _ in range(0,t):
    s1 = int(input(),2)
    s2 = int(input(),2)
    if(len(str(s2))<=500): 
        print(count_total(s1,s2))
    else:
        print(-1)
'''

n=int(input())
a=list(map(int,input().split(' ')))
sum=0
for i in range(0,62):
    z=0
    o=0
    cr=0
    for j in range(0,n):
        if(a[j]%2==0):
            z+=1
        else:
            o+=1
        a[j]//=2
    
    cr = o*z*(1<<i)
    sum+=cr
print(sum%1000000007)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
L=len(format(max(a),"b"))
s=[0]*L
for i in range(n):
  c=format(a[i], 'b').zfill(L)
  for j in range(len(c))[::-1]:
    s[j]+=int(c[j])
ans=0
for i in range(len(s))[::-1]:
  ans+=2**(i)*(s[L-i-1])*(n-s[L-i-1])
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

sum = 0
count = 0

for i in range(0, n-1):
    for j in range(i+1, n):
        sum = sum + (a[i] ^ a[j])
        count += 1

a = sum % (10**9 + 7)
print(a)

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):
    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

A_bin_cnt = [0] * 60
for i in range(N):
    a = A[i]
    for j in range(60):
        if a >> j & 1:
            A_bin_cnt[j] += 1
ans = 0
for i in range(N):
    a = A[i]
    for j in range(60):
        if not a >> j & 1:
            ans = (ans + (pow(2, j, mod) * A_bin_cnt[j]) % mod) % mod
        else:
            ans = (ans + (pow(2, j, mod) * (N - A_bin_cnt[j])) % mod) % mod
inv2 = pow(2, mod-2, mod)
print((ans*inv2)%mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=[0]*60
m=10**9+7
for i in a:
    t=bin(i)[2:][::-1]
    for i in range(len(t)):
        if t[i]=="1":
            s[i]+=1
c=0
for i in range(60):
    c=(c+s[i]*(n-s[i])*pow(2,i,m))%m
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) 
L = list(map(int, input().split()))
out = 0
for i in range(n-1):
  for j in range(i+1, n):
    out += (L[i] ^ L[j]) % (10**9 +7)
print(out%(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:
n = int(input())
ais = [int(i) for i in input().split()]
m = 10**9 + 7

total = 0
for i in range(n) :
  for j in range(i+1,n) :
    total += ais[i]^ais[j]
    total = total % m
    
print(total)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  for j in range(i+1,n):
    ans += a[i] ^ a[j]
    ans = ans % (10**9+7)
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())
l=list(map(int,input().split()))
ans=0
MOD=10**9+7
for i in l:
    for j in l:
        ans+=i^j
print(ans//2%MOD)

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007
s = 0
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	for j in range(i+1, n):
		s += a[i]^a[j]
		s = s % MOD
print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
A = list(map(lambda x: int(x),input().split()))
x = itertools.combinations(A,2)
count=0
for i in x:
  count += i[0]^i[1]
print(count%(10**9+7))

Submission status: Time Limit Exceeded

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

s = 0
mod = 10**9 + 7
for i in range(n-1):
    for j in range(i+1,n):
        s += a[i]^a[j]

        s %= mod

s %= mod
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
mod=1000000007

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

List=list(itertools.combinations(As,2)) #2つ選ぶ列挙

Ans=0
for i in range(len(List)):
        Ans+=(List[i][0] ^ List[i][1])%mod

print(Ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n  = int(input())
m  = 10 ** 9 + 7
l  = 2 ** 64
xs = [int(x) % l for x in input().split()]
r  = 0

for i in range(0, n - 1):
	for j in range(i + 1, n):
		r = (r + (xs[i] ^ xs[j])) % m

print(r)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [list(map(int, input().split())) for _ in range(1)][0]

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

keta=math.floor(math.log2(max(alist[-1],1)))+1
zeros=[0]*keta
ones=[0]*keta

for al in alist:
    kaz2=bin(al)[2:]
    kaz2=(keta-len(kaz2))*'0'+kaz2
    #print(kaz2)
    for i in range(keta):
        if kaz2[i]=='1':
            ones[i]+=1
        else:
            zeros[i]+=1

answer=0
for i in range(keta):
    tas=ones[-i-1]*zeros[-i-1]
    tas*=((2**i)%(10**9+7))
    answer+=tas%(10**9+7)

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

Submission status: Time Limit Exceeded

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

print(sum)

Submission status: Time Limit Exceeded

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

suma = 0
for i in range(len(a)-1):
    for j in range(i+1,len(a)):
        suma += a[i]^a[j]

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

Submission status: Time Limit Exceeded

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

num = 1000000007

ans = 0

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

print(ans % num)

Submission status: Time Limit Exceeded

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

cnt=[0]*100
p=10**9+7
for m in a:
    #print(m)
    kei=m
    for i in range(100):
        cnt[i]+=kei%2
        kei//=2
        if(kei==0):
            break

#print(cnt)

lis=[]
jou=1
for i in range(100):
    lis.append(jou)
    jou*=2
    jou%=p

ans=0

for i in range(100):
    ans+=(lis[i]%p)*(cnt[i]%p)*((n-cnt[i])%p)
    ans%=p

print(ans)

Submission status: Time Limit Exceeded

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

def xor(a, b):
  return a^b

ans = 0
for i in range(N-1):
  for j in range(i + 1, N):
    ans += (xor(A[i] , A[j])) % MOD

print(ans%MOD)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
MOD = (10**9) + 7

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

cnt = [0] * 60
for num in a:
    for j in range(60):
        cnt[j] += (num >> j) % 2

ans = 0
for b in range(60):
    ans += cnt[b] * (n - cnt[b]) << b
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(61):
	zero, one = 0, 0
	for x in a:
		if (x>>b)&1:
			one += 1
		else:
			zero += 1
	ans += zero*one*(1<<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
ans=0
for i in range(n):
    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()))

res = 0

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = 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 += (ls[i] ^ ls[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

def xor(a, b):
  return a^b

ans = 0
for i in range(N-1):
  for j in range(i + 1, N):
    ans += xor(A[i] , A[j])
    ans = ans % MOD

print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


class Solver(object):
    def __init__(self):
        pass

    def solve(self, N, A_l):
        ans = 0
        for i in range(N-1):
            for j in range(i+1, N):
                ans += A_l[i] ^ A_l[j]
        return ans % (10**9 + 7)


def main():
    N = int(input())
    A_l = [int(i) for i in input().split()]
    solver = Solver()
    print(solver.solve(N, A_l))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
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])%MOD
        s %= MOD
print(s)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = map(int, input().split())
    l0 = [0] * 61
    l1 = [0] * 61
    for i in A:
        t = format(i, 'b').zfill(61)
        for j, v in enumerate(t):
            if v == '1':
                l1[j] += 1
            else:
                l0[j] += 1
    a = 0
    for i in range(61):
        a += ((2 ** i) * (l0[60-i] * l1[60-i])) % (10 ** 9 + 7)
    return a % (10**9 + 7)

print(main())

Submission status: Time Limit Exceeded

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

mod=10**9+7
comb=list(itertools.combinations(A,2))
ans=0
for c in comb:
  a,b=c
  ans+=a^b
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

total = 0
for pat in combinations(range(n), 2):
    total += a[pat[0]] ^ a[pat[1]]
print(total % (10**9 + 7))

Submission status: Time Limit Exceeded

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

cnt=[0]*100

for m in a:
    #print(m)
    kei=m
    for i in range(100):
        cnt[i]+=kei%2
        kei//=2

#print(cnt)

lis=[]
jou=1
for i in range(100):
    lis.append(jou)
    jou*=2

ans=0
p=10**9+7
for i in range(100):
    ans+=lis[i]*cnt[i]*(n-cnt[i])
    ans%=p

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
num = 1000000007

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    m = 61
    d = [0]*m
    ans = 0
    for i in range(n):
        ai = a[i]
        for j in range(m):
            if ai&(1<<j):
                ans += (i-d[j])*pow(2,j,mod)%mod
                ans %= mod
                d[j] += 1
            else:
                ans += d[j]*pow(2,j,mod)%mod
                ans %= mod
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import sys

def get(x,n):
    return ((1<<x)&(n))!=0


def main():
    mod=1000000000+7
    n=int(sys.stdin.readline())
    a=list(map(int,sys.stdin.readline().split()))
    ans=0
    for x in range(60):
        now=get(x,a[-1])
        nnow=not get(x,a[-1])
        for i in range(n-2,-1,-1):
            now+=get(x,a[i])
            nnow+=not get(x,a[i])
            if get(x,a[i]):
                ans+=(2**x)*nnow
            else:
                ans+=(2**x)*now
    print(ans%mod)
main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
t = 0
for a in range(0,len(A)-1):
    for b in range(a+1,len(A)):
        t += A[a]^A[b]
mod = 10**9+7
print(t%mod)

Submission status: Time Limit Exceeded

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

Submission status: Accepted

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

mod = 10**9+7

cnt = [0]*60
bt = [0]*60

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

ans = 0
for i in range(60):
    x = cnt[i]
    y = x*(N-x)%mod
    ans += y*2**i
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = 0
    for mask in range(60):
        cnt1 = sum([1 if a & (1 << mask) else 0 for a in A])
        cnt0 = n - cnt1
        res += (pow(2, mask, mod) * cnt1 * cnt0) % mod
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

cumsum = [[0 for j in range(2)] for i in range(60)]
ans = [0] * 60
#print(cumsum)

for i in range(len(A) - 1, -1, -1):
    plus_num = A[i]
    bit_num = format(plus_num, "060b")
    #print(bit_num)
    for i, bit in enumerate(bit_num):
        bit = int(bit)
        if bit == 0:
            ans[i] += cumsum[i][1]
        else:
            ans[i] += cumsum[i][0]
        cumsum[i][bit] += 1
    #print(ans)
    #print(cumsum)

ans_num = 0
mod = 10**9 + 7
for i, cnt in enumerate(ans):
    ans_num += 2**(59-i) * cnt
    ans_num %= mod
print(ans_num)

Submission status: Accepted

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    ans = 0
    x = 1
    for i in range(60):
        c = 0
        for j in range(n):
            if arr[j]&x != 0:
                c += 1
        ans += (c * (n-c)) * x
        ans %= mod
        x = x*2
    print(ans)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Accepted

Solution code:
N,*A=map(int,open(0).read().split())
print(sum((b:=1<<i)*(N-(z:=sum(1 for a in A if a&b)))*z%(m:=10**9+7) for i in range(60))%m)

Submission status: Accepted

Solution code:
N,*A=map(int,open(0).read().split())
print(sum((b:=1<<i)*(z:=sum(1 for a in A if a&b==0))*(N-z)%(mod:=10**9+7) for i in range(60))%mod)

Submission status: Accepted

Solution code:
# coding: utf-8
import math
#n, k, s = map(int,input().split())
n = int(input())
A = list(map(int,input().split()))
ans = 0
MOD=10**9+7
L0 = [0] * 60
L1 = [0] * 60
for i in range(n):
    b = A[i]
    #print(b)
    b = format(b, '060b')
    #print(b)
    for j in range(60):
        if b[60 - j  -1] == "1":
            L1[j] += 1
        else:
            L0[j] += 1
#print(L0)
#print(L1)

for i in range(60):
    ans += L0[i] * L1[i] * 2**i
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    cnt = 0
    for j in range(n):
        cnt += a[j] >> i & 1
    ans = (ans + (1 << i) * cnt * (n - cnt) % mod) % mod
print(ans)

Submission status: Accepted

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    b1 = [0] * 60
    for a in A:
        for i in range(60):
            if a & (1 << i): b1[i] += 1
    ans = Mint()
    for i in range(60):
        ans += Mint(1 << i) * b1[i] * (N - b1[i])
    print(ans)

MOD = 10**9 + 7
class Mint:
    __slots__ = ('value')

    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self

    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self

    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj

    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self

    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self

    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj

    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)

Submission status: Accepted

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

mod = 10**9+7
X = [0]*62
for i in range(n):
    a = A[i]
    b = format(a, 'b')
    b = list(b)
    b.reverse()
    for j in range(len(b)):
        if b[j] == '1':
            X[j] += 1
ans = 0
for i in range(62):
    x = X[i]
    y = n-X[i]
    #print(i, x, y)
    ans += x*y*pow(2, i, mod)
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
MOD = 10**9+7
nums = list(map(int, input().split()))
B = [0 for _ in range(60)]
for num in nums:
  for i in range(60):
    if num>>i&1:
      B[i] += 1
answer = 0
for i, b in enumerate(B):
  if b > 0:
    answer = (answer+b*(N-b)*2**i)%MOD
print(answer)

Submission status: Accepted

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

mod = 10**9+7

ans = 0
p = 1
for i in range(60):
    s = sum(1 for b in a if b&p)
    ans += s*(n-s)*p
    ans %= mod
    p <<= 1
print(ans)

Submission status: Accepted

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