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 = list(map(int, input().split()))
# all_sum = 0
# for i in range(n):
#     for j in range(i+1, n):
#         # print("i:{}, j:{}, xor:{}".format(i, j, a_list[i] ^ a_list[j]))
#         mod_num = (a_list[i] ^ a_list[j]) % (10 ** 9 + 7)
#         all_sum += mod_num

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

# 結果の数
result_num = 0

# 割る数
mod = 10 ** 9 + 7

# ある桁について考える
for i in range(1, 61):
    zero_count = 0
    one_count = 0
    for a in a_list:
        i_num = str(bin(a))[2:].zfill(60)[-1 * i]
        if int(i_num) == 0:
            zero_count += 1
        else:
            one_count += 1
    result_num += (2 ** (i-1)) % mod * (zero_count * one_count) % mod 
    result_num %= mod

print(result_num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
# all_sum = 0
# for i in range(n):
#     for j in range(i+1, n):
#         # print("i:{}, j:{}, xor:{}".format(i, j, a_list[i] ^ a_list[j]))
#         mod_num = (a_list[i] ^ a_list[j]) % (10 ** 9 + 7)
#         all_sum += mod_num

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

result_num = 0
# ある桁について考える
for i in range(1, 61):
    zero_count = 0
    one_count = 0
    for a in a_list:
        i_num = str(bin(a))[2:].zfill(60)[-1 * i]
        if int(i_num) == 0:
            zero_count += 1
        else:
            one_count += 1
    result_num += 2 ** (i-1) * zero_count * one_count

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

Submission status: Time Limit Exceeded

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

all_sum = 0
for i in range(n):
    for j in range(i+1, n):
        # print("i:{}, j:{}, xor:{}".format(i, j, a_list[i] ^ a_list[j]))
        mod_num = (a_list[i] ^ a_list[j]) % (10 ** 9 + 7)
        all_sum += mod_num

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

Submission status: Time Limit Exceeded

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

all_sum = 0
for i in range(n):
    for j in range(i+1, n):
        # print("i:{}, j:{}, xor:{}".format(i, j, a_list[i] ^ a_list[j]))
        all_sum += a_list[i] ^ a_list[j]

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

Submission status: Time Limit Exceeded

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + ((n>>j)&1)

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        b = N-a-i # 0

        if n%2:
            ans += b*(2**j)
        else:
            ans += a*(2**j)
        n//=2
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + n%2
        n//=2

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        b = N-a-i # 0

        if n%2:
            ans += b*(2**j)
        else:
            ans += a*(2**j)
        n//=2
    ans %= mod

print(ans)

Submission status: Time Limit Exceeded

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + ((n>>j)&1)

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        if (n>>j)&1:
            a = N-a-i # 0

        ans += a*(1<<j)
        ans %= mod

print(ans)

Submission status: Time Limit Exceeded

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + ((n>>j)&1)

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        b = N-a-i # 0

        if n%2:
            ans += b*(2**j)
        else:
            ans += a*(2**j)
        ans %= mod
        n//=2

print(ans)

Submission status: Time Limit Exceeded

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + n%2
        n//=2

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        b = N-a-i # 0

        if n%2:
            ans += b*(2**j)
        else:
            ans += a*(2**j)
        ans %= mod
        n//=2

print(ans)

Submission status: Time Limit Exceeded

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j]
        if n%2:
            d1[i][j] += 1
        n//=2

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        b = N-a-i # 0

        if n%2:
            ans += b*(2**j)
        else:
            ans += a*(2**j)
        ans %= mod
        n//=2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
ans = 0
cnt = defaultdict(int)

for i in range(n):
    for j in range(i+1, n):
        if a[i] == a[j]: continue
        par = (min(a[i], a[j]), max(a[i], a[j]))
        cnt[par] += 1

for par, c in cnt.items():
    ans += c*(par[0]^par[1])
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7
ans = 0
cnt = defaultdict(int)

for i in range(n):
    for j in range(i+1):
        if a[i] == a[j]: continue
        par = (min(a[i], a[j]), max(a[i], a[j]))
        cnt[par] += 1

for par, c in cnt.items():
    ans += c*(par[0]^ par[1])
    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):
        #print(a[i] ^ a[j])
        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()))
MOD = 10**9 + 7
ans = 0

for i in range(60):
    count0 = 0
    count1 = 0
    for j in range(N):
        a = A[j]>>i & 1
        if a==0:
            count0 += 1
        else:
            count1 += 1
    tmp = 2**i
    n = count0 * count1
    tmp = tmp * n
    ans += tmp
    ans = ans % MOD
print(ans)

Submission status: Time Limit Exceeded

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

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

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]

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

Submission status: Time Limit Exceeded

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

def main():
    N = int(input())
    INF = 10**9+7
    A = list(map(int,input().split()))
    M = max(A)
    l = M.bit_length()
    d = [[0,0] for _ in range(l)]
    for i in range(N):
        num = A[i]
        count = 0
        while count != l:
            use = num%2
            d[count][use] += 1
            num //= 2
            count += 1
        
    ans = 0    
    for i in range(l):
        x,y = d[i]
        ans += (x*y)*(2**i)
        ans %= INF
        
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
N=int(input())

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

two=[2**i for i in range(61)]
two=two[::-1]
log=[0]*61

for i in range(len(A)):
    for j in range(len(two)):
        if A[i]-two[j]>=0:
            A[i]-=two[j]
            log[j]+=1

ans=0
for i in range(len(two)):
    ans+=(N-log[i])*log[i]*two[i]

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

Submission status: Time Limit Exceeded

Solution code:
# import collections as c
ip = lambda : map(int, input().split())
mod = 10**9+7
# ##############
N = int(input())
l = list(ip())
l.reverse()
v = [0]*60
av = [0]*60
for i in range(len(l)):
    for j in range(60):
        if i>0:
            if l[i]>>j & 1:
                av[j]+=i-v[j]
            else:
                av[j] += v[j]
        if l[i]>>j & 1:
            v[j]+=1
ans = 0
p2 = [1]*60
for i in range(1,60):
    p2[i] = p2[i-1]*2%mod
for i in range(60):
    ans = (ans + av[i]*p2[i]%mod)%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections as c
ip = lambda : map(int, input().split())
mod = 10**9+7
# ##############
N = int(input())
l = list(ip())
l.reverse()
v = [0]*60
av = [0]*60
for i in range(len(l)):
    for j in range(60):
        if i>0:
            if l[i]>>j & 1:
                av[j]+=i-v[j]
            else:
                av[j] += v[j]
        if l[i]>>j & 1:
            v[j]+=1
ans = 0
p2 = [1]*60
for i in range(1,60):
    p2[i] = p2[i-1]*2%mod
for i in range(60):
    ans = (ans + av[i]*p2[i]%mod)%mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = map(int, input().split())
digits = [0]*60
for i in a:
  for j in range(60):
    digits[j] += i%2
    i//=2
    if i==0:
      break
ans = 0
for i in range(60):
  ans += digits[i]*(n-digits[i])*(2**i)
  ans %= 10**9+7
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(lambda x:format(int(x), '060b') , input().split()))
n1 = [0]*60
for i in a:
  for j in range(60):
    if i[59-j]=='1':
      n1[j] += 1
ans = 0
for i in range(60):
  ans += n1[i]*(n-n1[i])*2**i
  ans %= 10**9+7
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()], reverse=True)
mod = 10**9 + 7
ans = 0
for j in range(len(bin(a[0])) - 2):
  k = [0, 0]
  for i in a:
    k[i >> j & 1] += 1
  ans = (ans + (k[0] * k[1]) * 2**j) % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list_num = list(map(int, input().split()))
ans = []

for i in range(n-1):
    for j in range(i+1, n):
        ans.append(list_num[i] ^ list_num[j])


b = 10**9 + 7
a = sum(ans) % b

print(a)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    ans = [0] * 60
    
    
    x0 = 0
    x1 = 0
    for j in range(N):
        if (A[j]>>0)&1:
            x1 += 1
        else:
            x0 += 1
    
    ans[0] = x0*x1
    for i in range(1, 60):
        # x0 = len([j for j in range(N) if not (A[j]>>i)&1])
        # x1 = len([j for j in range(N) if (A[j]>>i)&1])
        x0 = 0
        x1 = 0
        for j in range(N):
            if (A[j]>>1)&1:
                x1 += 1
            else:
                x0 += 1
            A[j] = A[j] >> 1

        ans[i] = x0*x1

    x = 0
    for i in range(60):
        # print(i, 2**i)
        x += pow(2, i) * ans[i] % MOD

    print(x%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    ans = [0] * 60
    
    
    for i in range(60):
        # x0 = len([j for j in range(N) if not (A[j]>>i)&1])
        # x1 = len([j for j in range(N) if (A[j]>>i)&1])
        x0 = 0
        x1 = 0
        for j in range(N):
            if (A[j]>>i)&1:
                x1 += 1
            else:
                x0 += 1

        ans[i] = x0*x1

    x = 0
    for i in range(60):
        # print(i, 2**i)
        x += pow(2, i) * ans[i] % MOD

    print(x%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    ans = [0] * 63
    
    
    for i in range(63):
        # x0 = len([j for j in range(N) if not (A[j]>>i)&1])
        # x1 = len([j for j in range(N) if (A[j]>>i)&1])
        x0 = 0
        x1 = 0
        for j in range(N):
            if (A[j]>>i)&1:
                x1 += 1
            else:
                x0 += 1

        ans[i] = x0*x1

    x = 0
    for i in range(len(ans)):
        # print(i, 2**i)
        x += pow(2, i) * ans[i] % MOD

    print(x%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    ans = [0] * 63
    for i in range(63):
        x0 = len([j for j in range(N) if not (A[j]>>i)&1])
        x1 = len([j for j in range(N) if (A[j]>>i)&1])
        ans[i] = x0*x1

    x = 0
    for i in range(len(ans)):
        # print(i, 2**i)
        x += (2 ** i) * ans[i] % MOD

    print(x%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
bin_A=[bin(c) for c in A]
flags=[True]*N

count=0
for keta in range(60):
   count_0=0
   count_1=0
   for i in range(N):
      if flags[i]:
         if bin_A[i][-1*(keta+1)]=="b":
            count_0+=1
            flags[i]=False
         elif bin_A[i][-1*(keta+1)]=="0":
            count_0+=1
         else:
            count_1+=1
      elif flags[i]==False:
         count_0+=1
   count+=count_0*count_1*2**keta

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

Submission status: Time Limit Exceeded

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

cnt = [[[0, 0] for _ in range(n + 1)] for _ in range(60)]
for i in range(60): # <= 2^60
    for j, v in enumerate(a):
        if v & (1 << i):
            cnt[i][j][1] = cnt[i][j - 1][1] + 1
            cnt[i][j][0] = cnt[i][j - 1][0]
        else:
            cnt[i][j][1] = cnt[i][j - 1][1]
            cnt[i][j][0] = cnt[i][j - 1][0] + 1

result = 0
for p, delete in enumerate(a):
    for i, cs in enumerate(cnt):
        if delete & (1 << i):
            target = 0
        else:
            target = 1

        result += (cs[n - 1][target] - cs[p - 1][target]) * (1 << i)
print(result % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
from math import log, ceil
N = int(input())
A = list(map(int, input().split()))

#print(ceil(log(max(A)+1,2)))
keta = ceil(log(max(A)+1,2))

X = [0] * keta

for a in A:
  work = a
  i = 0
  while work > 0:
    X[i] += work % 2
    i += 1
    work = work // 2

ans = 0
mod = int(1e9+7)
for i in range(len(X)):
  ans += X[i] * (N-X[i]) * 2**i
  ans = ans % mod
  
print(ans)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    As = list(map(int, input().split()))

    largest = max(As)
    digits = len(bin(largest))-2

    binaries = [format(i, '0'+str(digits)+'b') for i in As]

    total = 0
    for i in range(digits):
        t = [int(n[i]) for n in binaries]
        ones = sum(t)
        zeros = N - ones
        r = ones * zeros
        total += (2 ** (digits-i-1)) * r
        total = total % (10**9 + 7)

    print(total)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

import heapq
import collections
import math
import sys
N =  int(input())
input = sys.stdin.readline
# num = a << b →  a  * (2 ** b)
# 1 << i → i桁目のマスク
# mask = 1 << i
# num = a << b
# num & mask


#
nums = list(map(int,input().split(" ")))
keta = [0] * 62
# ある桁の1の出現回数
# keta[k] → 2**k の桁
jijou = []
MOD = 10 ** 9 + 7


for num in nums:
    s = format(num,"b")
    l = len(s)

    for i in range(0,l):
        if s[l - i - 1 ] == "1":
            keta[i] += 1

ans = 0
temp = 1
for i in range(62):

    ans += ( keta[i] * (N - keta[i])) * temp
    ans %= MOD
    temp *= 2
    temp %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:

import heapq
import collections
import math
import sys
N =  int(input())
input = sys.stdin.readline
# num = a << b →  a  * (2 ** b)
# 1 << i → i桁目のマスク
# mask = 1 << i
# num = a << b
# num & mask


#
nums = list(map(int,input().split(" ")))
keta = [0] * 62
# ある桁の1の出現回数
# keta[k] → 2**k の桁
jijou = []
MOD = 10 ** 9 + 7


for num in nums:
    s = format(num,"b")
    l = len(s)

    for i in range(0,l):
        if s[l - i - 1 ] == "1":
            keta[i] += 1

ans = 0
for i in range(62):
    temp = 1 << i
    ans += ( keta[i] * (N - keta[i])) * temp
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:

import heapq
import collections
import math
import sys
N =  int(input())
input = sys.stdin.readline
# num = a << b →  a  * (2 ** b)
# 1 << i → i桁目のマスク
# mask = 1 << i
# num = a << b
# num & mask
nums = list(map(int,input().split(" ")))
keta = [0] * 61
# ある桁の1の出現回数
# keta[k] → 2**k の桁
jijou = []
MOD = 10 ** 9 + 7
for i in range(62):
    temp = 1 << i
    temp%= MOD
    jijou.append(temp)

for num in nums:
    # s = format(num,"b")
    # l = len(s)

    for i in range(0,62):
        if num == 0:
            break
        temp = num & 1
        num  = num >> 1
        keta[i] += temp

ans = 0
for j,num in  enumerate(nums[:-1]):

    for i in range(0,61): #i →  2 ** i 乗 桁目に対応

        if num == 0:
            ans += (keta[i] * jijou[i]) % MOD
        else:
            temp = num & 1
            num = num >> 1
            if temp == 0:
                ans += (keta[i] * jijou[i]) % MOD
            else:
#              (N - j + 1) - (keta[i] + 1 ) → 0が経っているところの個数
                ans += (( (N - j + 1) - (keta[i] + 1)  ) * ( jijou[i]) ) % MOD
                keta[i] -= 1
        ans %= MOD
    ans %= MOD


print(ans)

Submission status: Time Limit Exceeded

Solution code:

import heapq
import collections
import sys
N =  int(input())
input = sys.stdin.readline

nums = list(map(int,input().split(" ")))
keta = [0] * 61
# ある桁の1の出現回数
# keta[k] → 2**k の桁
jijou = [1]
MOD = 10 ** 9 + 7
for i in range(60):
    temp = jijou[i] * 2
    temp%= MOD
    jijou.append(temp)

for num in nums:
    s = format(num,"b")
    l = len(s)
    for i in range(0,l):
        keta[i] += int(s[l - i - 1 ])
ans = 0
for j,num in  enumerate(nums[:-1]):
    s = format(num, "b")
    l = len(s)
    for i in range(0,61): #i →  2 ** i 乗 桁目に対応
        if l <= i:
            ans += (keta[i] * jijou[i]) % MOD
        else:
            if s[l - i - 1 ] == "0":
                ans += (keta[i] * jijou[i]) % MOD
            else:
#              (N - j + 1) - (keta[i] + 1 ) → 0が経っているところの個数
                ans += (( (N - j + 1) - (keta[i] + 1)  ) * ( jijou[i]) ) % MOD
                keta[i] -= 1
        ans %= MOD
    ans %= MOD


print(ans)

Submission status: Time Limit Exceeded

Solution code:

import heapq
import collections
N =  int(input())
nums = list(map(int,input().split(" ")))
keta = [0] * 61
# ある桁の1の出現回数
# keta[k] → 2**k の桁
jijou = [1]
MOD = 10 ** 9 + 7
for i in range(60):
    temp = jijou[i] * 2
    temp%= MOD
    jijou.append(temp)

for num in nums:
    s = format(num,"b")
    l = len(s)
    for i in range(0,l):
        keta[i] += int(s[l - i - 1 ])
ans = 0
for j,num in  enumerate(nums[:-1]):
    s = format(num, "b")
    l = len(s)
    for i in range(0,61): #i →  2 ** i 乗 桁目に対応
        if l <= i:
            ans += (keta[i] * jijou[i]) % MOD
        else:
            if s[l - i - 1 ] == "0":
                ans += (keta[i] * jijou[i]) % MOD
            else:
#              (N - j + 1) - (keta[i] + 1 ) → 0が経っているところの個数
                ans += (( (N - j + 1) - (keta[i] + 1)  ) * ( jijou[i]) ) % MOD
                keta[i] -= 1
        ans %= MOD
    ans %= MOD


print(ans)

Submission status: Time Limit Exceeded

Solution code:

import heapq
import collections
N =  int(input())
nums = list(map(int,input().split(" ")))
keta = [0 for _ in range(61)]
# ある桁の1の出現回数
# keta[k] → 2**k の桁
jijou = [1]
MOD = 10 ** 9 + 7
for i in range(60):
    temp = jijou[i] * 2
    temp%= MOD
    jijou.append(temp)

for num in nums:
    s = format(num,"b")
    l = len(s)
    for i in range(0,l):
        keta[i] += int(s[l - i - 1 ])
ans = 0
for j,num in  enumerate(nums[:-1]):
    s = format(num, "b")
    l = len(s)
    for i in range(0,61): #i →  2 ** i 乗 桁目に対応
        if l <= i:
            ans += (keta[i] * jijou[i]) % MOD
        else:
            if s[l - i - 1 ] == "0":
                ans += (keta[i] * jijou[i]) % MOD
            else:
#              (N - j + 1) - (keta[i] + 1 ) → 0が経っているところの個数
                ans += (( (N - j + 1) - (keta[i] + 1)  ) * ( jijou[i]) ) % MOD
                keta[i] -= 1
    ans %= MOD


print(ans)

Submission status: Time Limit Exceeded

Solution code:

import heapq
import collections
N =  int(input())
nums = list(map(int,input().split(" ")))
keta = [0 for _ in range(61)]
# ある桁の1の出現回数
# keta[k] → 2**k の桁
jijou = [1]
MOD = 10 ** 9 + 7
for i in range(60):
    temp = jijou[i] * 2
    temp%= MOD
    jijou.append(temp)

for num in nums:
    s = format(num,"b")
    l = len(s)
    for i in range(0,l):
        keta[i] += int(s[l - i - 1 ])
ans = 0
for j,num in  enumerate(nums[:-1]):
    s = format(num, "b")
    l = len(s)
    for i in range(0,61): #i →  2 ** i 乗 桁目に対応
        if l <= i:
            ans += (keta[i] * jijou[i]) % MOD
        else:
            if s[l - i - 1 ] == "0":
                ans += (keta[i] * jijou[i]) % MOD
            else:
#              (N - j + 1) - (keta[i] + 1 ) → 0が経っているところの個数
                ans += (( (N - j + 1) - (keta[i] + 1)  ) * ( jijou[i]) ) % MOD
                keta[i] -= 1


print(ans % MOD)

Submission status: Time Limit Exceeded

Solution code:

import heapq
import collections
N =  int(input())
nums = list(map(int,input().split(" ")))
keta = [0 for _ in range(61)]
# ある桁の1の出現回数
# keta[k] → 2**k の桁
jijou = [1]
MOD = 10 ** 9 + 7
for i in range(60):
    temp = jijou[i] * 2
    temp%= MOD
    jijou.append(temp)

for num in nums:
    s = format(num,"b")
    l = len(s)
    for i in range(0,l):
        keta[i] += int(s[l - i - 1 ])
ans = 0
for j,num in  enumerate(nums[:-1]):
    s = format(num, "b")
    l = len(s)
    for i in range(0,61): #i →  2 ** i 乗 桁目に対応
        if l <= i:
            ans += keta[i] * jijou[i] % MOD
        else:
            if s[l - i - 1 ] == "0":
                ans += keta[i] * jijou[i] % MOD
            else:
#              (N - j + 1) - (keta[i] + 1 ) → 0が経っているところの個数
                ans += ( (N - j + 1) - (keta[i] + 1)  ) * ( jijou[i])  % MOD
                keta[i] -= 1


print(ans % MOD)

Submission status: Time Limit Exceeded

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

def xor(p, q):
  bp = format(p, '060b')
  bq = format(q, '060b')
  r = ""
  for i in range(60):
    if bp[i] != bq[i]:
      r += "1"
    else:
      r += "0"
  #nr = int(r)
  rr = int(r, 2)
  return rr
  
for i in range(n-1):
  for j in range(n-i-1):
    # a[i] XOR a[j]をtotalに足す。
    total += xor(a[i], a[i + j + 1])
    
print(total % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

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

bit_lst = []
for i in range(n):
    bit_lst.append(format(lst[i], '060b'))
    
ans = 0
for i in range(60):
    tmp = []
    for j in range(n):
        tmp.append(bit_lst[j][i])
    
    cnt_one = tmp.count('1')
    cnt_zero = n - cnt_one
    
    tmp = cnt_one * cnt_zero
    for j in range(59 - i):
        tmp = (tmp * 2) % mod
    ans += tmp
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n, *a = map( int, open(0).read().split())
div = 10 ** 9 + 7
tmp = 0
for i in range(n):
  for j in range(i+1,n):
    tmp += a[i] ^ a[j]

print( tmp % div )

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
m = 62
d =[0]*m
ans = 0
for i in range(N):
    for j in range(m):
        if A[i]&(1<<j):
            ans += (1<<j)*(i-d[j])%mod
            d[j] += 1
        else:
            ans += (1<<j)*d[j]%mod
    ans %= mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
m = 62
d =[0]*m
ans = 0
for i in range(N):
    for j in range(m):
        if A[i]&(1<<j):
            ans += (1<<j)*(i-d[j])
            d[j] += 1
        else:
            ans += (1<<j)*d[j]
    ans %= mod
print(ans%mod)

Submission status: Time Limit Exceeded

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

maxA_len = len(bin(maxA)[2:])
num0_each_digit = [0 for _ in range(maxA_len)]
num1_each_digit = [0 for _ in range(maxA_len)]

for i in range(N):
    for i_bit, bit in enumerate(bin(A[i])[2:].zfill(maxA_len)):
        if bit == '0':
            num0_each_digit[i_bit] += 1
            num0_each_digit[i_bit] %= MOD
        else:
            num1_each_digit[i_bit] += 1
            num1_each_digit[i_bit] %= MOD
ans = 0
for i in range(maxA_len):
    factor = (2 ** (maxA_len - i - 1)) % MOD
    ans += (num0_each_digit[i] * num1_each_digit[i] * factor) % MOD

print(ans % MOD)

Submission status: Time Limit Exceeded

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

maxA_len = len(bin(maxA)[2:])
num0_each_digit = [0 for _ in range(maxA_len)]
num1_each_digit = [0 for _ in range(maxA_len)]

for i in range(N):
    for i_bit, bit in enumerate(bin(A[i])[2:].zfill(maxA_len)):
        if bit == '0':
            num0_each_digit[i_bit] += 1
            num0_each_digit[i_bit] %= MOD
        else:
            num1_each_digit[i_bit] += 1
            num1_each_digit[i_bit] %= MOD
ans = 0
for i in range(maxA_len):
    ans += (num0_each_digit[i] * num1_each_digit[i] * (2 ** (maxA_len - i - 1))) % MOD

print(ans % MOD)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
maxA = max(A)
maxA_len = len(bin(maxA)[2:])
num0_each_digit = [0 for _ in range(maxA_len)]
num1_each_digit = [0 for _ in range(maxA_len)]

for i in range(N):
    for i_bit, bit in enumerate(bin(A[i])[2:].zfill(maxA_len)):
        if bit == '0':
            num0_each_digit[i_bit] += 1
        else:
            num1_each_digit[i_bit] += 1
ans = 0
for i in range(maxA_len):
    ans += (num0_each_digit[i] * num1_each_digit[i] * (2 ** (maxA_len - i - 1))) % MOD

print(ans % MOD)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())

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


aas = list(itertools.combinations(a,2))
m = len(aas)

x = 0
for i in range(m):
    x += ((aas[i][0] ^ aas[i][1]) % (10**9 + 7))
    x %= 10**9 + 7

print(x)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

MOD = 10**9+7
N = int(input())
A = [bin(int(a))[2:] for a in input().split()]
keta = 0
for a in A:
    keta = max(keta, len(a))
A = [a.zfill(keta) for a in A]
ans = 0
for i in range(keta):
    count = [0, 0]
    for j in range(N):
        if (A[j][i] == '0'):
            count[0] += 1
        else:
            count[1] += 1
    ans += count[0] * count[1] * 2**((keta-1)-i)
    ans %= MOD
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

MOD = 10**9+7
N = int(input())
A = [bin(int(a))[2:].zfill(60) for a in input().split()]
ans = 0
for i in range(60):
    count = [0, 0]
    for j in range(N):
        if (A[j][i] == '0'):
            count[0] += 1
        else:
            count[1] += 1
    ans += count[0] * count[1] * 2**(59-i)
    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-1):

    for j in range(i+1, n):

        sum += a[i] ^ a[j]

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