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

res = 0

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

Submission status: Time Limit Exceeded

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

ans = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
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 += a[i] ^ a[j]
print(res % (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:
mod = 10 ** 9 + 7

def naive_main(nums):
    n = len(nums)
    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            ans += nums[i] ^ nums[j]
    return ans

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

# s

"""
0 0 0 1
0 0 1 0
0 0 1 0
0 1 0 0
1 0 0 0

4, 4, 6, 4

32 16 12 4
"""

max_len = len(bin(max(nums))) - 2

counter = [0 for _ in range(max_len)]
for i in range(n):
    ss = bin(nums[i])[2:]
    ss = "0" * (max_len - len(ss)) + ss
    for j in range(len(ss)):
        if ss[j] == "1":
            counter[j] += 1

# print(n)
# print(counter)
ans = 0
for i in range(max_len):
    c = counter[max_len - 1 - i]
    ans += (c * (n - c) * (2 ** i)) % mod

print(int(ans) % mod)
#print(naive_main(nums))

Submission status: Time Limit Exceeded

Solution code:
def XOR(a,b,n):
    s=0
    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],60)

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

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


def main():
    MOD = 10 ** 9 + 7
    N = int(input())
    A = [int(x) for x in input().split()]

    x = [0] * 61
    for i in range(N):
        for j in range(61):
            if A[i] >> j & 1:
                x[j] += 1
    ans = sum(A) * (N - 1)
    for i, v in enumerate(x):
        if v == 0 or v == 1:
            continue
        else:
            z = (2 ** i) * (v * (v - 1))
            ans = ans - z

    print(ans % MOD)







if __name__ == '__main__':
    main()

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

Submission status: Time Limit Exceeded

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

# print (MOD)
# left = [0]
# for a in A:
#     sm+=a
#     sm = sm % MOD
#     left.append(sm)
# print (left)
# sm = 0
# right = [0]
# for a in A[::-1]:
#     sm+=a
#     sm = sm % MOD
#     right.append(sm)
# right = right[::-1]
# print (right)


# ans = 0
# for i in range(len(A)):
#     sm = left[i]+right[i+1]
#     if (len(A)%2==0):
#         sm = sm^A[i]
#     ans += sm
#     ans = ans % MOD
# print (ans)

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]
    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(bin(i)[:1:-1]):
            keta[i] += int(v)
    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:
n=int(input())
a=[int(i) for i in input().split()]
s=0
for i in range(1,n):
  for j in range(i):
    s+=a[j]^a[i]
print(s%(10**9+7))

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):
           sum += a_list[i] ^ a_list[j]

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(61):
  one = np.count_nonzero(A_list[:,i]==1)
  ans += 2**(60-i) * one * (n-one)
  ans %= 10**9+7

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input().rstrip())
l = list(map(int, input().rstrip().split(' ')))
denominator = 1000000000 + 7
sum = 0

for i in range(N-1):
  for j in range(i+1, N):
    sum += (int(l[i] ^ l[j]) % denominator)
    #print('l[i]:' + str(l[i]) + ', l[j]: ' + str(l[j]) + ', l[i] ^ l[j]: ' + str(l[i] ^ l[j]))

print(sum % denominator)

Submission status: Time Limit Exceeded

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

N, *A = map(int, read().split())
mod = 10 ** 9 + 7
answer = 0

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

print(answer)

Submission status: Time Limit Exceeded

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

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 ans():
    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 // 2
            if kkk & 1:
                dp[i][j] = dp[i-1][j] + 1
            else:
                dp[i][j] = dp[i-1][j]

    two = [0 for i in range(61)]
    two[0] = 1
    for i in range(1,61):
        two[i] = (two[i-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)

if __name__ == '__main__':
    ans()

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    md = 10 ** 9 + 7
    n = int(input())
    aa = LI()
    cnt = [[0] * 2 for _ in range(61)]
    for a in aa:
        for i in range(61):
            cnt[i][a & 1] += 1
            a >>= 1
    #print(cnt)
    base = 1
    ans = 0
    for c0, c1 in cnt:
        ans += base * c0 * c1
        ans %= md
        base = base * 2 % md
    print(ans)

main()

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")
for i in range(len(str_a)):
  a_bit = int(str_a[-(i + 1)])
  b[0][i] = a_bit

for i in range(1, n):
  str_a = format(a[i], "0b")
  for j in range(len(str_a)):
    a_bit = int(str_a[-(j + 1)])
    b[i][j] = b[i - 1][j] + a_bit
    
ans = 0
for i in range(1, n):
  str_a = format(a[i], "0b")
  for j in range(len(str_a)):
    if str_a[-(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:
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math
import itertools

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


def main():
#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

    n = int(input())
    a=list(map(int,input().split()))
    temp=0
    count=0
    for i in range(n-1):
        for j in range(i+1,n):
    #        print(a[i] ^ a[j])
            count+=(a[i] ^ a[j])%MOD


    print(count%MOD)






#  print(c)




            #    print(n,kingaku(a,b,x))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lis=list(map(int,input().split()))
ans=0
for i in range(n):
    lislis=[lis[i],0]
    for j in range(n-1-i):
        m=0
        lislis[1]=lis[i+1+j]
        lislis.sort()
        lislis[0]=bin(lislis[0])
        lislis[1]=bin(lislis[1])
        x=len(lislis[0])-2
        y=len(lislis[1])-len(lislis[0])
        for k in range(x):
            s=len(lislis[0])-1-k
            ss=len(lislis[1])-1-k
            if lislis[0][s]!=lislis[1][ss]:
                m+=1*(10**k)
        for l in range(y):
            sss=len(lislis[1])-x-1-l
            if lislis[1][sss]=="1":
                m+=1*(10**(x+l))
        ans+=int(str(m),2)
        lislis=[lis[i],0]
ans=ans%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
MOD = 10**9 + 7

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

count_list = [0] * 60
for i in inputs:
    tmp = bin(i)[2:].zfill(60)
    for i in range(60):
        count_list[i] += int(tmp[i])

result_list = []
result = 0
for i in range(60):
    keta_result = count_list[i] * (n - count_list[i])
    result += keta_result * (2 ** (60 - 1 - i))
print(result % MOD)

Submission status: Time Limit Exceeded

Solution code:
N=int(input()) 
import math
A=list(map(int, input().split())) 
k =  len(bin(max(A))[2:])
mod = 10**9+7

c = [0]*k

for i in A:
  bit = bin(i)[2:].zfill(k)
  for j in range(k):
    if bit[j] == '1':
      c[-1-j] +=1
      
ans = 0
for i in range(k):
  ans = (ans +(2**i)*(c[i]*(N-(c[i]))))%mod
  
print(ans)

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):
    tr, fl = 0, 0
    for x in A:
        if x >> i & 1:
            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())
a=tuple(list(map(int,input().split())))
s=0
for i in range(n-1):
    for j in range(i+1,n):
        s += (a[i]^a[j])%(10**9+7)
print(s%(10**9+7))

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):
    for j in range(i+1, N):
        X = ((A[i] | A[j]) & (~A[i] | ~A[j]))
        Su += X
print(Su % (10**9+7))

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')
    # print(format(a_i, '030b'))
    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) % (10**9 + 7)) * ((count % (10**9 + 7)) * ((n - count) % (10**9 + 7)))
    ans %= 10**9 + 7
    # print(ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline


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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
L = len(format(max(a), 'b'))
x = [[0 for j in range(60)] for i in range(2)]
ans = 0
MOD = 10 ** 9 + 7
for i in a:
    i_str = list(format(i, '0' + str(L) + 'b'))[::-1]
    for j, s in enumerate(i_str):
        x[int(s)][j] += 1
for i in range(60):
    x0 = x[0][i]
    x1 = x[1][i]
    y = x0 * x1
    ans += y * 2 ** i % MOD
    ans %= MOD
print(ans)

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):
    c = 0
    for j in range(n):
        if a[j][i] == '0':
            c += 1
    s += pow(2,59-i,MOD)*c*(n-c)
print(s%MOD)

Submission status: Time Limit Exceeded

Solution code:
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 += 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()))
mod = 10**9+7
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        # print(A[i], A[j], A[i]^A[j])
        ans += (A[i] ^ A[j]) % mod
        # print(A[i]^A[j])
print(ans % mod)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

sum = 0

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

result = sum % 1000000007

print(result)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
l=[int(x) for x in input().rstrip().split()]
a=[]

for i in l:
    for j in l:
        if i<j:
            a.append([i,j])

A_1=0
A_2=0
SUM=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)
    SUM+=int(ans,2)
    ans=''
SUM=SUM%(10**9+7)
print(SUM)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
s =[0]*n
ans =0
ans2 =0

def xor(x,ans,k):
	for j in range(k,n):
		s[j] = format(x ^ a[j])
		s[j] = int(s[j])
		ans+=s[j]

	return ans

for i in range(n-1):
	ans2 +=xor(a[i],ans,i+1)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = tuple(map(int,input().split()))
d = []
d_append = d.append
num = 10**9 + 7
for i in range(N-1):
    #print(i)
    for j in range(i+1,N):
        #print(j)
        b = A[i] ^ A[j]
        #b %= num
        d_append(b)
print(sum(d)%num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    c = []
    for j in range(60):
        if a[i] % 2**(j+1) == 0:
            c.append(0)
        else:
            c.append(1)
            a[i] -= 2**j
    b.append(c)

ans = 0

for i in range(60):
    c0 = 0
    c1 = 0
    for j in range(n):
        if b[j][i] == 0:
            c0 += 1
        else:
            c1 += 1
    ans += 2 ** i * c0 * c1
    ans %= 10**9 + 7

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def calc_xor(a, b):
    return a ^ b


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

ans = 0
for n in range(N-1):
    for k in range(n+1, N):
        a = num_list[n]
        b = num_list[k]
        ans += calc_xor(a, b)

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

Submission status: Time Limit Exceeded

Solution code:
MOD=10**9+7

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

#print(alist)
blist=[0]*64
for a in alist:
  bin_str=format(a, '064b')
  dlist=list(map(int,list(bin_str)))
  #print(bin_str)
  for i in range(64):
    blist[i]+=dlist[i]
      
blist.reverse()
#print(blist)
answer=0
for i in range(64):
  answer+=blist[i]*(N-blist[i])*(2**i)
  
print(answer%MOD)

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 k in range(i+1, N):
        ans += A[i] ^ A[k]
print(ans % mod)

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 += (a[i]^a[j]) % MOD

print(ans%MOD)

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]

    ruiseki = [[()]*N for _ in range(mLEN)]
    for keta in range(mLEN):
        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(mLEN):
        a = 0
        for i in range(N):
            if bA[keta][i] == '1':
                a += ruiseki[keta][i][0]
            else:
                a += ruiseki[keta][i][1]

        answer += a*2**(mLEN-1-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:
import numpy as np
n = int(input())
A_list = np.array([[int(i) for i in bin(int(A))[2:].zfill(61)] for A in input().split()])
ans = 0

for i in range(61):
  one = np.count_nonzero(A_list[:,i]==1)
  ans += 2**(60-i) * one * (n-one)

print(ans%(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(len(a)-1):
    for j in range(i,len(a)):
        s+=a[i]^a[j]
        s=s%1000000007

print(s)

Submission status: Time Limit Exceeded

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

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

print(ans%div)

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

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 = [0 for i in range(61)]
two[0] = 1
for i in range(1,61):
    two[i] = (two[i-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())
nums = list(map(int, input().split()))

X=0
for i in range(N-1):
    for j in range(N):
        if (j > i):
            X+= nums[i] ^ nums[j]
            
if X< 1000000007:
    print(X)
else:
    print(str(X % (10**9 + 7)))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
cs = [[0] * 61 for _ in range(N + 1)]
mod = 10 ** 9 + 7
for i in range(N):
  for j in range(61):
    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(61):
    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:
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')
    # print(format(a_i, '030b'))
    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) % (10**9 + 7)) * (count * (n - count))
    ans %= 10**9 + 7 
    # print(ans)

print(ans)

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])
            sum %= mod
print(sum)

Submission status: Time Limit Exceeded

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

sum_a = 0
for i in range(n-1):
    for j in range(i+1, n):
        sum_a += a[i] ^ a[j]
        if sum_a > 1000000007:
            sum_a -= 1000000007

print(sum_a % 1000000007)

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
d=1
for i in range(60):
    r = sum([A[j][59-i]=="1" for j in range(N)])
    res += (r * (N - r) *d)%MOD
    d*=2
    d%=MOD
print(res%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]
        if ans + b < 1000000007:
            ans += b
        else:
            ans = (ans + b) % 1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
save = {}
ans = 0
tmp = 0

for i in range(n - 1):
    tmp = 0
    if i in save:
        ans += save[i]
    for j in range(i + 1, n):
        ans += a[i] ^ a[j]
        tmp += a[i] ^ a[j]

    save[i] = tmp

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    b.append(format(a[i],"b"))
ans = 0
def func(num):
    global ans
    flag = False
    one_count = 0
    zero_count = 0
    for i in range(n):
        if len(b[i]) > num:
            flag = True
            if b[i][-1*(num+1)] == "1":
                one_count += 1
            else:
                zero_count += 1
        else:
            zero_count += 1
    if flag:
        ans += one_count * zero_count * (2** num)
        func(num+1)
func(0)
print(ans%(10**9+7))

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

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

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 = [A[x][h] for x in range(N)]
    isOne = sum(B)
    isZero = N - isOne
    C = [isOne,isZero]
    bbb += sum([C[B[x]] for x in range(N)])*ruijoo
    ruijoo *= 2
    ruijoo %= 1000000007

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

Submission status: Time Limit Exceeded

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

result=0
for i in range(len(a)):
  for j in range(i+1,len(a)):
    temp=a[i]^a[j]
    result+=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
ans=0
for i in range(n):
  for j in range(i,n):
    ans+=(A[i]^A[j])
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = list(map(int, input().split()))
digit = np.zeros(60)
for a in A:
    binary = np.array(list(map(int, bin(a)[-1:1:-1])))
    digit[0:len(binary)] += binary
ans = 0
mod = 10**9+7
digit = digit * (N - digit) % mod
for i in range(60):
    ans += int(digit[i]) * pow(2, i, mod)
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
keta=[0 for i in range(61)]
ans=0
for i in range(n):
  b=a[i]
  cnt=0
  while(b>=1):
    if b%2==1:
      keta[cnt]+=1
    b=b//2
    cnt+=1
#print(keta)
for i in range(61):
  #print(keta[i])
  #print(keta[i]*(n-keta[i])*(2**i))
  ans+=(keta[i]*(n-keta[i])*(2**i))%(1000000007)
while(ans>1000000007):
  ans%=1000000007
print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    ans = [int(bin(a^b), 2) for a,b in itertools.combinations(A, 2)]
    

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

if __name__ == '__main__':
    main()