Problem:


Score : 400 points

Problem Statement

We have N integers. The i-th integer is A_i.

Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

What is \mbox{ XOR }?

The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:

When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.

For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Constraints

2 \leq N \leq 3 \times 10^5

0 \leq A_i < 2^{60}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

Sample Input 1

3
1 2 3

Sample Output 1

6

We have (1\mbox{ XOR } 2)+(1\mbox{ XOR } 3)+(2\mbox{ XOR } 3)=3+2+1=6.

Sample Input 2

10
3 1 4 1 5 9 2 6 5 3

Sample Output 2

237

Sample Input 3

10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820

Sample Output 3

103715602

Print the sum modulo (10^9+7).



Sample input:
3
1 2 3


Sample output:
6

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = []
for x in A:
    tmp_lst = []
    for _ in range(60):
        tmp = x // 2
        tmp_lst.append(x - tmp * 2)
        x = tmp
    B.append(tmp_lst)

ans = 0
for i in range(60):
    tr, fl = 0, 0
    for x in B:
        if x[i]:
            tr += 1
        else:
            fl += 1
    ans += (tr * fl) * 2 ** i
    ans = ans % (10 ** 9 + 7)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


n = 60
N = read_a_int()
A = read_ints()


def ret_binary(a: int):  # 逆順で返すことに注意
    tmp = bin(a)[2:]
    ret_r = [0] * n
    for i, t in enumerate(tmp[::-1]):
        ret_r[i] = int(t)
    return ret_r


def calc_sum(a, n_1_ls, n_1_max):
    '''
    aはxorしてから和を取りたい数
    n_1_lsは各桁の1の数
    n_1_maxは最大1は何個あり得るか
    '''
    a_binary = ret_binary(a)
    ret = 0
    for i, (aa, n_1) in enumerate(zip(a_binary, n_1_ls)):
        if aa == 0:
            ret += ((2**i) * n_1) % MOD
        else:
            ret += ((2**i) * (n_1_max - n_1)) % MOD
    return ret


def add_koko(lsa, lsb):
    return [a + b for a, b in zip(lsa, lsb)]


MOD = 10**9 + 7

n_1_max = 0
n_1_ls = [0] * n
ans = 0
for i in range(N - 2, -1, -1):
    a = A[i]
    a_pre = A[i + 1]
    n_1_ls = add_koko(n_1_ls, ret_binary(a_pre))
    n_1_max += 1
    tmp = calc_sum(a, n_1_ls, n_1_max)
    ans += tmp
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

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

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

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:
import itertools
n = int(input())
a = list(map(int, input().split()))

sums = 0
k = {}
for x in itertools.combinations(a, 2):
    if ((x[0], x[1]) in k.values() or (x[1], x[0]) in k.values()):
        sums += k[x[0], x[1]]
    else:
        r =int(bin(x[0] ^ x[1]), 2)
        k.setdefault((x[0], x[1]), r)
        sums += r

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

lis = [0]*60

for a in input().split():
    a = int(a)
    for i in range(60):
        lis[i] += a % 2
        a = a//2
ans = 0
for i, j in enumerate(lis):
    ans += j * (N-j) *(2**i)
    ans = ans % (10**9 + 7)

print(ans)

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):
    for j in range(i,N):
        ans += int(A[i]^A[j])
print(ans % 1000000007)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

from collections import deque

N = int(input())
A = deque(list(map(int,input().split())))
tmp, ans = 0, 0

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, (input().split())))
result = 0
dic = {}
for i in range(n - 1):
    for j in range(i + 1, n):
        key1 = str(a[i]) + "," + str(a[j])
        key2 = str(a[j]) + "," + str(a[i])
        if (key1 in dic):
            result += int(dic.get(key1))
        elif (key2 in dic):
            result += int(dic.get(key2))
        else:
            temp = a[i] ^ a[j]
            result += temp
            dic[key1] = temp
            dic[key2] = temp

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
bi=[0]*60
for i in range(N):
  a=list(map(int,bin(A[i])[2:].zfill(60)))
  for j in range(60):
    bi[j]+=a[j]
  
bi.reverse()
ans=0
for i in range(60):
  ans=(ans+((2**i)*bi[i]*(N-bi[i]))%mod)%mod
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
P = 10 ** 9 + 7

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

b = [[0 for j in range(60)] for i in range(n)]

str_a = format(a[0], "0b")
l = len(str_a)
for i in range(len(str_a)):
  a_bit = int(str_a[l - 1 - i])
  b[0][i] = a_bit

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

print(ans)

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_0%mod
        tmp = tmp*num_1%mod
        for _ in range(i):
            tmp = tmp*2%mod
        res = (res+tmp)%mod
    print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
MOD = 10 ** 9 + 7
ans = 0
bit_matrix = [[0] * N for _ in range(61)]
for i in range(len(A)):
    n = 0
    while 2 ** n <= A[i]:
        if A[i] >> n & 1:
            bit_matrix[n][i] = 1
        n += 1
#print(bit_matrix)
#bit_matrix_T = []
'''
for j in range(60):
    tmp = []
    for i in range(N):
        tmp.append(bit_matrix[i][j])
    bit_matrix_T.append(tmp)
'''
#print(bit_matrix_T)
for i in range(len(bit_matrix)):
    tmp = Counter(bit_matrix[i])
    a = list(tmp.values())
    if len(a) == 2:
        ans += (2 ** i) * a[0] * a[1]
        ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=input()
A=list(map(int,input().split()))
a=0
i=1
while len(A):
    for m in A[1:]:
        a+=A[0]^m
    A.pop(0)
print(a%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = input()
l = list(map(int,input().split()))
c = itertools.combinations(l,2)

s = 0

for v in c:
    s += (v[0]^v[1])% (10**9+7)
    if(s >= 10**9+7):
        s = s % (10**9+7)

print(s)

Submission status: Time Limit Exceeded

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

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

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

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 = bin(A_i)
        for j in range(len(A_bit)-2):
            if A_bit[len(A_bit)-1-j] == '1':
                count[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())
a = list(map(int, input().split()))

mod = 10 ** 9 + 7

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

print(ans % mod)

Submission status: Time Limit Exceeded

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

B = []
for a in A:
    b = bin(a)
    b = b.lstrip("0b")
    while len(b) < 60:
        b = "0"+b
    B.append(b)
    
ans = 0
pow2 = [1]
for i in range(59):
    pow2.append(pow2[-1]*2)

for i in range(60):
    rui = [0]
    old = 0
    for b in B:
        if b[i] == "1":
            old+=1
            rui.append(old)
        else:
            rui.append(old)
    del rui[0]
    
    N1 = rui[N-1]
    kari = 0
    for j,(b,r) in enumerate(zip(B,rui)):
        if b[i] == "1":
            kari+=(N-j-1)-(N1-r)
        else:
            kari+=(N1-r)
    ans+=kari*pow2[59-i]
    ans%=mod
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
A = list(int(i) for i in input().split())

ans = 0

for v in itertools.combinations(A, 2):
    ans += v[0] ^ v[1]
    
print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
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:
        b = format(a, "065b")[::-1]
        for i in range(65):
            num[i] += int(b[i])

    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:
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:
mod = int(1e9 + 7)
N = int(input())
A = list(map(int, input().split()))
S = 0
j = 0
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) * (2 ** j)
  S %= mod
  j += 1
print(S)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
alist=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+=(alist[i]^alist[j])%MOD
ans=ans%MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def print_ans(N, ar):
    """Test Case
    >>> print_ans(3, [1, 2, 3])
    6
    >>> print_ans(10, [3, 1, 4, 1, 5, 9, 2, 6, 5, 3])
    237
    >>> print_ans(10, [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820])
    103715602
    """
    ans = 0
    for i in range(N -1):
        for k in range(i, N):
            ans += ar[i] ^ ar[k]
    print(ans % (10 ** 9 + 7))

if __name__ == '__main__':
    N = int(input().rstrip())
    ar = list(map(int, input().rstrip().split()))
    print_ans(N, ar)

Submission status: Time Limit Exceeded

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

num_max = len(bin(max(a_list)))-2
bin_list = [['0' for _ in range(num_max-len(bin(a))+2)] + list(bin(a))[2:] for a in a_list]

flag = True
score = 0
count = 0

for i in range(num_max):
    array = []
    for l in bin_list:
        if len(l)-1 >= count:
            array.append(l[count])
    count_0 = array.count('0')
    count_1 = array.count('1')
    score += count_0*count_1*(2**(num_max-i-1))
    score = score % 1000000007
    count += 1

print(score)

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]
print(cnt%M)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

def xor_(x, y):
    p, q = tuple(sorted([x, y]))
    p = np.array(list(bin(p)))
    q = np.array(list(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:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    mLEN = len(format(max(A),'b'))
    bA = [[0]*N for _ in range(mLEN)]

    for i in range(N):
        a = format(A[i],'b').zfill(mLEN)
        for k in range(mLEN):
            bA[k][i] = a[k]

    answer = 0
    for keta in range(mLEN):
        zero = bA[keta].count('0')
        one = N-zero
        a = 0

        for i in range(N):
            if bA[keta][i] == '1':
                one -= 1
            else:
                zero -= 1

            if bA[keta][i] == '1':
                a += zero
            else:
                a += one
        answer += a*pow(2,mLEN-1-keta,MOD)
    
    print(answer%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 = [int(i) for i in input().split()]
divide = 10 ** 9 + 7

inf=float("inf")
dp=[[inf for i in range(n+1)] for j in range(n+1)]

sum = 0
for i in range(n):
    for j in range(i+1, n):
        if dp[i][j] != inf or dp[j][i] != inf:
            sum += dp[i][j]
            print('yes')
        else:
            val =  a_list[i] ^ a_list[j]
            dp[i][j] = val
            dp[j][i] = val
            sum += val

print(sum % divide)

Submission status: Time Limit Exceeded

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

SUM = list()
for i in range (n - 1):
  for j in range (i+1, n):
    SUM.append(int(bin(a[i] ^ a[j]), 2))
print(sum(SUM) % (10**9 + 7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def sumXOR(arr, n):       
    MOD = 10 ** 9 + 7
    sum = 0
    for i in range(0, 61): 
        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

n = int(input())
A = list(map(int, input().split()))
sum = 0
sum = sumXOR(A, n); 
print(sum)

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

def xor(n):
    return n[0] ^ n[1]

import itertools
L = list(itertools.combinations(A, 2))
for i in L:
    S += xor(i)
      
print(S % MOD)

Submission status: Time Limit Exceeded

Solution code:
#problem4
N = int(input())
numbers = list(map(int, input().split()))

sum=0
for i in range(1,N):
    for j in range(i+1,N+1):
        s=numbers[i-1]^numbers[j-1]
        sum=sum+s

ans = sum%(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( )))
ans = 0
mod = 10**9+7
Bit = [[0]*2 for j in range(60)]# for i in range(n+1)

for i in range(1,n):##1から
    for j in range(60):
        if not ((a[i-1]>>j)&1):#a[i-1]のjビット目0
            Bit[j][0] += 1
        else:#ｊビット目1
            Bit[j][1] += 1
        if ((a[i]>>j)&1):#aiのjビット目1
            ans += Bit[j][0]<<j
            ans %=mod
        else:
            ans += Bit[j][1]<<j
            ans %= mod
    #print(Bit[:6])
"""
for i in range(1,n):##1から
    for j in range(60):

    #ans += a[i]
    #ans %=mod
    #自身の分
        #print(ans)
"""
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
an=list(map(int, input().split()))
sum = 0

from itertools import combinations
for item in list(combinations(an, 2)):
    sum += item[0] ^ item[1]

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

Submission status: Time Limit Exceeded

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

l = (10 ** 9) + 7

res = 0
res = [ [A[i], A[j] ] for i in range(0,N-1) for j in range(i, N)]
a = list(map(lambda x: x[0] ^ x[1] , res))


print(sum(a) % l)

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-1):
    for j in range(i+1,n):
        x=format(a[j],"b")
        y=format(a[i],"b")
        length=len(y)
        anss=x[:len(x)-length]
        for k in range(length):
            if x[-length+k]==y[k]:
                anss+="0"
            else:
                anss+="1" 
        ans+=(int(anss,2)%(10**9+7)) 
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = tuple(map(int,input().split()))
b = 0
c = N-1
num = 1000000007
for i in range(c):
    for j in range(i+1,N):
        b += A[i] ^ A[j]
print(b%num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(input().split())
output = 0
for i in range(N):
  A =int(A_list[i])
  for j in range(i+1,N):
    B = int(A_list[j])
    output += int(bin(A^B),2)
output %= 1000000000+7
print(output)

Submission status: Time Limit Exceeded

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


def main():
    sum_ = 0
    A = list(map(int, input().split()))
    for i in range(len(A)-1):
        for j in range(i+1, len(A)):
            sum_ += A[i] ^ A[j]
    print(sum_ % MOD)


if __name__ == "__main__":
    main()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import time

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

#出力
#print(N)
#print(A)
#print(' ')
#print(sum)

Submission status: Time Limit Exceeded

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

def func(x, nn):
    value = 0
    for i in range(nn - 1):
        for j in range(i + 1, nn):
            value += x[i] ^ x[j]
    ans = value % (10 ** 9 + 7)
    return ans

def main():
    n = int(input())
    li = tuple(map(int, input().split()))
    print(func(li, n))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
 
def jouyo(X):
    return X%1000000007
 
MAX=A[0]
for i in range(N):
    if MAX<=A[i]:
        MAX = A[i]
    else:
        MAX = MAX
 
p = 1
M = 1
for i in range(60):
    if 2*p <= MAX:
        p = 2*p
        M = M+1
    else:
        break
 
List = []        
for i in range(1,M+1):
    count = 0
    for j in range(N):
        if A[j]%(2**i) >= 2**(i-1):
            count = count +1
        else:
            count = count
    List.append(count)
    
ans = 0   
for i in range(M):
    ans = jouyo(ans) + jouyo(jouyo((2**i))*jouyo(List[i])*jouyo((N-List[i])))
    
print(jouyo(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


n = 60
N = read_a_int()
A = read_ints()


def ret_binary(a: int):  # 逆順で返すことに注意
    tmp = bin(a)[2:]
    ret_r = [0] * n
    for i, t in enumerate(tmp[::-1]):
        ret_r[i] = int(t)
    return ret_r


def calc_sum(a, n_1_ls, n_1_max):
    '''
    aはxorしてから和を取りたい数
    n_1_lsは各桁の1の数
    n_1_maxは最大1は何個あり得るか
    '''
    a_binary = ret_binary(a)
    ret = 0
    for i, (aa, n_1) in enumerate(zip(a_binary, n_1_ls)):
        if aa == 0:
            ret += (2**i) * n_1
        else:
            ret += (2**i) * (n_1_max - n_1)
    return ret


def add_koko(lsa, lsb):
    return [a + b for a, b in zip(lsa, lsb)]


MOD = 10**9 + 7

n_1_max = 0
n_1_ls = [0] * n
ans = 0
for i in range(N - 2, -1, -1):
    a = A[i]
    a_pre = A[i + 1]
    n_1_ls = add_koko(n_1_ls, ret_binary(a_pre))
    n_1_max += 1
    tmp = calc_sum(a, n_1_ls, n_1_max)
    ans += tmp
    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
from itertools import combinations
base = list(combinations(A,2))
for i in range(len(base)):
  ans+=base[i][0]^base[i][1]
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
div = 10**9 + 7
ans = 0

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

memo = {}

for i in range(N):
    for j in range(i+1,N):
        #print(str(i) + " : " + str(j))
        if (A[i],A[j]) in memo:
            ans += memo[A[i],A[j]]

        else:
            a = A[i]^A[j]
            memo[A[i],A[j]] = a
            ans+= a

#print(ans)
print(ans%div)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

b_pairs = []
for i in range(2, n+1):
    b_pairs += list(itertools.combinations(b, i))
    # 単に b_pairs += itertools.combinations(b, i) でも可

lis = []
for i in range(len(b_pairs)):
    if len(b_pairs[i]) == 2:
        lis.append(b_pairs[i])

z = []
for i in lis:
    x1, x2 = i[0], i[1]
    x = x1 ^ x2
    z.append(x)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = [0 for _ in range(len(bin(max(a))) - 2)]
len_c = len(c)
ans = 0
mod = 10**9 + 7
for i in range(n):
  b = bin(a[i])[2:]
  binlist = list('0' * (len_c - len(b)) + b)
  for j in range(len_c):
    power = 2**(len_c-j-1)
    if binlist[j] == '0':
      ans += c[j] * power
    else:
      ans += (i - c[j]) * power
      c[j] += 1
  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(len(A)-1):
    for j in range(i+1, len(A)):
        ans += (A[i] ^ A[j])


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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A_list = [[int(i) for i in bin(int(A))[2:].zfill(61)] for A in input().split()]
ans = 0

for i in range(61):
  one = sum([A_list[j][i] for j in range(n)])
  ans += 2**(60-i) * one * (n-one)
  ans %= 10**9+7

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
mod = int(1e9 + 7)
N = int(input())
A = list(map(int, input().split()))
S = 0
j = 0
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) * (2 ** j)) % mod)
  j += 1
S %= mod
print(S)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
n = 0
n = sum([sum([L[i] ^ L[j] for j in range(i,N)]) for i in range(0,N-1)])

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = list(map(int, input().split()))
AList = [bin(i) for i in A]
AList = [int(i, 2) for i in AList]
count = 0
for i in range(0, N):
    for q in range(i, N):
        count += int(bin(AList[i] ^ AList[q]), 2)
print(count % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
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:
        b = format(a, "065b")[::-1]
        for i in range(65):
            num[i] += int(b[i])

    res = 0
    for i in range(65):
        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:
n = int(input())
a = list(map(int, input().split( )))
ans = 0
mod = 10**9+7
Bit = [[0]*2 for j in range(60)]# for i in range(n+1)

for i in range(1,n):##1から
    for j in range(60):
        if not ((a[i-1]>>j)&1):#a[i-1]のjビット目0
            Bit[j][0] += 1
        else:#ｊビット目1
            Bit[j][1] += 1
        if ((a[i]>>j)&1):#aiのjビット目1
            ans += Bit[j][0]<<j
            ans %=mod
        else:
            ans += Bit[j][1]<<j
            ans %= mod
    #print(Bit[:6])
"""
for i in range(1,n):##1から
    for j in range(60):

    #ans += a[i]
    #ans %=mod
    #自身の分
        #print(ans)
"""
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = []
ans = 0
for i in A:
    B.append(list(bin(i)[2:]))
for i in range (len(B)):
    for l in range(len(B[i])):
        B[i][l] = int(B[i][l])
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:
n =int(input())
a_list = list(map(int,input().split()))
x = 0
for i in range(1, n):
    for j in range(i+1, n+1):
        x += (a_list[i-1] ^ a_list[j-1])
print(x % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
MOD = 10 ** 9 + 7
ans = 0
bit_matrix = [[0] * 60 for _ in range(N)]
for i in range(len(A)):
    n = 0
    while 2 ** n <= A[i]:
        if A[i] >> n & 1:
            bit_matrix[i][n] = 1
        n += 1
#print(bit_matrix)
bit_matrix_T = []
for j in range(60):
    tmp = []
    for i in range(N):
        tmp.append(bit_matrix[i][j])
    bit_matrix_T.append(tmp)
#print(bit_matrix_T)
for i in range(len(bit_matrix_T)):
    tmp = Counter(bit_matrix_T[i])
    a = list(tmp.values())
    if len(a) == 2:
        ans += (2 ** i) * a[0] * a[1]
        ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

l=10**9+7
numlist=[format(int(i),"060b") for i in input().split(" ")]
# print(numlist)


def xor(a,b):
    c=[]
    for i in range(60):
        if a[i]!=b[i]:
            c.append("1")
        else:
            c.append("0")
    return int("".join(c),2)
        

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        ans+=xor(numlist[i],numlist[j])
    ans=ans%l
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def xor(l1=[]):
  
  s2=0
  n=len(l1)

  mod=1e9+7
  for i in range(64):
    s1=0
    one=0
    zero=0
    for j in range(n):
      if l1[j]%2==0:
        zero+=1
      else:
        one+=1
      
      l1[j]=l1[j]//2

    #print(one)
    #print(zero)
    #print(2**i)
    s1=one*zero*(2**i)
    #print(s1)
    s2=(s2%mod+s1%mod)%mod
  return s2%mod

n = int(input())
arr = input()   
l = list(map(int,arr.split(' ')))
val=xor(l)
print(int(val))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
numbers = list(map(int,input().split(" ")))

conv = itertools.combinations(numbers, r=2)

print(sum([j[0]^j[1] for j in conv])%(10**9+7))