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()))
ans = 0
mod = 10**9+7
b = [0]*60
for i in range(N):
    for j in range(1,61):
        if len(bin(A[i])) -1  <= j:
            break
        else:
            b[-j] += int(bin(A[i])[-j])
for i in range(1,61):
    ans += (b[-i] * (N - b[-i])*(2**(i-1)))%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
P = 10 ** 9 + 7
 
n = int(input())
a = list(map(int, input().split()))
a.sort()
str_a = [format(a[i], "0b") for i in range(n)]

b = [[0 for j in range(60)] for i in range(n)]
 
for i in range(len(str_a[0])):
  a_bit = int(str_a[0][-(i + 1)])
  b[0][i] = a_bit
 
for i in range(1, n):
  for j in range(len(str_a[i])):
    a_bit = int(str_a[i][-(j + 1)])
    b[i][j] = b[i - 1][j] + a_bit
    
ans = 0
for i in range(1, n):
  for j in range(len(str_a[i])):
    if str_a[i][-(j + 1)] == "0":
      ans = (ans + b[i - 1][j] * (2 ** j)) % P
    else:
      ans = (ans + (i - b[i - 1][j]) * (2 ** j)) % P
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
p = 10 ** 9 + 7

def comb(n):
  if n < 2:
    return(0)
  else:
    return(int(n * (n-1) / 2))

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

a = [int(i) for i in a]

r = 0

for j in range(60):
  b = [k>>j & 1 for k in a] # 各ビットを取り出す
  n_one = sum(b)
  n_zero = n - n_one
  r_tmp = comb(n) - (comb(n_zero) + comb(n_one))
  r_tmp = r_tmp << j
  r = (r + r_tmp) % p
  
print(r)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [[] for i in range(60)]
As = list(map(int, input().split()))
mod = 1000000007
ans = 0
for i in range(N):
    tmp = format(As[i], 'b').zfill(60)
    for j in range(60):
        L[j].append(int(tmp[j]))


def calc(acc, i):
    if i == 0:
        return acc
    else:
        return calc(acc*2 % mod, i-1)


for i in range(60):
    tmp = calc(1, 59 - i)
    a = sum(L[i]) % mod
    b = (N - a) % mod
    ans += (tmp * a * b) % mod
ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

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


def solve(n, arr):
    sum = 0
    bitcount = [0]*100
    for num in arr:
        b = reversed(bin(num)[2:])
        for i, s in enumerate(b):
            if i != "0":
                bitcount[i] += int(s)
    for i, b in enumerate(bitcount):
        sum += b * (n-b) * 2**i
    return sum % (10**9 + 7)


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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
B = []
ans = 0
for i in A:
    B.append(list(bin(i)[2:]))
C = [0 for i in range(60)]
for i in B:
    for l in range(len(i)):
        if i[-(l+1)] == '1':
            C[l] += 1
for i in range(60):
    ans = (ans + C[i]*(N-C[i])*(2**i))%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

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

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

INF = 10**9 + 7

res = 0

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**7)
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())

def main():
    n = II()
    a_s = LI()
    kaizyo = [1]
    kaizyo_append = kaizyo.append
    keta = [0 for i in range(60)]
    ans = 0
    for i in range(60):
        kaizyo_append(kaizyo[i] * 2 % MOD)
    for i in a_s:
        for i, v in enumerate(format(i, 'b')[::-1]):
            keta[i] += int(v)
    for i, v in enumerate(keta):
        c = v * (n-v) % MOD
        ans = (ans + c * kaizyo[i]) % MOD

    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#O(nm) = O(60n)で解けるはず・・・！
n = int(input())
*l, = map(int,input().split())
#2進数の桁の出現数をカウントする。
lone = [0]*60
for i in range(n):
  s = bin(l[i])[2:]
  for j in range(len(s)):
    lone[j] += int(s[-j-1])
ans = 0
for i in range(60):
  ans += (2**i*lone[i]*(n-lone[i]))%(10**9+7)
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
# D - Xor Sum 4
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 += int(A[i]^A[j])
print(ans % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
A=list(map(int,input().split()))
S=0
mod=10**9+7
for v in itertools.combinations(A,2):
    S+=v[0]^v[1]
print(S%mod)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

mod = 10**9+7
ans = 0

b_pairs = list(itertools.combinations(a_li,2))

for i,j in b_pairs:
    ans += i^j

ans = ans%mod

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0
for i in range(N):
  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 numpy as np

n=int(input())

a=[]

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

ans=0
anssub=0
tmpsum=0
a=np.sort(a)
for i in range(n-1):
    if a[i]!=a[i-1]:
        for k in range(i+1,n):
            tmp=a[i]^a[k]
            tmpsum=tmp+tmpsum
            #print(a[i])
            #print(a[k])
            #print('\0')
            ans=(ans+tmp)%1000000007

    else:
        ans=(ans+tmpsum)%1000000007
    if a[i]!=a[i+1]:
        tmpsum=0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N =int(input())
A = list(map(int, input().split()))
ans = 0
mod = 10**9+7
b = [0]*60
for i in range(N):
    for j in range(1,61):
        if len(bin(A[i])) -1  <= j:
            break
        else:
            b[-j] += int(bin(A[i])[-j])
for i in range(1,61):
    ans += (b[-i] * (N - b[-i])*(2**(i-1)))
print(ans%mod)

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(n):
  for j in range(i, n):
    sum += arr[i] ^ arr[j]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n =int(input())
a_list = list(map(int,input().split()))
x = 0
for i in range(1, n):
    ai = a_list[i-1]
    for j in range(i+1, n+1):
        aj = a_list[j-1]
        x += ai ^ aj


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

Submission status: Time Limit Exceeded

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

mod = 10**9 + 7

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

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007

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

digits = [0] * 60
for i in A:
    for j in range(60):
        if i>>j&1 == 1:
            digits[j] += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ai = list(map(int, input().split()))
ans = 0

for i in range(n-1):
  for j in range(i+1, n):
    ans += ai[i] ^ ai[j]
  ans = ans % (pow(10,9)+7)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n = int(input())
a = list(map(int, input().split()))
a.reverse()
mod = 7 + 10**9
leng = 61
data = [[0 for i in range(leng+1)]for j in range(n)]
#pre
for i in range(n):
    k = deque(bin(a[i]))
    k.reverse()
    k = list(k)
    for j in range(1, leng+1):
        if j - 1 >= len(k):
            data[i][j] = data[i - 1][j]
            continue
        if k[j - 1] == "1":
            data[i][j] = data[i - 1][j] + 1
        else:
            data[i][j] = data[i-1][j]
ans = 0
a.reverse()
data.reverse()
for i in range(n-1):
    k = deque(bin(a[i]))
    k.reverse()
    k.pop()
    k.pop()
    k = list(map(int, k))
    k = k + [0 for i in range(leng - len(k))]
    for j in range(leng):
        if k[j] == 1:
            ans += ((n - i - 1) - data[i+1][j+1]) * (2**j)
            ans %= mod
        else:
            ans += data[i+1][j+1] * (2**j)
            ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools


def xORSum(arr, n):
    ans = 0
    for i in range(0, n):
        for j in range(i + 1, n):
            ans = ans + (arr[i] ^ arr[j])
    return ans


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

print(xORSum(a, n) % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

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

p=1000000000+7
result=0
for i in range(N-1):
    for j in range(i+1, N):
        result=(result+(array[i] ^ array[j]))%p

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def add(a,b):
  return (a ^ b) % 1000000007

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

###
ans2 = [add(A[y],A[x]) for y in range(N) for x in range(y+1,N)]
print(sum(ans2)%1000000007)
###

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b=[]
b=list(map(int,input().split()))
sum1=0
num = []
for i in range(a-1):
  for j in range(i+1,a):
    num.append(b[i]^b[j])
sum1=sum(num)
 
if sum1>=1000000007:
  sum1=sum1%1000000007
print(sum1)

Submission status: Time Limit Exceeded

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

d = [0]*60
for ai in aa:
  for e,i in enumerate(bin(ai)[:1:-1]):
    d[e]+=int(i) 

ans = 0
for i in range(len(d)):
  if d[i]==0 or d[i]==n:
    pass
  else:     
    #print(d[i]*(n-d[i])* 2**(i))    
    ans += d[i]*(n-d[i])* 2**(i)
    ans %= (10**9+7)
    
print(ans)

Submission status: Time Limit Exceeded

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

mod = 10 ** 9 + 7

pows = [1] * 66
for i in range(65):
    pows[i + 1] = (pows[i] * 2) % mod


def read_valus():
    return map(int, input().split())


def read_list():
    return list(read_valus())


def read_lists(N):
    return [read_list() for n in range(N)]


def p(N, a):
    return (a * (N - a)) % mod


def main():
    N = int(input())
    A = read_list()

    num = [0] * 65
    for a in A:
        tmp = a
        for i in range(65):
            if tmp == 0:
                break
            num[i] += tmp % 2
            tmp //= 2

    res = 0
    for i in range(65):
        if num[i] == 0:
            continue

        res = (res + (pows[i] * p(N, num[i])) % mod) % mod

    print(res % mod)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from itertools import permutations
from itertools import combinations

#input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7

A.sort()
sumv = 0
for i, vi in enumerate(A):
    for vj in A[i+1:]:
        sumv += vi^vj
        sumv %= mod
print(sumv)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
A = [int(i) for i in input().split()]
maxA = max(A)
if maxA == 0:
    print(0)
else:   
    digs = int(math.log(maxA, 2)+1)
    count = [0] * digs
    
    for A_i in A:
        A_bit = format(A_i,'b')
        j=0
        for elem in A_bit:
            count[len(A_bit)-j-1] += int(elem)
            j+=1
    total = 0
    for i in range(digs):
        total += ((2**i  % 1000000007) * count[i] * (N - count[i])) % 1000000007
        
    print(total % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

count = 0
for i in range(0, N):
    for q in range(i, N):
        count += int(AList[i] ^ AList[q])
print(count % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    ans=0
    for i in range(N-1):
        for j in range(i+1,N):
            a= (A[i]^A[j])%MOD
            #print(i,j,a)
            ans+=a
    print(ans%MOD)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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 = [int(x) for x in input().split()]

a_b = []
for i in A:
    this_b = []
    this_a = i
    for j in range(59,-1,-1):
        if this_a >= 2**j:
            this_b.append(1)
            this_a -= 2**j
        else:
            this_b.append(0)
    a_b.append(this_b)
    
#print(a_b)

count_a_b = []
for i in range(60):
    count_a_b.append(0)

    
for i in a_b:
    for j in range(len(i)):
        count_a_b[j] += i[j]
#print(count_a_b)

count = 0
for i in range(len(count_a_b)):
    count += (count_a_b[i] * (N-count_a_b[i])) *2**(59-i)
    
print(count%(10**9+7))

Submission status: Time Limit Exceeded

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

total = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        total += A[i] ^ A[j]
        # print("A[i] ^ A[j]: ", A[i] ^ A[j])
        # print("total: ", total)

# print(total)
# print(total % 100000007)

canContinue = True
if total - 999999999 - 8 < 0:
    canContinue = False
while canContinue:
    total = total - 999999999 - 8
    if total - 999999999 - 8 < 0:
        canContinue = False
print(total)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python

import sys
from pprint import pprint

def pow_r(x, n):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2) % (10**9 + 7)
    else:
        return x * pow_r(x ** 2, (n - 1) // 2) % (10**9 + 7)


def solve(n, a):

    zero_count = [0] * 60
    for a_i in a:
        binary = format(a_i, '060b')

        for j, b_j in enumerate(binary):
            zero_count[j] += int(b_j)

    ans = 0
    for i, count in enumerate(zero_count[::-1]):
        # ans += (2**i) * (count * (n - count)) 
        ans += pow(2, i) * (count * (n - count)) 
        ans %= 10**9 + 7
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np
N = int(input())
w = [int(x) for x in input().split()]
x = [balls for balls in itertools.combinations(w, 2)] 
def XOR(x):
    return x[0] ^ x[1]
count = list(map(XOR, x))
result = sum(count) % (10**9+7)
print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
cs = [[0] * 60 for _ in range(N + 1)]
mod = 10 ** 9 + 7
for i in range(N):
  for j in range(60):
    t = 1 << j
    #print(a[i], t, a[i] & t)
    x = (a[i] & t) > 0
    cs[i + 1][j] = (cs[i][j] + x) % mod
res = 0
#print(cs[-1])
#print(cs[2])
for i in range(N):
  t = 0
  for j in range(60):
    x = 1 << j
    if a[i] & x != 0:
      #if i == 1: print((1 << j) * (N - i - 1), (cs[-1][j] - cs[i + 1][j]))
      t += x * ((N - i - 1) - (cs[-1][j] - cs[i + 1][j]))
    else:
      #if i == 1: print(a[i] & (1 << j), (cs[-1][j] - cs[i + 1][j]))
      t += x * (cs[-1][j] - cs[i + 1][j])
    #print(t)
    t %= mod
  res += t
  res %= mod
print(res % mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a=list(map(int,input().split()))
sum1 = 0
length = len(a)-1
for i in range(length):
    p = a.pop(0)
    b=list(map(lambda x:x^p,a))
    sum1 += sum(b)
print(sum1%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys
inputs = sys.stdin.readlines()
n = int(inputs[0])
A = sorted(list(map(int, inputs[1].split())))
MOD = 10 ** 9 + 7

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

Submission status: Time Limit Exceeded

Solution code:
lim=10**9+7
H=int(input())
A=[int(i) for i in input().split()]

#M=[[0]*H for _ in range(H)]
#K=[[0]*H for _ in range(H)]
for N in range(0,H+1):
    sum_=0
    sum2=0
    for i in range(N):
        for j in range(i+1,N):
            #M[i][j]=A[i]^A[j]
            #K[i][j]=A[i]+A[j]
            sum_ = (sum_+(A[i]^A[j])) % lim
            #sum2 = (sum2+(A[i]+A[j])) 
print(sum_)
#print(sum2)
#print(sum2-sum_)
#print("###")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
sum = 0
for i in range(0,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:
from collections import Counter
from itertools import combinations

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

print(sum((a ^ b) * A[a] * A[b] for a, b in combinations(A, 2)) % (10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
list_A = []
num_A = []
list_A.append(A[0])
j = 1
cnt = 1
while(j<=N-1):
    if A[j-1]==A[j]:
        cnt += 1
        if j == N-1:
            num_A.append(cnt)
    else:
        list_A.append(A[j])
        num_A.append(cnt)
        cnt = 1
        if j == N-1:
            num_A.append(cnt)
    j += 1
len_A = len(list_A)
j = 0
k = 1
xor = 0
while(j<=len_A-2):
    xor += (list_A[j]^list_A[k])*(num_A[j]*num_A[k])
    k += 1
    if k == len_A:
        j += 1
        k = j+1
print(xor%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
MOD = 1000000007
nums = list(map(int, input().split(' ')))

ret = 0
combi = itertools.combinations(nums, 2)
for x, y in combi:
  ret = (ret + (x ^ y))% MOD
print(ret)

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]
print(count % ((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
from scipy.misc import comb
import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input())
lis = list(map(int, input().split()))
ans = 0
x = comb(n, 2, exact=True)
for i in range(60):
    temp = 0
    for j in range(n):
        if format(lis[j],'060b')[i] == "1":
            temp += 1
    ans += 2**(59-i)*(x - comb(n-temp, 2, exact=True)-comb(temp, 2, exact=True))
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

p = 10 ** 9 + 7

def comb(n):
  if n < 2:
    return(0)
  else:
    a = n % p
    b = (n-1) % p
    c = int((a * b / 2)) % p
    return(c)

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

a = [int(i) for i in a]

#bmax = math.ceil(math.log2(max(a)))

r = 0

for j in range(60):
  b = [k>>j & 1 for k in a] # 各ビットを取り出す
  n_one = sum(b)
  n_zero = n - n_one
  r_tmp = comb(n) - (comb(n_zero) + comb(n_one))
  r_tmp = r_tmp << j
  #b_tmp = (2 ** j) % p
  r = (r + r_tmp) % p
  
print(r)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = list(input().split())
d_to_num1 = {}
max_len = 0
for i in range(N):
    a = list(bin(int(A[i]))[2:])
    if max_len <= len(a):
        max_len = len(a)
    for j,b in enumerate(reversed(a)):
        if b=='1':
            if not(j in d_to_num1.keys()):
                d_to_num1[j]=1
            else:
                d_to_num1[j]+=1 
        
if __name__ == "__main__":

    res = 0
    mod = 10**9+7

    for i in range(max_len):
        if not(i in d_to_num1.keys()):
            num_1 = 0
        else:
            num_1 = d_to_num1[i]
        num_0 = N-num_1
        tmp = 1
        tmp = tmp*num_1*(N-num_1)%mod
        tmp %= mod
        for _ in range(i):
            tmp = (tmp*2)%mod
        res += tmp%mod
        res %= mod
    print(res)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    b = l[int(i)] ^ l[int(j)]
    ans = ans  +b
    
  

print(ans% 1000000007)

Submission status: Time Limit Exceeded

Solution code:
#O(nm) = O(60n)で解けるはず・・・！
n = int(input())
*l, = map(int,input().split())
#2進数の桁の出現数をカウントする。
lone = [0]*60
for i in range(n):
#  m = l[i]
  s = bin(l[i])[2:]
  for j in range(len(s)):
    lone[j] += int(s[-j-1])
#  for j in range(59,-1,-1):
#    if m >= 2**j:
#      m -= 2**j
#      lone[j] += 1

ans = 0
for i in range(60):
  ans += 2**i*lone[i]*(n-lone[i])
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
def xor_(x, y):
    p, q = list(sorted([x, y]))
    p = bin(p)
    q = bin(q)
 
    i = -1
    r = str()
    while p[i] != 'b':
        if p[i] == q[i]:
            r = '0' + r
        else:
            r = '1' + r
        i -= 1
 
    while q[i] != 'b':
        r = q[i] + r
        i -= 1
    
    r = '0b' + r
 
    return(int(r, 0))
 
sum = 0
for i in range(n-1):
    for j in range(i+1, n):
        sum += xor_(a[i], a[j])
        sum = sum % (10**9 + 7)
 
print(sum)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(len(A)):
    for j in range(i):
        cnt += A[i] ^ A[j]
        cnt %=  M
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

X=[]

for i in range(N-1):
    for j in range(N):
        if (j > i):
            X.append(nums[i]^nums[j])

s = sum(X)
    
print(str(s % (10**9 + 7)))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
MOD = 1000000007

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

digits = [0] * 60
for i in A:
    for j in range(60):
        if i>>j&1 == 1:
            digits[j] += 1

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

print(ans)

Submission status: Time Limit Exceeded

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

mod = 10 ** 9 + 7


def read_valus():
    return map(int, input().split())


def read_list():
    return list(read_valus())


def read_lists(N):
    return [read_list() for n in range(N)]


def p(N, a):
    return (a * (N - a)) % mod


def main():
    N = int(input())
    A = read_list()

    num = [0] * 65
    for a in A:
        tmp = a
        for i in range(65):
            if tmp == 0:
                break
            num[i] += tmp % 2
            tmp //= 2

    res = 0
    for i in range(65):
        if num[i] == 0:
            continue

        res = (res + (pow(2, i, mod) * p(N, num[i])) % mod) % mod

    print(res % mod)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
from sys import stdin


def main():
    # コンソール入力を受け取る
    N = int(stdin.readline().rstrip())
    l = stdin.readline().rstrip().split()

    sum = 0
    for i in range(len(l) - 1):
        for j in range(i+1, len(l)):
            tmp = (int(l[i]) ^ int(l[j]))
            sum += tmp
    print(sum % (10 ** 9 + 7))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
F = 10**9+7
n = int(input())
s = sys.stdin.readline().split()
ans = 0
for i in range(n-1):
  for j in range(n-1-i):
    ans+=(int(s[i])^int(s[i+j+1]))
    
print(ans%F)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
S = 0
MOD = 1000000007

for i in range(N - 1):
    for j in range(i + 1, N):
        S += A[i] ^ A[j]
        S = S % MOD

print(S)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums =["INF"] + list(map(int,input().split()))

counter = 0

sigma1 = [x for x in range(1,n)]

for s1 in sigma1:
  counter  += sum([nums[s1]^nums[x] for x in range(s1 + 1,n+1)])
  
  #for s2 in sigma2:
  #  counter += nums[s1] ^ nums[s2]



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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
t = 0
u = 0
m = max(A)
for i in range(60):
    if m >= 2**i:
        u += 1
    else: break
for i in range(u):
    for j in range(N):
        if A[j]%(2**(i+1)) >= 2 ** i:
            t += 1
    ans += (t * (N-t)) * 2**i
    t = 0
print(ans%1000000007)

Submission status: Time Limit Exceeded

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

d = [0]*60
for ai in aa:
  for e,i in enumerate(bin(ai)[:1:-1]):
    d[e]+=int(i)  

ans = 0
for i in range(len(d)):
  if d[i]==0 or d[i]==n:
    pass
  else:     
    #print(d[i]*(n-d[i])* 2**(i))
    ans += d[i]*(n-d[i])* 2**(i)
    
print(ans % (10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def XOR(a,b):
    s=0
    n=0
    while max(a,b)>=2**n:
        n+=1

    for i in reversed(range(0,n+1)):
        if a//(2**i)==0:
            if b//(2**i)==1:
                s+=2**i
                b-=2**i
        else:
            a-=2**i
            if b//(2**i)==1:
                b-=2**i
            else:
                s+=2**i
    return s

N=int(input())
A=[0]
B=[0]

A=(input().split())
sum=0


for y in range(N):
    B.append(int(A[y]))

for i in range(1,N):
    for j in range(i+1,N+1):
        sum+=XOR(B[i], B[j])

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

print(ans)

Submission status: Time Limit Exceeded

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

z=0
m=10**9+7

for i in range(0,N-1):
  for j in range(i+1,N):
#    print(i,j)
#    print(a[i],a[j])
    z+=int(a[i])^int(a[j])
print(z%m)

Submission status: Time Limit Exceeded

Solution code:
def main():
    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]
    print(ans % MOD)


main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7


def main():
    _ = INT()
    A = LIST()

    cnt = 0
    for i, j in list(combinations(A, 2)):
        tmp = int(bin(i ^ j), 2)
        cnt = (cnt + tmp) % mod

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input().strip())
A = list(map(int, input().strip().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))