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 = list(map(int,input().split()))
MOD = 10 ** 9 + 7

K = [0] * 61
for a in A:
    L = list(format(a, 'b').zfill(61))
    M = list(int(s) for s in L)
    for i in range(61):
        K[i] += M[i]

cnt = []
for i in range(61):
    cnt.append(K[i] * (N - K[i]))
cnt.reverse()

ans = 0
for i in range(61):
    ans += (2 ** i) * cnt[i] % MOD

print(ans % MOD)

Submission status: Time Limit Exceeded

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

K = []
for a in A:
    L = list(format(a, 'b').zfill(61))
    M = list(int(s) for s in L)
    K.append(M)

cnt = []
for i in range(61):
    temp_1 = 0
    for j in range(N):
        if K[j][i] == 1:
            temp_1 += 1
    temp_0 = N - temp_1
    cnt.append(temp_0 * temp_1)
cnt.reverse()

ans = 0
for i in range(61):
    ans += (2 ** i) * cnt[i] % MOD

print(ans % MOD)

Submission status: Time Limit Exceeded

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

for i in a:
  for j in range(len(bin(i))-2):
    count[j] += 1 & (i>>j)

print(sum([count[i]*(n-count[i])*(1<<i) for i in range(len(count))])%1000000007)

Submission status: Time Limit Exceeded

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

for i in a:
  for j in range(len(bin(i))-2):
    count[j] += 1 & (i>>j)

print(sum([count[i]*(n-count[i])*2**i for i in range(len(count))])%1000000007)

Submission status: Time Limit Exceeded

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

for i in a:
  for j in range(len(bin(i))-2):
    if (2**j)&i != 0:
      count[j] += 1

print(sum([count[i]*(n-count[i])*2**i for i in range(len(count))])%1000000007)

Submission status: Time Limit Exceeded

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

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

print(r % (pow(10, 9) + 7))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
S=[0]*60

for a in A:
  c=0
  while a>0:
    if a&1!=0:
      S[c]+=1
    a>>=1
    c+=1

s,c=0,0
while c<60:
  s+=S[c]*(N-S[c])*((2**c)%(10**9+7))
  c+=1

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
S=[0]*60

for i,a in enumerate(A):
  c=0
  while a>0:
    if a&1!=0:
      S[c]+=1
    a>>=1
    c+=1

s,c=0,0
while c<60:
  s+=S[c]*(N-S[c])*((2**c)%(10**9+7))
  c+=1

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
S=[[0]*60 for x in range(N+1)]

for i,a in enumerate(A):
  c=0
  while a>0:
    if a&1!=0:
      S[i+1][c]=1
    a>>=1
    c+=1
  for c in range(60):
    S[i+1][c]+=S[i][c]

s=0
for i,a in enumerate(A[:N-1]):
  c,i=0,i+1
  while c<60:
    s+=2**c*((S[N][c]-S[i][c]) if a&1==0 else (N-S[N][c]+S[i][c]-i))
    s%=10**9+7
    a>>=1
    c+=1

print(s)

Submission status: Time Limit Exceeded

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

x = [a[i]^a[j] for i in  range(0,n-1) for j in  range(i+1,n)]
print(sum(x)%1000000007)

Submission status: Time Limit Exceeded

Solution code:

def add(a,b):
    mod=1000000007
    res=(a%mod+b%mod)%mod
    return res

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=add(ans,A[i]^A[j])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ans=0
for i in range(64):
    x,y=0,0
    for j in a:
        if j>>i&1:
            y+=1
        else:
            x+=1
    ans+=x*y*(1<<i)
    ans%=10**9+7
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
B=[0]*60
ans=0
mod=10**9+7
for i in range(n):
  a=str(bin(A[i]))[2:].zfill(60)
  for j in range(60):
    if a[j]=="0":
      ans=(ans+B[j]*(pow(2,(59-j),mod)))%mod
    else:
      ans=(ans+(i-B[j])*pow(2,(59-j),mod))%mod
      B[j]+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
B=[0]*60
C=[0]*60
ans=0
mod=10**9+7
for i,a in enumerate(A):
  for j in range(60):
    if a%2==0:
      C[j]+=B[j]
    else:
      C[j]+=i-B[j]
      B[j]+=1
    a//=2
for i in range(60):
  ans=(ans+C[i]*(pow(2,i,mod)))%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
B=[0]*60
C=[0]*60
ans=0
mod=10**9+7
for i,a in enumerate(A):
  for j in range(60):
    if a%2==0:
      C[j]+=B[j]
    else:
      C[j]+=i-B[j]
      B[j]+=1
    a//=2
for i in range(60):
  ans=(ans+C[i]*(2**i))%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
B=[0]*60
ans=0
mod=10**9+7
for i,a in enumerate(A):
  for j in range(60):
    if a%2==0:
      ans=(ans+B[j]*(2**j))%mod
    else:
      ans=(ans+(i-B[j])*(2**j))%mod
      B[j]+=1
    a//=2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
z = 7 + (10 ** 9)
nums = list(map(int, input().split()))
ans = 0
for x in range(len(nums)):
    for y in range(x, len(nums)):
        u = nums[x] ^ nums[y]
        ans = ans + u
print(ans % z)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a = list(map(int, input().split()))
b=[0]*60
ans=0
count=0
mod=10**9+7

for i in range(60):
    for j in range(n):
        if a[j]>>i&1==1:
            count+=1

    b[i]=count
    count=0

for i in range(60):
    ans+=2**i*( b[i]*(n-b[i]) )


print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
B=[0]*60
ans=0
mod=10**9+7
for i in range(n):
  a=str(bin(A[i]))[2:].zfill(60)
  for j in range(60):
    if a[j]=="0":
      ans=(ans+B[j]*(2**(59-j)))%mod
    else:
      ans=(ans+(i-B[j])*(2**(59-j)))%mod
      B[j]+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    ans = 0
    for i in range(0,60) :
        one = zer = 0
        for x in A:
            if(x&(1<<i)):
                one+=1
            else:
                zer+=1
        ans += one*zer*(1<<i)
    print(ans%1000000007)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
arr=[int(i) for i in input().split()]
def sumXOR(arr, n):
    MOD=int((1e+9)+7)
    sum = 0
    for i in range(0, 62): 
        zc = 0
        oc = 0
        idsum = 0
        for j in range(0, n): 
            if (arr[j] % 2 == 0): 
                zc = zc + 1
            else: 
                oc = oc + 1
            arr[j] = arr[j]//2
        idsum = oc * zc * (1 << i) 
        sum = (sum + idsum)%MOD
    return sum

ans = sumXOR(arr, n); 
print (ans)

Submission status: Time Limit Exceeded

Solution code:
sum = 0
num = input()
list = [int(i) for i in input().split()]
 
#list2 = [3,1,4,1,5,9,2,6,5,3]
#list2 = [1,2,3]
 
for i in range(int(num)):
    for j in range(i+1,int(num)):
        sum += list[i]^list[j]
print(sum % 1000000007)

Submission status: Time Limit Exceeded

Solution code:

sum = 0
num = input()
list = [int(i) for i in input().split()]

#list2 = [3,1,4,1,5,9,2,6,5,3]
#list2 = [1,2,3]

for i in range(len(list)):
    for j in range(len(list)):
        if i < j:
            sum += list[i]^list[j]

print(sum % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
from collections import defaultdict
d = dict()
d[0] = defaultdict(int)
d[1] = defaultdict(int)
for i in map(int,input().split()):
  for idx,j in enumerate(reversed('{:b}'.format(i))):
    d[int(j)][idx]+=1

m = max(set(d[0].keys()) | set(d[1].keys()) )

print(int(sum([((2**i)* (N-d[1][i])*d[1][i])%(1e9+7) for i in range(m+1)])%(1e9+7)))

Submission status: Time Limit Exceeded

Solution code:
nums = int(input())
a = list(map(int, input().split(" ")))
xor = 0

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

print(xor % (7 + 1000000000))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

level_count = dict()
for a in A:
    bin_a = bin(a)
    for i in range(len(bin_a[2:])):
        if int(bin_a[-i-1]) == 1:
            try:
                level_count[i] += 1
            except:
                level_count[i] = 1

sum_ = 0
for level, count in level_count.items():
    sum_ += 2**level * count * (N - count)
print(sum_ % (10**9 + 7))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
C = [0 for i in range(60)]
mod = 1000000007
for a in A:
  for i in range(60):
    C[i] += a%2
    a>>=1
    if a==0:
      break
ans = 0
for i in range(60):
  u = (2**(i))%mod
  num = C[i]*(n-C[i])
  ans+=u*num
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
C = [0 for i in range(60)]
mod = 1000000007
for a in A:
  for i in range(60):
    C[i] += a%2
    a//=2
    if a==0:
      break
ans = 0
for i in range(60):
  u = (2**(i))%mod
  num = C[i]*(n-C[i])
  ans+=u*num
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
n = int(input())
a = list(map(int,input().split()))
ans = 0
mod = (10**9 +7)
for j in range(61):
    num_zero = 0
    for i in range(len(a)):
        if a[i] % 2 == 0: 
            num_zero += 1
        a[i] = a[i] //2
    #print(a)
    ans += num_zero * (n-num_zero) * (2**j) % mod
    #print(ans)
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
mod = 10**9+7;ans=0
for i in range(60):
  cnt=sum([a>>i&1for a in A]) 
  cnt=cnt*(n-cnt)%mod
  cnt=2**i*cnt%mod
  ans+=cnt
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
mod = 10**9+7;ans=0
for i in range(60):
  cnt=0
  for a in A: cnt+=a>>i&1
  cnt=cnt*(n-cnt)%mod
  cnt=2**i*cnt%mod
  ans+=cnt
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
mod = 10**9+7;ans=0
for i in range(60):
  cnt=0
  for a in A: cnt+=a>>i&1
  cnt=cnt*(n-cnt)%mod
  for i in range(i): cnt=cnt*2%mod
  ans+=cnt
print(ans%mod)

Submission status: Time Limit Exceeded

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

MOD = 1000000007

ans = 0

for i in range(62):
    b = 1 << i
    # v = [[0 for i in range(n + 1)] for j in range(2)]
    v = [[0 for i in range(2)] for j in range(n + 1)]
    
    for j in reversed(range(n)):
        x = (a[j] >> i) & 1
        v[j][x] = v[j+1][x] + 1
        v[j][1-x] = v[j+1][1-x]
        
    t = 0
    for j in range(n-1):
        x = (a[j] >> i) & 1
        t += v[j+1][1-x]
        t %= MOD
           
    y = t * b
    y %= MOD
    ans += y
    ans %= MOD
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
mod = int(1e9+7)
input=sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2


for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*pow(2, idx, mod)%mod

        else:
            ans += S[i+1][idx]*pow(2, idx, mod)%mod

        idx += 1
        tmp //= 2
        ans %= mod
    for x in S[i+1][idx:]:
        ans += x*pow(2, idx, mod)%mod
        idx += 1
        ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*(2**i)
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2

for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*2**idx%mod

        else:
            ans += S[i+1][idx]*2**idx%mod

        idx += 1
        tmp //= 2

    rest = S[i+1][idx:]
    for x in rest:
        ans += x*2**idx%mod
        idx += 1

    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    mod = int(1e9+7)
    input=sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    #S[0]は使わない
    S = [[0]*60 for _ in range(N)]

    tmp = A[-1]
    idx = 0
    while tmp > 0:
        if tmp%2:
            S[-1][idx] += 1
        idx += 1
        tmp //= 2
    S[-1] = tuple(S[-1])

    for i in range(N-2, 0, -1):
        for j in range(60):
            S[i][j] = S[i+1][j]
        tmp = A[i]
        idx = 0
        while tmp > 0:
            if tmp % 2:
                S[i][idx] += 1
            idx += 1
            tmp //= 2
        S[i] = tuple(S[i])

    ans = 0
    for i in range(N-1):
        tmp = A[i]
        idx = 0
        while tmp > 0:
            if tmp % 2:
                ans += ((N-1-i)-S[i+1][idx])*2**idx

            else:
                ans += S[i+1][idx]*2**idx

            idx += 1
            tmp //= 2

        for x in S[i+1][idx:]:
            ans += x*2**idx%mod
            idx += 1

        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    mod = int(1e9+7)
    input=sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    #S[0]は使わない
    S = [[0]*60 for _ in range(N)]

    tmp = A[-1]
    idx = 0
    while tmp > 0:
        if tmp%2:
            S[-1][idx] += 1
        idx += 1
        tmp //= 2

    for i in range(N-2, 0, -1):
        for j in range(60):
            S[i][j] = S[i+1][j]
        tmp = A[i]
        idx = 0
        while tmp > 0:
            if tmp % 2:
                S[i][idx] += 1
            idx += 1
            tmp //= 2

    ans = 0
    for i in range(N-1):
        tmp = A[i]
        idx = 0
        while tmp > 0:
            if tmp % 2:
                ans += ((N-1-i)-S[i+1][idx])*2**idx

            else:
                ans += S[i+1][idx]*2**idx

            idx += 1
            tmp //= 2

        for x in S[i+1][idx:]:
            ans += x*2**idx%mod
            idx += 1

        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
mod = int(1e9+7)
input=sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2

for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*2**idx

        else:
            ans += S[i+1][idx]*2**idx

        idx += 1
        tmp //= 2

    for x in S[i+1][idx:]:
        ans += x*2**idx%mod
        idx += 1

    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
mod = int(1e9+7)
input=sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2

for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*2**idx

        else:
            ans += S[i+1][idx]*2**idx

        idx += 1
        tmp //= 2

    rest = S[i+1][idx:]
    for x in rest:
        ans += x*2**idx
        idx += 1

    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2

for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*2**idx

        else:
            ans += S[i+1][idx]*2**idx

        idx += 1
        tmp //= 2

    rest = S[i+1][idx:]
    for x in rest:
        ans += x*2**idx
        idx += 1

    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
mod = int(1e9 + 7)
N = int(input())
A = list(map(int, input().split()))
S = 0
j = 1
while A != [0 for i in range(N)]:
  m = 0
  n = 0
  for i in range(N):
    if A[i] % 2 == 1:
      m += 1
    else:
      n += 1
    A[i] //= 2
  S += (m * n) * j
  j *= 2
S %= mod
print(S)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 60
mod = 1000000007
ans = 0
for i in range(n):
    b = format(a[i],'b')
    for j in range(len(b)):
        cnt[j] += int(b[-j-1])
for i in range(60):
    ans += (pow(2,i,mod)*(cnt[i]*(n-cnt[i])%mod))%mod
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=0
for j in range(len(bin(max(a)))-2):
    cnt1=0
    cnt0=0
    for i in range(n):
      if (a[i]>>j)&1:
        cnt1+=1
      else:
        cnt0+=1
    s+=cnt1*cnt0*2**j
print(s%(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
q2 = 1
for j in range(60):
    mm1 = 0
    for i in range(n):
        if a[i]>>j&1:
            mm1 += 1

    ttl = ((n-mm1)*mm1)
    ans += ((q2)*((ttl)%mod))%mod
    ans %= mod
    q2 = (q2*2)%mod

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

mod = 10**9+7

mm0 = [0 for i in range(60)]
mm1 = [0 for i in range(60)]

for i in range(n):
    for j in range(60):
        if (a[i]>>j)<0:
            break
        if (a[i]>>j)&1:
            mm1[j] += 1

ans = 0
for i in range(60):
    ttl = ((n-mm1[i])*mm1[i])
    ans += (((1<<i)%mod)*((ttl)%mod))%mod
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=0
for j in range(len(bin(max(a)))-2):
    cnt1=0
    cnt0=0
    for i in range(n):
      if (a[i]>>j)&1:
        cnt1+=1
      else:
        cnt0+=1
    s+=(cnt1*cnt0*2**j)%(10**9+7)
print(s%(10**9+7))

Submission status: Time Limit Exceeded

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

mod = 10**9+7

mm0 = [0 for i in range(60)]
mm1 = [0 for i in range(60)]

for i in range(n):
    for j in range(60):
        if (a[i]>>j)<0:
            break
        if (a[i]>>j)&1:
            mm1[j] += 1

ans = 0
for i in range(60):
    ttl = ((n-mm1[i])*mm1[i])
    ans += ((1<<i)%mod)*((ttl)%mod)
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = int(1e9+7)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


def main():
    N = int(input())
    A = list(map(int, input().split()))
    M = 60
    bitcnt = [0] * M
    for a in A:
        for i in range(M):
            if a & (1 << i):
                bitcnt[i] += 1
    ans = 0
    for a in A:
        for i in range(M):
            if a & (1 << i):
                ans = (ans + (1 << i) * (N - bitcnt[i])) % MOD
            else:
                ans = (ans + (1 << i) * bitcnt[i]) % MOD
            ans %= MOD
    ans = div(ans, 2)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
MOD = int(1e9+7)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


def main():
    N = int(input())
    A = list(map(int, input().split()))
    M = 60
    bitcnt = [0] * M
    for a in A:
        for i in range(M):
            if a & (1 << i):
                bitcnt[i] += 1
    ans = 0
    for a in A:
        for i in range(M):
            if a & (1 << i):
                ans += (1 << i) * (N - bitcnt[i])
            else:
                ans += (1 << i) * bitcnt[i]
            ans %= MOD
    ans = div(ans, 2)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(int(x) for x in input().split())
mod = 10**9+7

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

print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=0
    temp=0
    MOD=10**9+7
    cnt1=[0]*60
    for num in a:
        for i in range(60):
            cnt1[i] += (num >> i) & 1
    for i in range(60):
        ans += cnt1[i] * (n - cnt1[i]) * pow(2,i,MOD)
    print(ans % MOD)


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=0
    temp=0
    MOD=10**9+7
    bin_a=[[0] * n for i in range(60)]
    cnt1=[0]*60
    for i in range(n):
        tmp=str(bin(a[i]))
        # print(a[i])
        # print(len(tmp))
        for j in range(len(tmp)-2):
            if j==len(tmp)-2:
                break
            # print(tmp[len(tmp)-i-1])
            bin_a[j][i]=int(tmp[len(tmp)-j-1])
            cnt1[j]+=int(tmp[len(tmp)-j-1])

    for i in range(60):
        # cnt1=sum(bin_a[i])
        # cnt0=n-cnt1
        ans+=cnt1[i]*(n-cnt1[i])*2**i%MOD
    print(ans%MOD)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=0
    temp=0
    MOD=10**9+7
    bin_a=[[0] * n for i in range(60)]
    cnt1=[0]*60
    for i in range(n):
        tmp=str(bin(a[i]))
        # print(a[i])
        # print(len(tmp))
        for j in range(len(tmp)-2):
            if tmp[len(tmp)-j-1] == 'b':
                break
            # print(tmp[len(tmp)-i-1])
            bin_a[j][i]=int(tmp[len(tmp)-j-1])
            cnt1[j]+=int(tmp[len(tmp)-j-1])

    for i in range(60):
        # cnt1=sum(bin_a[i])
        # cnt0=n-cnt1
        ans+=cnt1[i]*(n-cnt1[i])*2**i%MOD
    print(ans%MOD)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=0
    temp=0
    MOD=10**9+7
    bin_a=[[0] * n for i in range(60)]
    for i in range(n):
        tmp=str(bin(a[i]))
        # print(a[i])
        # print(len(tmp))
        for j in range(len(tmp)-2):
            if tmp[len(tmp)-j-1] == 'b':
                break
            # print(tmp[len(tmp)-i-1])
            bin_a[j][i]=int(tmp[len(tmp)-j-1])

    for i in range(60):
        cnt1=sum(bin_a[i])
        cnt0=n-cnt1
        ans+=cnt1*cnt0*2**i%MOD
    print(ans%MOD)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
MOD = 10 ** 9 + 7
 
n = int(input())
a = list(map(int, input().split()))
 
bin_a = [bin(x)[2:] for x in a]
 
max_length = len(max(bin_a, key=len))
 
for ind, num in enumerate(bin_a):
    if len(num) < max_length:
        bin_a[ind] = '0' * (max_length - len(num)) + bin_a[ind]
 
# print(bin_a, max_length)
 
result = 0
for i in range(max_length-1, -1, -1):
    oc = sum([int(x[i]) for x in bin_a])
    zc = n - oc
    # print(oc, zc)
    # print(no_of_ones)
    result += (oc * zc * (2 ** (max_length - i - 1))) % MOD
 
 
print(result % MOD)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10 ** 9 + 7

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

bin_a = [bin(x)[2:] for x in a]

max_length = len(max(bin_a, key=len))

for ind, num in enumerate(bin_a):
    if len(num) < max_length:
        bin_a[ind] = '0' * (max_length - len(num)) + bin_a[ind]

# print(bin_a, max_length)

result = 0
for i in range(max_length-1, -1, -1):
    oc = sum([int(x[i]) for x in bin_a])
    zc = n - oc
    # print(oc, zc)
    # print(no_of_ones)
    result += oc * zc * (2 ** (max_length - i - 1))


print(result % MOD)

Submission status: Time Limit Exceeded

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

mod = 10**9+7

num = [0]*60

ans=0

for i in range(len(a)):
    for j in range(60):
        if((1<<j)&a[i]):
            num[j]+=1

for i in range(len(num)):
    po = (n-num[i])*(num[i])
    ans+=((po)*(pow(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

mm0 = [0 for i in range(60)]
mm1 = [0 for i in range(60)]

for i in range(n):
    for j in range(60):
        if (a[i]>>j)<0:
            break
        if (a[i]>>j)&1:
            mm1[j] += 1

ans = 0
for i in range(60):
    ttl = (n-mm1[i])*mm1[i]
    ans += ((1<<i)*ttl)%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

mm0 = [0 for i in range(61)]
mm1 = [0 for i in range(61)]

for i in range(n):
    for j in range(61):
        if (a[i]>>j)<0:
            break
        if (a[i]>>j)&1:
            mm1[j] += 1

ans = 0
for i in range(61):
    ttl = (n-mm1[i])*mm1[i]
    ans += ((1<<i)*ttl)%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

mm0 = [0 for i in range(61)]
mm1 = [0 for i in range(61)]

for i in range(n):
    for j in range(61):
        if (a[i]>>j)<0:
            break
        if (a[i]>>j)&1:
            mm1[j] += 1

for i in range(61):
    mm0[i] = n-mm1[i] 

ans = 0

for i in range(61):
    ttl = mm0[i]*mm1[i]
    ans += ((1<<i)*ttl)%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
sum = 0
for i in range(60):
    count0 = 0
    count1 = 0
    count2 = 0

    for j in range(N):
        if A[j] & 1:
            count1 += 1
        else:
            count0 += 1
        A[j] = A[j] >> 1
    count2 = count0 * count1
    sum += count2 * (2 ** i)

print(sum % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
M=len(bin(max(A)))-2
B=[]
MOD=10**9+7
for i in range(N):
    B.append(bin(A[i])[2:].rjust(M,'0'))
T=[0]*M
for i in range(M):
    for j in range(N):
        T[i]+=int(B[j][i])

T=T[::-1]
ans=0
for i in range(M):
    ans+=T[i]*(N-T[i])*(2**i)
    ans%=MOD
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
MOD = 10**9+7
for i in range(60):
    b = 1 << i
    cnt_1 = sum([a & b > 0 for a in A])
    cnt_0 = N - cnt_1
    b_sum = cnt_1 * cnt_0
    ans += (b_sum << i) % MOD
print(ans%MOD)

Submission status: Time Limit Exceeded

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

result = 0
for i in range(60):
    on = sum([(1 << i) & a for a in A]) >> i
    result += (on * (N - on)) << i
    result %= ((10**9) + 7)

print(result)

Submission status: Time Limit Exceeded

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

each_bit_sum = [{"0": 0, "1": 0} for _ in range(62)]
result = 0
for a in A:
    for i, b in enumerate(format(a, "b").zfill(62)[::-1]):
        each_bit_sum[i][b] += 1

for i, b in enumerate(each_bit_sum):
    result += ((b["0"] * b["1"]) * (2**i)) % ((10**9) + 7)

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