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:
import numpy as np
n = int(input())
arr = list(map(int,input().split()))
buf = [0 for i in range(61)]

count = [[0,0] for i in range(61)]

for a in arr:
    txt = str(bin(a))[2:].zfill(61)

    for i in range(len(txt)):
        if txt[i] == "0":
            buf[i] += count[i][1]
            count[i][0] += 1
        else:
            buf[i] += count[i][0]
            count[i][1] += 1

m = 10**9 +7

buf.reverse()
ans = 0

for i in range(len(buf)):
    num = buf[i]
    base = np.power(2,i)
    base = base%m
    base = (base*num)%m

    ans += base
    ans = ans%m

# print(buf)
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(1, N):
    for j in range(i + 1, N + 1):
        ans += (a[i - 1] ^ a[j - 1])

print(ans % K)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

res = 0

for i in range(n):
  for j in range(i, n):
    res += a[i] ^ a[j]
print(res % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python

from pprint import pprint
import sys
 
n = int(sys.stdin.readline().strip())
a = map(int, sys.stdin.readline().strip().split(" "))

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

# pprint(zero_count)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def xor(a, b):
    a_ = format(a, 'b')
    b_ = format(b, 'b')
    l = max(len(a_), len(b_))
    a_ = '0'*(l-len(a_)) + a_
    b_ = '0'*(l-len(b_)) + b_
    result = ''
    for x, y in zip(a_, b_):
        if x == y:
            result += '0'
        else:
            result += '1'
    return int(result, 2)

total = 0
N = int(input())
nums = list(map(int, input().split()))
for i in range(len(nums)):
    for j in range(i+1, len(nums)):
        total += xor(nums[i], nums[j])
        
print(total % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:


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

ans = 0
mod = 10**9 + 7


b = bin(max(A))

l = len(b) - 2


for j in range(l):
    tmp = 0
    for i in range(N):
        if (A[i] >> j) % 2 == 1:
            tmp += 1

    ans += (2**j) * tmp * (N-tmp)
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
n = onem()

a = l()

dp = [[0 for i in range(60)] for j in range(n+1)]

co = 0

for i in range(1,n+1):
    kkk = a[i-1]
    for j in range(60):
        if j != 0:
            kkk = kkk >> 1
        if kkk & 1:
            dp[i][j] = dp[i-1][j] + 1
        else:
            dp[i][j] = dp[i-1][j]

two = [1]

for i in range(60):
    two.append(two[-1]*2 % mod)

for i in range(1,n):
    for j in range(60):
        if dp[i][j] == dp[i-1][j]:
            ans = two[j]*(dp[-1][j]-dp[i][j])
            ans %= mod
            co += ans
            co %= mod
        else:
            ans = two[j]*(n-(i-1) - (dp[-1][j] - dp[i-1][j]))
            ans %= mod
            co += ans
            co %= mod

print(co)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

# A[i] = 2^60 * a60 + ... + 2^0*a0
# A[i] XOR A[j]
# a60==1 -> P
# a60 == 0 -> Q
# 2^60 * (P * Q)

P = [0 for _ in range(0, 61)]

for a in A:
    ba = bin(a)
    ba = ba[2:][::-1]
    for i in range(0, 61):
        if i < len(ba):
            if ba[i] == '1':
                P[i] += 1

mod = int(1e9) + 7
total = 0
base = 1

for i in range(0, 61):
    total += ((P[i] * (N - P[i]) * base) % mod)
    total %= mod
    base = base * 2
    base %= mod

print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Ns = list(map(int, input().strip().split(' ')))

total = 0

for i in range(N - 1):
	for j in range(i + 1, N):
		total += (Ns[i]) ^ (Ns[j])

total %= 1000000007
		
print(total)

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:
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n):
    for j in range(i,n):
        if i == j:
            continue
        ans+=l[i]^l[j]
print(ans%(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]"):
    bA = [[0]*N for _ in range(60)]

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

    ruiseki = [[()]*N for _ in range(60)]
    for keta in range(60):
        zero = bA[keta].count('0')
        one = bA[keta].count('1')

        for i in range(0,N):
            if bA[keta][i] == '1':
                one -= 1
            else:
                zero -= 1
            ruiseki[keta][i] = (zero,one)
    
    answer = 0
    for keta in range(60):
        a = 0
        for i in range(N):
            if bA[keta][i] == '1':
                ##zeroの個数
                a += ruiseki[keta][i][0]
            else:
                a += ruiseki[keta][i][1]

        answer += a*2**(59-keta)
        answer %= 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:
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(60)]
for x in a:
    x=bin(x)[2:]
    col=0
    for b in x[::-1]:
        if b=='1':
            l[col] = l[col]+1
        col+=1
l2=[0 for i in range(60)]
for x in a:
    x=bin(x)[2:]
    x=x.zfill(60)
    col=0
    for b in x[::-1]:
        if b=='0':
            l2[col] = l2[col] + l[col]
        else:
            l2[col] = l2[col] + n - l[col]
        col+=1
cnt=0
c=1
for i in range(60):
    cnt+=l2[i]*c
    c*=2
    c%=mod
print(cnt//2%mod)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 0
for a in range(n):
  for b in range(a):
    ans += (l[a] ^ l[b])
    
print(ans % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools
def main():
    N = int(input())
    w = [int(x) for x in input().split()]
    x = list(itertools.combinations(w, 2))
    count = [i[0]^i[1] for i in x]
    print((sum(count) % (10**9+7)))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)

@mt
def slv(N, A):
    ans = 0
    M = Mod(10**9+7)
    for i in range(0, 60):
        m = 1 << i
        b0 = deque()
        b1 = deque()
        for j, a in enumerate(A):
            if m & a > 0:
                b1.append(j)
            else:
                b0.append(j)
        for j, a in enumerate(A):
            c = m & a
            if c > 0:
                d = b0
                b1.popleft()
            else:
                d = b1
                b0.popleft()
            ans = M.add(M.mul(len(d), m), ans)
    return ans

def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))

    # N = 3 * (10**5)
    # A = [random.randint(0, 2**60) for _ in range(N)]
    # print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def do_code():
    num = int(input())
    table = [int(i) for i in input().split(" ")]
    sum = 0
    for i in range(len(table) - 1):
        for j in range(i, len(table)):
            sum += table[i] ^ table[j]
    print(sum % (10 ** 9 + 7))


if __name__ == '__main__':
    do_code()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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:
N = int(input())
A = list(map(int,input().split()))
B = [[0 for i in range(len(A))] for j in range(len(A))]
for i in range(len(A)):
    for j in range(i+1,len(A)):
        B[i][j] = A[i]^A[j]

ans = 0
for i in range(len(A)):
    ans += sum(B[i])
bk = int(1e9+7)
ans = ans%bk
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def tentwo(N):
    ret = [0] * 60
    NN = N
    for i in range(60):
        ret[i] = NN % 2
        NN //= 2
    return ret

N = int(input())

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

B = [0] * N

for i in range(N):
    B[i] = tentwo(A[i])

ans = 0
for j in range(60):
    count = 0
    for i in range(N):
        if B[i][j] == 1:
            count += 1
    ans = (ans + (count * (N-count)) * (2 ** j)) % (10**9 + 7)

print(ans)

Submission status: Time Limit Exceeded

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

total = 0
for i in range(n-1):
    for j in range(i+1, n):
        total += ali[i]^ali[j]
print(total%mod)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
MOD=10**9+7
A = list(map(lambda s:"{:060b}".format(int(s)), input().split()))
res=0
for i in range(60):
    r = sum([A[j][59-i]=="1" for j in range(N)])
    res += ((r * (N - r)) << i) % MOD
print(res%MOD)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

s = 0
b = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7
m = []
for i in range(1 - 1, N - 1):
    for j in range(i + 1 - 1, N + 1 - 1):
        s += A[i] ^ A[j]
        s = s % b

print(s)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
ans = 0
for i in range(60):
    tmp = [x >> i & 1 for x in A]
    ans += (tmp.count(True) * tmp.count(False)) * 2 ** i
    ans = ans % (10 ** 9 + 7)
print(ans)

Submission status: Time Limit Exceeded

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

res = 0

for i in range(n):
  for j in range(i, len(a)):
    res += a[i] ^ a[j]
print(res % 1000000007)

Submission status: Time Limit Exceeded

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

s=0

for i in range(N):
    for j in range(i,N):
        s+=(A[i]^A[j])%mod

print(s%mod)

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):
    for j in range(i+1, N):
        sum_ += A[i] ^ A[j]

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

Submission status: Time Limit Exceeded

Solution code:
import operator
N = int(input())
A = [int(x) for x in input().split()]
res = 0
for i in range(N-1):
    for j in range(i+1, N):
        res = (res+operator.xor(A[i],A[j]))%(10**9+7)
print(res)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
MOD=10**9+7
L=60
ls=[int(s) for s in input().split()]
bils=[]
for i in range(N):
  val_ls=[0 for j in range(L)]
  for j in range(L):
    if (2**j)&ls[i]>0:
      val_ls[j]=1
  bils.append(val_ls)
bisumls=[[0 for _ in range(L)] for _ in range(N)]
bisumls[N-1]=bils[N-1]
for i in range(2,N):
  for j in range(L):
    bisumls[-i][j]=bisumls[-i+1][j]+bils[-i][j]
#[[0, 0, 0], [3, 0, 2], [2, 0, 2], [2, 0, 1], [1, 0, 1]]
ans=0
ans_ls=[0 for _ in range(L)]
for i in range(N-1):
  #print(bils[i],bisumls[i+1])
  for k in range(L):
    if bils[i][k]==1:
      a=N-i-1-bisumls[i+1][k]
    else:
      a=bisumls[i+1][k]
   #   print(a)
    ans_ls[k]+=a
ans=0
base=1
for k in range(L):
  ans+=base*ans_ls[k]%MOD
  base=base*2%MOD
print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
import math
MOD = 10**9 + 7
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] = format(a[i], '060b')
s = 0
for i in range(60):
    c0 = 0
    c1 = 0
    for j in range(n):
        if a[j][i] == '0':
            c0 += 1
        else:
            c1 += 1
    s += pow(2,59-i,MOD)*c0*c1
    s %= MOD
print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

count = 0

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

for j in conv:
    pair = (j[0]^j[1])
    count += pair
        
print(count%(10**9+7))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

print(sum(res) % l)

Submission status: Time Limit Exceeded

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

out = 0
mod = 10**9 + 7 
for i in range(N-1):
    A_i = A[i]
    for j in range(i+1, N):
        A_j = A[j]
        out += A[i]^A[j]
        out = out % mod
print(out)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
numbers = input()
res = 0
for i in range(n):
    for j in range(i,n):
        res += (int(numbers.split(" ")[i]) ^ int(numbers.split(" ")[j]))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
a = MAP()

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

Submission status: Time Limit Exceeded

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

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:
# coding: utf-8
mod = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i, a1 in enumerate(A[:-1]):
    for a2 in A[i+1:]:
        # print(a1, a2, a1&a2)
        ans += a1 ^ a2
        ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input()
a = list(map(int, input().split()))
i = 0
sum = 0
while i < len(a)-1:
  for j in range(i+1, len(a)):
    #print(i, j)
    sum += a[i]^a[j]
    while sum >= 1000000007:
      sum -= 1000000007
  i += 1
print(sum)

Submission status: Time Limit Exceeded

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

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

sum = 0
for i in range(N):
  for j in range(i+1,N):
    sum += add(A[i], A[j])


ans = sum % (1000000007)
#出力

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def bi(x):
    x = int(x)
    i = 0
    o = [0]*61
    while x > 0:
        o[i] = x % 2
        x //= 2
        i += 1
    return o

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

# print(*A,sep='\n')
a = 0
ruijoo = 1
bbb = 0
for h in range(61):
    B = list(map(lambda x: x[h],A))
    isZero = sum(map(lambda x: x == 0,B))
    isOne = sum(map(lambda x: x == 1,B))
    bbb += sum(map(lambda x:isZero if x else isOne,B))*ruijoo
    ruijoo *= 2
    ruijoo %= 1000000007

bbb *= 500000004
bbb %= 1000000007
print(bbb)

Submission status: Time Limit Exceeded

Solution code:
import itertools
x = 10 ** 9
S = int(input())
a = [int(i) for i in input().split()]
 
xor = 0
patern = list(itertools.combinations(a, 2))
for p in patern:
    xor += p[0] ^ p[1]
if xor >= x:
    print(xor % (x + 7))
else:
    print(xor)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
ls = [[0 for j in range(N)] for i in range (60)]
mod = 10**9+7

for i,n in enumerate(A):
  for j in range(60):
    d, m = divmod(n,2)
    ls[j][i]=m
    n = d
    if n==0:
      break
      
      
ans = 0
for i in range(60):
  s = sum(ls[i])
  ln = len(ls[i])
  tmp = s * (ln-s) % mod
  ans += tmp * 2**i % mod
  ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int,input().split()))
sum_xor = 0

def plus(i):
    global sum_xor
    sum_xor += i

for m in range(N-1):
    for v in A_list[m+1:]:
        plus(A_list[m] ^ v)

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def main():
  N = int(input())
  A = list(map(int, input().split()))
  ans = 0
  for i in range(N):
    for j in range(i+1,N):
      ans += A[i] ^ A[j]
  print(ans % 1000000007)

if __name__ == '__main__':
    main()

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 += int(bin(a[i]^ a[j]), 2)
print(SUM % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
List = list(map(int, input().split()))
mod = 10**9+7
sum = 0
range_list = range(len(List))
for i in range_list:
    for j in range_list:
        if i >= j:
            continue
        else:
            sum += (List[i] ^ List[j]) % mod
print(sum % mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list()
ans = 0
for i in range(n - 1):
    for j in range(n - i - 1):
        b = A[i] ^ A[j + i + 1]
        B.append(b)
        len_B = len(B)
        if ans + B[len_B - 1] < 1000000007:
            ans += b
        else:
            ans = (ans + b) % 1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input().split()
A = []
Su = 0
for c in S:
    A.append(int(c))
for i in range(N):
    # print(i)
    B = int(bin(A[i])[2:])
    for j in range(i+1, N):
        C = int(bin(A[j])[2:])
        D = str(B+C)
        D = D.replace("2", "0")
        Su += int(D, 2)
print(Su % (10**9+7))

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]
    for b in B:
        if b[i] == "1":
            rui.append(rui[-1]+1)
        else:
            rui.append(rui[-1])
    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:
n = int(input())
li_a = list(map(int, input().split()))
a = 0
mod = 10**9 + 7
for i in range(n-1):
  for j in range(i+1, n):
    a += li_a[i]^li_a[j]
print(a%mod)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

maxA = max(A)
bmaxA = format(maxA, 'b')
n_bmaxA = len(bmaxA)


cmb = itertools.combinations(A, 2)

ans = 0
for item in cmb:

    if item[0] == item[1]:
        ans += 0
    else:
        bfirst = format(item[0], '0{}b'.format(n_bmaxA))
        blast = format(item[1], '0{}b'.format(n_bmaxA))

        cXOR = []
        for i in range(len(bfirst)):
            if bfirst[i] == blast[i]:
                cXOR.append("0")
            else:
                cXOR.append("1")

        cXOR = ''.join(cXOR)
        ans += int(cXOR, 2)

base = 1000000000 + 7
print(ans % base)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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

ans = []
for i in range(N - 1):  
    for j in range(i + 1, N):
        ans.append(a[i] ^ a[j])
print(sum(ans) % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

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


def xor(x, y):
    X = bin(max(x, y))[2:]
    Y = bin(min(x, y))[2:]
    w = str(int(X)+int(Y))
    ans = ""
    for i in range(len(w)):
        if w[i] != "1":
            w = w[:i] + "0" + w[i+1:]
    return int("0b" + w, 2)


Ans = 0
mod = 10**9 + 7
for i in itertools.combinations(a, 2):
        Ans = (Ans + xor(i[0], i[1])) % 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(0,n-1):
    k=i+1
    for j in range(k,n):
        sum += a[i]^a[j]
        sum = sum%(10**9+7)
print(sum%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
keta=[0]*60
for i in range(n):
    for j in range(60):
        if (a[i]>>j)&1==1:
            keta[j]+=1

s=sum(a)
ans=0
for i in range(n):
    s-=a[i]
    j=0
    tmp2=a[i]
    while tmp2!=0:
        if tmp2%2==1:
            keta[j]-=1
            ans+=(2**j)*((n-(i+1)-keta[j]*2))
        j+=1
        tmp2=tmp2//2
    ans+=s
    ans%=mod
    # print(ans,s)
    # print(keta)
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    a_s = LI()
    kaizyo = [1]
    keta = [0 for i in range(61)]
    ans = 0
    for i in range(61):
        kaizyo.append(kaizyo[i] * 2 % MOD)
    for i in a_s:
        for i, v in enumerate(bin(i)[:1:-1]):
            keta[i] += int(v)
    # print(kaizyo)
    # print(keta)
    for i, v in enumerate(keta):
        c = v * (n-v) % MOD
        ans += c * kaizyo[i]
        ans = ans % MOD
        # print(ans, c, kaizyo[i])

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
k=int(input())
l=[int(x) for x in input().rstrip().split()]
a=[]
for i,j in itertools.combinations(l,2):
    a.append([i,j])

A_1=0
A_2=0
ans=""
ANS=[]
for i in range(len(a)):
    A_1=format(a[i][0],'b')
    A_2=format(a[i][1],'b')
    if len(A_1)<len(A_2):
        A_1='0'*(len(A_2)-len(A_1))+A_1
    elif len(A_2)<len(A_1):
        A_2='0'*(len(A_1)-len(A_2))+A_2
 

    for j in range(len(A_1)):
        if A_1[j]==A_2[j]:
            ans=ans+'0'
        else:
            ans=ans+'1'
    ANS.append(ans)
    ans=''

SUM=0

for i in range(len(ANS)):
    SUM+=int(ANS[i],2)
SUM=SUM%(10**9+7)
print(SUM)

Submission status: Time Limit Exceeded

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

n = int(input())
li = list(map(int, input().split()))
print(func(li, n))

Submission status: Time Limit Exceeded

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

b = 1
b2 = 1
ans = (base * N) % MOD
for i in range(60):
	s = 0
	k = 0
	for a in A:
		if (a // b) % 2 == 1:
			k -= 1
			s += 1
		else:
			k += 1
	ans = (ans + ((b2 * s * k) % MOD)) % MOD
	b2 = b2 * 2 % MOD
	b = b * 2
# divide 2
ans = (ans * ((MOD + 1) // 2)) % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
MOD = 10**9 + 7
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] = format(a[i], '060b')
s = 0
for i in range(60):
    c0 = 0
    c1 = 0
    for j in range(n):
        if a[j][i] == '0':
            c0 += 1
        else:
            c1 += 1
    s += 2**(59-i)*c0*c1%MOD
    s %= MOD
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    num = input()
    num_list = list(map(int, input().split(" ")))
    # result = sum([sum([num_list[i]^num_list[j] for j in range(i)]) for i in range(int(num))])
    result = 0
    for i in range(int(num)):
        for j in range(i):
            result += num_list[i]^num_list[j]
    print(result%(10**9+7))    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(len(A)):
    for j in range(len(A)-i -1 ):
        sum += A[i] ^ A[j + i + 1]

#sum = sum * 2

#for i in range(len(A)):
#    sum += A[i] ^ A [i] 

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