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 = [int(i) for i in input().split()]

mod = 10**9+7

#sum_a = sum(a)

#bin_num = format(2, 'b')
#print(bin_num,len(bin_num))

max_a = max(a)
bin_max_a = format(max_a, 'b')

#print(bin_max_a)
ans = 0

for i in range(len(bin_max_a)):
    tmp = 0
    #print(i)
    kazu = 0
    for j in range(n):
        #print(j,kazu)
        kazu += int(format(a[j], 'b').zfill(len(bin_max_a))[i])
        #print(a[j],int(format(a[j], 'b').zfill(len(bin_max_a))[i]))
        #print(format(a[j], 'b').zfill(len(bin_max_a))[i])
        #print(kazu)
    if kazu == 0:
        continue
    tmp = kazu*(n-kazu) % mod
    tmp1 = 1
    """
    for i in range(len(bin_max_a)-1-i):
        tmp1 *= 2
        tmp1 %= mod
    """
    tmp1 = 2**(len(bin_max_a)-1-i) % mod
    tmp = tmp*tmp1%mod
    ans += tmp
    ans %= mod
    #print(ans,kazu)
    
print(ans)

Submission status: Time Limit Exceeded

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

mod = 10**9+7

#sum_a = sum(a)

#bin_num = format(2, 'b')
#print(bin_num,len(bin_num))

max_a = max(a)
bin_max_a = format(max_a, 'b')

#print(bin_max_a)
ans = 0

for i in range(len(bin_max_a)):
    tmp = 0
    #print(i)
    kazu = 0
    for j in range(n):
        #print(j,kazu)
        kazu += int(format(a[j], 'b').zfill(len(bin_max_a))[i])
        #print(a[j],int(format(a[j], 'b').zfill(len(bin_max_a))[i]))
        #print(format(a[j], 'b').zfill(len(bin_max_a))[i])
        #print(kazu)
    if kazu == 0:
        continue
    tmp = kazu*(n-kazu) % mod
    tmp1 = 1
    for i in range(len(bin_max_a)-1-i):
        tmp1 *= 2
        tmp1 %= mod
    #tmp1 = 2**(len(bin_max_a)-1-i) % mod
    tmp = tmp*tmp1%mod
    ans += tmp
    ans %= mod
    #print(ans,kazu)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#D
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
B = []
for a in A:
    b = bin(a)
    b = b.lstrip("0b")
    while len(b) < 60:
        b = "0"+b
    B.append(b)

ans = 0
for i in range(60):
    keta = 2**(59-i)
    bilist = []
    for b in B:
        bilist.append(b[i])
        
    brui = [0]
    for bi in bilist:
        bl = brui[-1]
        if bi == "1":
            bl+=1
        brui.append(bl)
        
    M = brui[-1]
    k = 0
    for j,b in enumerate(bilist):
        if b == "0":
            k+=(M-brui[j])
        else:
            k+=(N-M)-(j-brui[j])
            
    ans+=keta*k
    ans%=mod
    
print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=input().split()
sum=0
for i in range(a-1):
    for x in range(a-i-1):
        g=str(int(format(int(b[i]),'b'))+int(format(int(b[x+i+1]),'b')))
        h=[]
        for j in range(len(g)):
            if g[j]=='2':
                k='0'
                h.append(k)
            else:
                k=g[j]
                h.append(k)
        l=''.join(h)
        m=int(l,2)
        sum+=m
print(sum%(pow(10,9)+7))

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=input().split()
sum=0
for i in range(a-1):
    for x in range(a-i-1):
        e=format(int(b[i]),'b')
        f=format(int(b[x+i+1]),'b')
        g=str(int(e)+int(f))
        h=[]
        for j in range(len(g)):
            if g[j]=='2':
                k='0'
                h.append(k)
            else:
                k=g[j]
                h.append(k)
        l=''.join(h)
        m=int(l,2)
        sum+=m
print(sum%(pow(10,9)+7))

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=input().split()
sum=0
for i in range(a-1):
    for x in range(a-i-1):
        c=int(b[i])
        d=int(b[x+i+1])
        e=format(c,'b')
        f=format(d,'b')
        g=str(int(e)+int(f))
        h=[]
        for j in range(len(g)):
            if g[j]=='2':
                k='0'
                h.append(k)
            else:
                k=g[j]
                h.append(k)
        l=''.join(h)
        m=int(l,2)
        sum+=m
print(sum%(pow(10,9)+7))

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    r = [0] * 60
    t = [0] * 60
    u = [0] * 60
    ii = [2**i for i in range(60)]
    for k in a[::-1]:
        for i in range(60):
            if k & ii[i] > 0:
                r[i] += u[i]
                t[i] += 1
            else:
                r[i] += t[i]
                u[i] += 1

    rr = 0
    for i in range(60):
        rr += r[i] * ii[i]
        rr %= mod

    return rr


print(main())

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

def main():
    MOD = 10**9+7
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    k = 1
    
    for i in range(60):
        c = 0
        for j in range(N):
            if A[j] & 1: c += 1
            A[j] = A[j] >> 1
        ans += c * (N-c) * k
        ans %= MOD
        k *= 2
            
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(60):
    c = 0
    for a in A:
        if (a>>i) & 1: c += 1
        
    ans += (c * (N-c) % MOD * 2 **i % MOD) % MOD
        
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
bit_one_count = [0 for i in range(60)]
bit_zero_count = [0 for i in range(60)]
for i in range(n):
    bits = '{0:060b}'.format(a[i])
    for j in range(60):
        if bits[-1 -j] == '1':
            bit_one_count[j] += 1
        else:
            bit_zero_count[j] += 1

ans = 0
for j in range(60):
    ans += bit_one_count[j] * bit_zero_count[j] * 2 ** j
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(c) for c in input().split()]
D=[0 for i in range(60)];
for a in A:
  for i in range(60):
    D[i]+=a%2
    a//=2
t=1
ans=0
for i in range(60):
  ans+=D[i]*(N-D[i])*t
  t*=2
print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


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

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def bi(x):
    x = bin(x)
    return x[2:len(x)]

def xor(x, y):
    if x > y:
        x, y = y, x
    x = bi(x)
    y = bi(y)
    lenx = len(x)
    leny = len(y)
    if lenx != leny:
        x_new = ""
        for i in range(leny - lenx):
            x_new = "0" + x_new
        x = x_new + x
        
    s = "0b"
    for i in range(len(x)):
        if x[i] != y[i]:
            s += "1"
        else:
            s += "0"

    return int(s, 2)

N = int(input())
L = [x for x in map(int, input().split())]

out = 0
for i in range(N):
    for j in range(N):
        if i > j:
            x = L[i]
            y = L[j]
            out += xor(x, y)
print(out % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(n) for n in input().split(' ')]

ans = 0
for i in range(60):
    x = 0
    for A_i in A:
        if A_i>>i&1:
            x += 1
    ans += x*(N-x)*2**i
ans = ans % (10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10 ** 9 + 7

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
    x = 0
    now = 0
    for j in range(n):
        if (a[j] >> i) & 1:
            x += 1
        now = x * (n - x) % MOD
    now = now * (2 ** i) % MOD
    ans = (ans + now) % MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
MOD = 10 ** 9 + 7

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i, j in itertools.combinations(a, 2):
    ans += (i ^ j) % MOD

print(ans % MOD)

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(n-i-1):
        ai = format(a[i],"b")
        aj = format(a[i+j+1],"b")
        if len(ai) <= len(aj) :
            ai = "0"*(len(aj)-len(ai)) + ai
        else:
            aj = "0"*(len(ai)-len(aj)) + aj
        num = ""
        for k in range(len(ai)):
            if ai[k] ==aj[k]:
                num = num + "0"
            else:
                num = num + "1"
        ans += int(num,2)
        ans = ans%(1000000007)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(x) for x in input().split(" ")]
sum = 0
pow = 0
while any(a):
    one = 0
    for i in range(N):
        if a[i] & 1:
            one += 1
        a[i] >>= 1
    sum += one * (N - one) * 2 ** pow
    sum %= (10 ** 9 + 7)
    pow += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(x) for x in input().split(" ")]
sum = 0
pow = 0
while any(a):
    zero = 0; one = 0
    for i in range(N):
        if a[i] % 2 == 0:
            zero += 1
        else:
            one += 1
        a[i] >>= 1
    sum += zero * one * 2 ** pow
    pow += 1
print(sum % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(x) for x in input().split(" ")]
sum = 0
pow = 0
while any(a):
    zero = 0; one = 0
    for i in range(N):
        if a[i] % 2 == 0:
            zero += 1
        else:
            one += 1
        a[i] //= 2
    sum += zero * one * 2 ** pow
    pow += 1
print(sum % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sm = 0
for i in range(n-1):
    for j in range(n-i-1):
        sm += x[i]^x[i+j+1]

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = list(map(lambda n: format(int(n), '060b')[::-1], input().split()))

mod = 10 ** 9 + 7

res = 0
power_of_two = 1
for d in range(60):
    one = sum(x[d] == "1" for x in arr)
    res += one * (n - one) * power_of_two
    res %= mod
    power_of_two *= 2
    power_of_two %= mod

print(res)

Submission status: Time Limit Exceeded

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

sum_xor = 0
for i in range(n):
  for j in range(i+1, n):
    sum_xor += l[i]^l[j]
    # sum_xor %= 10**9+7

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

Submission status: Time Limit Exceeded

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

sum_xor = 0
for i in range(n):
  for j in range(i+1, n):
    sum_xor += l[i]^l[j]
    sum_xor %= 10**9+7

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

Submission status: Time Limit Exceeded

Solution code:

MOD = 10 ** 9 + 7
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)

Submission status: Time Limit Exceeded

Solution code:
import itertools as it
N=input()
a_l=[int(i) for i in input().split()]

def xor(i,j):
    l=len(str(format(max(i,j),'b')))
    i2=str(format(i,'b').zfill(l))
    j2=str(format(j,'b').zfill(l))
    ans=0
    for k in range(l):
        if i2[k]!=j2[k]:
            ans+=2**(l-k-1)
    yield ans

sum1=0
for (i,j) in it.combinations(a_l, 2):
    for k in xor(i,j):
        sum1+=k
print(sum1%(7+10**9))

Submission status: Time Limit Exceeded

Solution code:
import itertools as it
N=input()
a_l=[int(i) for i in input().split()]

sum1=0
for (i,j) in it.combinations(a_l, 2):
        sum1+=i^j
print(sum1%(7+10**9))

Submission status: Time Limit Exceeded

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

sum1=0
j=1
for i in range(N-1):
    while j<N:
        sum1+=a_l[i]^a_l[j]
        j+=1
    j=i+2
print(sum1%(7+10**9))

Submission status: Time Limit Exceeded

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

def xor(i,j):
    l=len(str(format(max(i,j),'b')))
    i2=str(format(i,'b').zfill(l))
    j2=str(format(j,'b').zfill(l))
    ans=0
    for k in range(l):
        if i2[k]!=j2[k]:
            ans+=2**(l-k-1)
    return ans

sum1=0
j=1
for i in range(N-1):
    while j<N:
        sum1+=xor(a_l[i],a_l[j])
        j+=1
    j=i+2
print(sum1%(7+10**9))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
SUM = 0
DIV = 10**9 + 7

for i in range(1,N):
    for j in range(i+1,N+1):
        XOR = A[i-1]^A[j-1]#XOR
        SUM = SUM + XOR
if SUM < DIV:
    print(SUM)
else:
    print(SUM%DIV)

Submission status: Time Limit Exceeded

Solution code:
import itertools as it

N=int(input())
a_l=[int(i) for i in input().split()]

sum1=0
for (i,j) in it.combinations(a_l, 2):
    l=max(len(str(format(i,'b'))),len(str(format(j,'b'))))
    i2=str(format(i,'b').zfill(l))
    j2=str(format(j,'b').zfill(l))
    for k in range(l):
        if i2[k]!=j2[k]:
            sum1 += 2**(l-k-1)
print(sum1%(7+10**9))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools as it

N=int(input())
a_l=np.array([int(i) for i in input().split()])

def xor(i,j):
    l=max(len(str(format(i,'b'))),len(str(format(j,'b'))))
    i2=str(format(i,'b').zfill(l))
    j2=str(format(j,'b').zfill(l))
    ans=0
    for k in range(l):
        if i2[k]!=j2[k]:
            ans+=2**(l-k-1)
    return ans

sum1=0
for (i,j) in it.combinations(a_l, 2):
        sum1+=xor(i,j)
print(sum1%(7+10**9))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N=int(input())
a_l=np.array([int(i) for i in input().split()])

def xor(i,j):
    l=max(len(str(format(i,'b'))),len(str(format(j,'b'))))
    i2=str(format(i,'b').zfill(l))
    j2=str(format(j,'b').zfill(l))
    ans=0
    for k in range(l):
        if i2[k]!=j2[k]:
            ans+=2**(l-k-1)
    return ans

sum1=0
for i in range(N-1):
    for j in a_l[i+1:]:
        sum1+=xor(a_l[i],j)
print(sum1%(7+10**9))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N=int(input())
a_l=[int(i) for i in input().split()]

def xor(i,j):
    l=max(len(str(format(i,'b'))),len(str(format(j,'b'))))
    i2=str(format(i,'b').zfill(l))
    j2=str(format(j,'b').zfill(l))
    ans=0
    for k in range(l):
        if i2[k]!=j2[k]:
            ans+=2**(l-k-1)
    return ans

sum1=0
for (i,j) in itertools.product(range(N), range(N)):
    if i<j:
        sum1+=xor(a_l[i],a_l[j])
print(sum1%(7+10**9))

Submission status: Time Limit Exceeded

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

def xor(i,j):
    l=max(len(str(format(i,'b'))),len(str(format(j,'b'))))
    i2=str(format(i,'b').zfill(l))
    j2=str(format(j,'b').zfill(l))
    ans=0
    for k in range(l):
        if i2[k]!=j2[k]:
            ans+=2**(l-k-1)
    return ans

sum1=0
for i in range(N-1):
    for j in range(N-1-i):
        sum1+=xor(a_l[i],a_l[j+i+1])
print(sum1%(7+10**9))

Submission status: Time Limit Exceeded

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

def xor(i,j):
    l=max(len(str(format(i,'b'))),len(str(format(j,'b'))))
    i2=str(format(i,'b').zfill(l))
    j2=str(format(j,'b').zfill(l))
    ans=0
    for k in range(l):
        if i2[k]!=j2[k]:
            ans+=2**(l-k-1)
    return ans

sum1=0
j=1
for i in range(N-1):
    while j<N:
        sum1+=xor(a_l[i],a_l[j])
        j+=1
    j=i+2
print(sum1%(7+10**9))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
class Num:
    nums=[]
    sum=0
    def __init__(self,num):
        for val in Num.nums:
            Num.sum+=val^num
        Num.nums.append(num)
        Num.sum%=1000000007

n=input()
a=input().split()

for val in a:
    num=Num(int(val))

print(num.sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
num_list = list(map(int, input().split()))
 
length = N
amount = 0
for i in range(length-1):
  for j in range(i+1, length):
    num1 = num_list[i]
    num2 = num_list[j]
    num = num1 ^ num2
    amount += num

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

Submission status: Time Limit Exceeded

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

bit2 = [0] * 80
for i in range(N):
  bin_a = bin(A[i])
  #print(bin_a)#2なら0b10と返す
  str_bin_a = str(bin_a)[2:]
  #print(str_bin_a)
  l = len(str_bin_a)
  for j in range(l):
    bit2[j] += int(str_bin_a[-(j + 1)])
    
#print(bit2)
ans = 0
for i in range(80):
  count1 = bit2[i]
  count0 = N - count1
  ans += ((2 ** i) * count0 * count1) % MOD
  
print(ans % MOD)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def trans(number):
    i = 0
    while(1):
        i += 1
        if(number - 2**i < 0):
            i = i - 1
            break


    sel = [0 for i in range(61)]
    sel[- (i + 1)] = 1
    number = number - 2**i
    i = i - 1
    count = -(i + 1)
    while(i >= 0):
        if(number - 2**i >= 0):
            number = number - 2**i
            sel[count] = 1
            count += 1
        else:
            count += 1

        i = i - 1
    return(sel)

def reverse(number_list):
    result = 0
    count = len(number_list) - 1
    for i in range(len(number_list)):
        result += number_list[i] * 2**count
        count = count - 1
    return(result)


def calculate(num1,num2):
    numa = trans(num1)
    numb = trans(num2)
    index_a = numa.index(1)
    index_b = numb.index(1)
    del numa[:min(index_a,index_b) - 1]
    del numb[:min(index_a,index_b) - 1]

    result = [0 for i in range(len(numa))]
    for i in range(len(numa)):
        if(numa[i] != numb[i]):
            result[i] = 1
    return(reverse(result))

def main():

    num = int(input())

    point = input().split(' ')
    for i in range(num):
        point[i] = int(point[i])

    result = 0
    for i in range(num - 1):
        for l in range(num - i - 1):
            result += calculate(point[i],point[i + l + 1])

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



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:

def trans(number):
    i = 0
    while(1):
        i += 1
        if(number - 2**i < 0):
            i = i - 1
            break


    sel = [0 for i in range(61)]
    sel[- (i + 1)] = 1
    number = number - 2**i
    i = i - 1
    count = -(i + 1)
    while(i >= 0):
        if(number - 2**i >= 0):
            number = number - 2**i
            sel[count] = 1
            count += 1
        else:
            count += 1

        i = i - 1
    return(sel)

def reverse(number_list):
    result = 0
    count = len(number_list) - 1
    for i in range(len(number_list)):
        result += number_list[i] * 2**count
        count = count - 1
    return(result)


def calculate(num1,num2):
    numa = trans(num1)
    numb = trans(num2)
    index_a = numa.index(1)
    index_b = numb.index(1)
    del numa[:min(index_a,index_b) - 1]
    del numb[:min(index_a,index_b) - 1]

    result = [0 for i in range(len(numa))]
    for i in range(len(numa)):
        if(numa[i] != numb[i]):
            result[i] = 1
    return(reverse(result))


num = int(input())

point = input().split(' ')

for i in range(num):
    point[i] = int(point[i])

result = 0
for i in range(num - 1):
    for l in range(num - i - 1):
        result += calculate(point[i],point[i + l + 1])

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
num_list = list(map(int, input().split()))
 
length = N
amount = 0
for i in range(length-1):
  for j in range(i+1, length):
    num1 = num_list[i]
    num2 = num_list[j]
    bit_num1 = format(num1, "b")
    bit_num2 = format(num2, "b")
    length_num1 = len(bit_num1)
    length_num2 = len(bit_num2)
    max_length = max(length_num1, length_num2)
    bit_num1 = bit_num1.zfill(max_length)
    bit_num2 = bit_num2.zfill(max_length)       
    num = ""
    for k in range(0, max_length):
      if num1 >> k & 1 and not num2 >> k & 1:
        num = "1" + num
      elif not num1 >> k & 1 and num2 >> k & 1:
        num = "1" + num
      else:
        num = "0" + num
    amount += int(num, 2) % (10**9 + 7)

L = 10**9 + 7
print(amount % L)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))  # O(N)
p = len(format(max(A), 'b')) # O(N)
digit = ['0' + str(p) + 'b'] * N
S = list(map(format, A, digit))  # O(N)

r = [0] * p
for s in S:
  for j in range(p):
    r[j] += int(s[j])

ans = 0
for j in range(p):
  ans += r[-(j+1)] * (N - r[-(j+1)]) * (2 ** j)

print(ans % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))  # O(N)
p = len(format(max(A), 'b')) # O(N)
digit = ['0' + str(p) + 'b'] * N
S = list(map(format, A, digit))  # O(N)

r = [0] * p
for s in S:
  for j in range(p):
    r[j] += int(s[j])

ans = 0
for j in range(p):
  ans += r[-(j+1)] * (N - r[-(j+1)]) * (2 ** j)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

p = len(format(max(A), 'b'))
digit = '0' + str(p) + 'b'
#S = list(map(format, A, digit))

r = [0] * p
for a in A:
  s = format(a, digit)
  for j in range(p):
    r[j] += int(s[j])

res = 0
for j in range(p):
  res += r[j] * (N - r[j]) * (2 ** (p-1-j))

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

Submission status: Time Limit Exceeded

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

p = len(format(max(A), 'b'))
digit = '0' + str(p) + 'b'
#S = list(map(format, A, digit))

r = [0] * p
for a in A:
  for j in range(p):
    s = format(a, digit)
    r[j] += int(s[j])

res = 0
for j in range(p):
  res += r[j] * (N - r[j]) * (2 ** (p-1-j))

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

Submission status: Time Limit Exceeded

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

p = len(format(max(A), 'b'))
digit = ['0' + str(p) + 'b'] * N
S = list(map(format, A, digit))

r = [0] * p
for s in S:
  for j in range(p):
    r[j] += int(s[j])

res = 0
for j in range(p):
  res += r[j] * (N - r[j]) * (2 ** (p-1-j))

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

Submission status: Time Limit Exceeded

Solution code:

def trans(number):
    i = 0
    while(1):
        i += 1
        if(number - 2**i < 0):
            i = i - 1
            break


    sel = [0 for i in range(61)]
    sel[- (i + 1)] = 1
    number = number - 2**i
    i = i - 1
    count = -(i + 1)
    while(i >= 0):
        if(number - 2**i >= 0):
            number = number - 2**i
            sel[count] = 1
            count += 1
        else:
            count += 1

        i = i - 1
    return(sel)

def reverse(number_list):
    result = 0
    count = 60
    for i in range(61):
        result += number_list[i] * 2**count
        count = count - 1
    return(result)


def calculate(num1,num2):
    numa = trans(num1)
    numb = trans(num2)
    result = [0 for i in range(61)]
    for i in range(61):
        if(numa[i] != numb[i]):
            result[i] = 1
    return(reverse(result))


num = int(input())

point = input().split(' ')

for i in range(num):
    point[i] = int(point[i])

result = 0
for i in range(num - 1):
    for l in range(num - i - 1):
        result += calculate(point[i],point[i + l + 1])

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

Submission status: Time Limit Exceeded

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

bit = [0] * 60
for a in A:
    i = 0
    while a > 0:
        bit[i] += a & 1
        i += 1
        a >>= 1

ans = 0
for i, x in enumerate(bit):
    x = x*(n-x)
    for _ in range(i):
        x *= 2
        x %= mod
    ans += x
    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):
    for j in range(i+1,N+1):
        sum += A[i-1] ^ A[j-1]

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

Submission status: Time Limit Exceeded

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

p = len(format(max(A), 'b'))
digit = '0' + str(p) + 'b'

r = [0] * p
for i in range(N):
  tmp = format(A[i], digit)
  #print(tmp)
  for j in range(p):
    r[j] += int(tmp[j])

#print(r)
s = 0
for j in range(p):
  s += r[j] * (N - r[j]) * (2 ** (p-1-j))

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

Submission status: Time Limit Exceeded

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

r = [0] * 60
for i in range(N):
  tmp = format(A[i], '060b')
  #print(tmp)
  for j in range(60):
    r[j] += int(tmp[j])

s = 0
for j in range(60):
  s += r[j] * (N - r[j]) * (2 ** (59-j))
  

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

#print(bin(10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
def count(num_lst):
    count = [0]*60
    for num in num_lst:
        for i in range(60):
            tmp = 0
            if tmp == num:
                break
            if num & (1<<i):
                count[i] += 1
                tmp += 2**i
    return count

n = int(input())
num_list = list(map(int,input().split()))
mod = 10**9 + 7

count = count(num_list)
ans = 0
for i in range(60):
    if i == 0:
        pow_two = 1
    else:
        pow_two = pow_two * 2 % mod
    ans += pow_two * count[i] * (n - count[i]) % mod
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def count(num_lst):
    count = [0]*60
    for num in num_lst:
        for i in range(60):
            if num & (1<<i):
                count[i] += 1
    return count

n = int(input())
num_list = list(map(int,input().split()))
mod = 10**9 + 7

count = count(num_list)
ans = 0
for i in range(60):
    if i == 0:
        pow_two = 1
    else:
        pow_two = pow_two * 2 % mod
    ans += pow_two * count[i] * (n - count[i]) % mod
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

length = N
amount = 0
for i in range(length-1):
  for j in range(i+1, length):
    num1 = num_list[i]
    num2 = num_list[j]
    bit_num1 = format(num1, "b")
    bit_num2 = format(num2, "b")
    length_num1 = len(bit_num1)
    length_num2 = len(bit_num2)
    max_length = max(length_num1, length_num2)
    bit_num1 = bit_num1.zfill(max_length)
    bit_num2 = bit_num2.zfill(max_length)       
    num = ""
    for k in range(1, max_length+1):
      if int(bit_num1[-k]) and not int(bit_num2[-k]):
        num = "1" + num
      elif not int(bit_num1[-k]) and int(bit_num2[-k]):
        num = "1" + num
      else:
        num = "0" + num
    amount += int(num, 2) % (10**9 + 7)

L = 10**9 + 7
print(amount % L)

Submission status: Time Limit Exceeded

Solution code:
def count(num_lst):
    count = [0]*60
    for num in num_lst:
        for i in range(60):
            if num & (1<<i):
                count[i] += 1
    return count

n = int(input())
num_list = list(map(int,input().split()))
mod = 10**9 + 7

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