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 sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


class Solver(object):
    def __init__(self):
        pass

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


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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# problem D
mod=10**9+7

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

b=[[0 for i in range(N)] for k in range(60)] # i番目の数の2^kの位(0<=k<60)

for i in range(N):
    for k in range(60):
        b[k][i]=A[i]>>k&1

ans=0
for k in range(60):
    ans+=2**k*b[k].count(0)*b[k].count(1)

print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
lst = [int(e)for e in s.split(' ')]
re = 0
for i in range(n):
    for j in range(i, n):
        re += lst[i]^lst[j]
print(re%(10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import operator
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 += operator.xor(a[i], a[j])
if sum > 1000000007 :
	print(sum % 1000000007)
else :
	print(sum)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  ar = list(map(int,input().split(' ')))
  ans , mod = 0 , int(1e9+7)

  for i in range(0,62):
    zero , one = 0 , 0
    for j in range(len(ar)):
      if ar[j]%2 == 1:
        one+=1
      else:
        zero+=1
      ar[j]//=2
    
    idsum =  ((one%mod * zero%mod)%mod * (1 << i)%mod)%mod
    ans = (ans%mod + idsum%mod)%mod
  
  print(ans%mod)

######## Python 2 and 3 footer by Pajenegod and c1729

# Note because cf runs old PyPy3 version which doesn't have the sped up
# unicode strings, PyPy3 strings will many times be slower than pypy2.
# There is a way to get around this by using binary strings in PyPy3
# but its syntax is different which makes it kind of a mess to use.

# So on cf, use PyPy2 for best string performance.

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

# Read all remaining integers in stdin, type is given by optional argument, this is fast
def readnumbers(zero = 0):
    conv = ord if py2 else lambda x:x
    A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()
    try:
        while True:
            if s[i] >= b'0' [0]:
                numb = 10 * numb + conv(s[i]) - 48
            elif s[i] == b'-' [0]: sign = -1
            elif s[i] != b'\r' [0]:
                A.append(sign*numb)
                numb = zero; sign = 1
            i += 1
    except:pass
    if s and s[-1] >= b'0' [0]:
        A.append(sign*numb)
    return A

if __name__== "__main__":
  main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(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:
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
    for i in range(n):
        a_sub = a[i+1:]
        a_sub_dict = dict(Counter(a_sub))
        for j in a_sub_dict:
            ans += a_sub_dict[j] * (a[i] ^ j)
    print(ans % mod)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = list(map(int,input().split()))
sum = 0
MOD = 10**9+7
max_x = max(lst) 
max_length = len(bin(max_x))-2

for i in range(max_length,-1,-1):
    #ビットにある0,1の数を数えていく.
    cnt_0 = 0
    cnt_1 = 0
    for x in lst:
        if bin( x >> i )[-1] == '1':
            cnt_1 +=1
        else:
            cnt_0 +=1
    sum += cnt_0 * cnt_1 * (1 << i)
    sum = sum % MOD

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
A = [int(i) for i in input().split()]
A = tuple(A)
count = 0
for z in list(itertools.combinations(A, 2)):
    a, b = z
    count += a^b
print(count % (10**9+7))
print()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
# N = int(input())
# A = [0] * N
# B = []
# for n in range(N):
#     A[n] = int(input())
#     bn = []
#     for i in range(A[n]):
#         x, y = map(int, input().split())
#         bn.append((x-1, y))
#     B.append(bn)

# ans = 0
# # bit & (1 << n) で n 番目の 0,1
# for bit in range(1 << N):
#     ok = [False] * N
#     for n in range(N):
#         if ((bit >> n) & 1) == 1:
#             if all([((bit >> B[n][i][0]) & 1) == B[n][i][1] for i in range(A[n])]):
#                 ok[n] = True
#         else:
#             if all([((bit >> B[n][i][0]) & 1) != B[n][i][1] for i in range(A[n])]):
#                 ok[n] = True
#     if all(ok):
#         ans = max(ans, sum(list(map(int, format(bit, "b")))))

# print(ans)

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

MOD = 10 ** 9 + 7

ans = 0
for i in range(60):
    n = sum([(a >> i) & 1 for a in A])
    ans = (ans + n * (N - n) * (2 ** i)) % MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
mod = 10**9+7
num = [ int(v) for v in input().split() ]
bits = [ 0 for i in range(100) ]
num_bin_len = []

for i in num:
    t = bin(i)[2:][::-1]
    num_bin_len.append(len(t))
    for j, v in enumerate(t):
        bits[j] += int(v)

binmax = max(num_bin_len)+1

pow_2_list = []
q = 1
for i in range(100):
    pow_2_list.append(q)
    q *= 2
    q %= mod


ans = 0
for i, v in enumerate(bits[:binmax]):
    ans += v * (n-v)  * pow_2_list[i] 
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = [int(x) for x in input().split()]

mod = 10**9 + 7
ans = 0
for i in range(60):
    bit = 1 << i
    oc = 0
    zc = 0
    for x in a:
        if x & bit != 0:
            oc += 1
        else:
            zc += 1

    add = zc * oc * bit
    ans += add % mod

ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

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 >= 10 ** 9:
    print(np.mod(xor, (10 ** 9 + 7)))
else:
    print(xor)

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
cnt = 0
for i in range(n):
  binlist = list(map(int, list('0' * (len_c - len(bin(a[i])) + 2) + bin(a[i])[2:])))
  for j in range(len_c):
    if binlist[j] == 0:
      ans = (ans + c[j] * (2**(len_c-j-1))) % mod
    else:
      ans = (ans + (cnt - c[j]) * (2**(len_c-j-1))) % mod
      c[j] += 1
  cnt += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  ar = list(map(int,input().split(' ')))
  ans , mod = 0 , int(1e9+7)

  for i in range(0,62):
    zero , one = 0 , 0
    for j in range(len(ar)):
      if ar[j]%2 == 1:
        one+=1
      else:
        zero+=1
      ar[j]//=2
    
    idsum =  ((one%mod * zero%mod)%mod * (1 << i)%mod)%mod
    ans = (ans%mod + idsum%mod)%mod
  
  print(ans%mod)

main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
big=10**9+7

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


ret=0
for i in range(n-1):
  for j in range(i+1,n):
    #print("{0}({1}) xor {2}({3}) = {4}".format(a[i],i,a[j],j,a[i]^a[j]))
    ret += (a[i]^a[j])%big

ret = ret%big
print(ret)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
MAXBIT = 60
MOD = 10 ** 9 + 7
A = list(map(int, input().split()))
B = []
C = [[] for _ in range(MAXBIT)]
for a in A:
    for d in range(MAXBIT):
        C[d].append(a >> d & 1)
ans = 0
for d in range(MAXBIT):
    num0 = C[d].count(0)
    num1 = N - num0
    ans += (num0 * num1) * (2 ** d)
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10 ** 9 + 7


def solve(n, a):
    m = 62
    b = [('0'*m + bin(a[i])[2:])[-1:-m:-1] for i in range(n)]
    cnt_bit = [0] * m
    for i in range(n):
        for j, c in enumerate(b[i]):
            if c == '1':
                cnt_bit[j] += 1
    total = 0
    for i in range(n):
        for j, c in enumerate(b[i]):
            if c == '0':
                total += 2 ** j * cnt_bit[j]
            if c == '1':
                total += 2 ** j * (n - cnt_bit[j])
    return (total//2) % MOD


def bf(n, a):
    total = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            total += (a[i] ^ a[j])
    return total % MOD


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    print(solve(n, a))
    # print(bf(n, a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = [int(x) for x in input().split()]

mod = 10**9 + 7
ans = 0
for i in range(60):
    bit = 1 << i
    oc = 0
    zc = 0
    for x in a:
        if x & bit != 0:
            oc += 1
        else:
            zc += 1

    add = zc * oc * bit
    ans += add

ans = 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(61):
    cnt_0 = 0
    cnt_1 = 0
    for j in range(N):
        if (A[j] >> i & 1):
            cnt_1 += 1
        else:
            cnt_0 += 1
    ans += (cnt_1 * cnt_0 * (2**i)) % mod
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
alist = list(map(int,input().split()))
binlist = [0 for _ in range(60)]
mod_number = 10**9+7
for a in alist:
    a_bin = bin(a)
    for i in range(len(a_bin)-2):
        if int(a_bin[-(i+1)])==1:
            binlist[-(i+1)] += 1
            #print(a,a_bin,i,binlist)
ans = 0
for i in range(60):
    ans = (ans + binlist[-(i+1)]*(n-binlist[-(i+1)])*pow(2,i))%mod_number
    
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
ma = max(a)
maketa = len(bin(ma))-2
#print(maketa)
res = 0
dic = {}
for i in range(maketa):
    dic[i] = 0
for j in range(N):
    count = 0
    while a[j] >= 1:
        dic[count] += a[j] % 2
        a[j] = a[j] // 2
        count += 1
for i in range(maketa):
    num = dic[i]
    res += num*(N-num)*(2**(i))
print(res%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
#%%
inf = 10**9 + 7
import numpy as np

n = int(input())
a = list(map(int, input().split()))
count = np.array([0] * 70)
for i in range(n):
    tmp = np.array(list(map(int, (bin(a[i])[2:].zfill(70)))))
    count[tmp==1] += 1


ans = 0
for i in range(70):
    k = 2 ** (69 - i)
    k %= inf
    x = count[i] % inf
    y = (n - x) % inf
    ans += (x * y * k) % inf
    ans %= inf

ans %= inf
print(ans)


# %%

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
A = [int(a) for a in A]

sum_ = 0
for i in range(len(A)-1):
    for j in range(i+1,len(A)):
        sum_ += A[i]^A[j]
        sum_ = sum_%1000000007
        
print(sum_)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
MOD = 10**9+7
a = [int(c) for c in input().split()]
ls = [0]*60
for i in range(N):
  m = a[i]
  for j in range(60):
    if m%2==1:
      ls[j] += 1
    m >>= 1

ans = 0
x = 1
for i in range(60):
  ans += x*(ls[i]*(N-ls[i]))
  ans %= MOD
  x *= 2
  x %= MOD
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
mod=10**9+7
def axora(a,b):
  x=(a^b)%mod
  return x

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=(ans+axora(a[i],a[j]))%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
arr = list(map(int, input().split()))
ans = 0
arr = list(itertools.combinations(arr, 2))

for i, j in arr:
    ans += i ^ j
print(ans % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
mod=10**9+7
def num2bi(x, k):
  #10進数xを2進数k桁(string)で出力
  out=format(x, '0'+str(k)+'b')
  return out

N=int(input())
A=list(map(int, input().split()))
ma=max(A)
keta=1
while ma>=2**keta:
  keta+=1
  
onekazu=[0 for i in range(keta)]
k=str(keta)
for i in range(N):
  temp=format(A[i], '0'+str(k)+'b')
  for j in range(keta):
    onekazu[-1-j]+=int(temp[-1-j])
    
out=0
for i in range(keta):
  temp=onekazu[i]*(N-onekazu[i])
  temp%=mod
  temp*=(2**(keta-1-i))
  temp%=mod
  out+=temp
  out%=mod
  
print(out)

Submission status: Time Limit Exceeded

Solution code:
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

MOD = 10**9 + 7

n = ri()
ls = ril()
counter = collections.defaultdict(int)
for a in ls:
    i = 0
    while a > 0:
        if a % 2 == 1:
            counter[i] += 1
        a //= 2
        i += 1
res = 0
for k, v in counter.items():
    res += (n - v) * v * 2**k % MOD
    res %= MOD
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
lists=list(map(int,input().split()))
aa=[0 for i in range(n)]
length=61
use=[0 for i in range(61)]
for  j in range(n):
    k=format(lists[j],"0%ib"%length)
    k=k[::-1]
    aa[j]=k  
for p in aa:    
    for some in range(61):
        use[some]+=int(p[some])

answer=0

for j in range(61):
    answer+=(2**j)*use[j]*(n-use[j])%(10**9+7)
print(answer%(10**9+7))

Submission status: Time Limit Exceeded

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

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

    ans = ans % (INF + 7)
    return ans

print(calc(N, A))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

mod = 10**9+7

s = 0
p = itertools.combinations(a,2)
for v in p:
  s += v[0]^v[1]
  
print(s%mod)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

Submission status: Time Limit Exceeded

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

ni = [0 for _ in range(60)]
for i in range(N):
    tmp = A[i]
    count = 0
    while(True):
        if tmp % 2 == 1:
            ni[count] += 1
        count += 1
        tmp = tmp // 2
        if tmp == 0:
            break
ans = 0
for j in range(60):
    ans += (ni[j] * (N-ni[j])) * 2 ** j 

print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
def XOR( arr, n): 
	sumi = 0
	for i in range(0, 60): 
		zc = 0
		oc = 0
		# Individual sum at each bit position 
		idsum = 0
		for j in range(0, n): 
			if (arr[j] % 2 == 0): 
				zc = zc + 1
			else: 
				oc = oc + 1
			arr[j] = arr[j] >> 1
		# calculating individual bit sum 
		idsum = oc * zc * (1 << i) 
		# final sum	 
		sumi = (sumi%mod + idsum%mod)%mod; 
	return sumi%mod
mod = 10**9+7
n = int(input())
ls = list(map(int,input().strip().split()))
print(XOR(ls, n))

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

Submission status: Time Limit Exceeded

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

if sum1>=1000000007:
  sum1=sum1%1000000007
print(sum1)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
N = int(input())
*A, = map(int, input().split())
ans = 0
for i in range(len(format(max(A), 'b'))):
    bit_0, bit_1 = 0, 0
    for a in A:
        if (a >> i) & 1: 
            bit_1 += 1
        else:
            bit_0 += 1
    ans += bit_1 * bit_0 * pow(2, i, MOD)
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  ar = list(map(int,input().split(' ')))
  sum = 0

  for i in range(0,62):
    zero , one = 0 , 0
    for j in range(len(ar)):
      if ar[j]%2 == 1:
        one+=1
      else:
        zero+=1
      ar[j]//=2
    
    idsum =  one * zero * (1 << i)
    sum = sum + idsum
  
  print(sum%int(1e9+7))

main()

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]
        while s >= b:
            s -= b

print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

# for i in range(N-1):
#     ans += sum(a[i+1:]) ^ a[i] + (N - a[i])
#     print(sum(a[i+1:]) ^ a[i])
#     #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
N = int(input())
w = [int(x) for x in input().split()]
x = [balls for balls in itertools.combinations(w, 2)]
count = 0
for i in range(len(x)):
    count += x[i][0] ^ x[i][1]
result = count % (10**9+7)
print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [None for k in range(N)]
for k in range(N):
	B[k] = format(A[k], '060b')
c = 0
for k in range(60):
	t = 0
	f = 0
	for s in range(N):
		if B[s][k] == '1':
			t +=1
		else:
			f +=1
	c += (t*f*(2**(59-k)))%(10**9+7)
print(c%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
mod = 10**9 + 7
A = sorted([int(i) for i in input().split()])
bits = [0]*61

ans = 0
for i, a in enumerate(A):
    for b in range(len(bin(a))-2):
        if (a >> b) & 1:
            ans += (2**b)*(i-bits[b])
            bits[b] += 1
        else:
            ans += (2**b)*bits[b]
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

c = [0] * 60

const = 10 ** 9 + 7

ans = 0

for i in range(n):
    b = a[i]
    t = 0
    while t <= 60:
        if b == 0:
            break
        elif b == 1:
            c[t] += 1
            break
        else:
            q, mod = divmod(b, 2)
            b = q
            c[t] += mod
            t += 1

for i in range(60):
    ans += (2 ** i * (c[i] * (n - c[i]))) % const

print(ans % const)

Submission status: Time Limit Exceeded

Solution code:
import operator
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 += operator.xor(a[i], a[j])
print(sum % (pow(10, 9) + 7 ))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
MAXBIT = 60
MOD = 10 ** 9 + 7
A = list(map(int, input().split()))
B = []
C = [[] for _ in range(MAXBIT)]
for a in A:
    b = format(a, '0'+str(MAXBIT)+'b')
    for d in range(MAXBIT):
        # C[d].update([b[d]])
        C[d].append(int(b[d]))
ans = 0
for d in range(MAXBIT):
    num0 = C[d].count(0)
    num1 = N - num0
    ans += (num0 * num1) * (2 ** (MAXBIT-d-1))
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    mod = 7 + 10 ** 9

    bit = [0 for _ in range(60)] 

    last = A[N-1]
    for j in range(60):
        bit[j] = last % 2
        last //= 2
    
    ans = 0
    for i in reversed(range(N-1)):
        total = N - 1 - i
        num = A[i]
        for j in range(60):
            if num % 2 == 1:
                ans += (total - bit[j]) * pow(2, j, mod)
                ans %= mod
            else:
                ans += bit[j] * pow(2, j, mod)
                ans %= mod
            bit[j] += (num % 2)
            num //=2
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:

def main():
    from itertools import combinations

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    ans = 0
    for i in combinations(a, 2):
        ans += i[0] ^ i[1]
        ans %= mod

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def solve(a,n):
	s = 0
	mod = 1000*1000*1000 + 7
	for i in range(0,64):
		zc,oc = 0,0
		for j in range(n):
			if a[j]%2!=0:
				oc+=1
			else:
				zc+=1
			a[j] = a[j]//2
		l = oc * zc * (1<<i)
		s = s + l
	return s%mod

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

ans = solve(a,n)
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
for i in range(N-1):
    for j in range(i+1, N):
        ans += A[i] ^ A[j]
print(ans % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(sys.stdin.readline().strip())
a = [int(v) for v in sys.stdin.readline().strip().split()]
c = 0
m = 10 ** 9 + 7
for i in range(n-1):
  for j in range(i+1, n):
    # print('a[%d] ^ a[%d] = %d' %( i, j, a[i] ^ a[j]))
    c += (a[i] ^ a[j]) % m
print(c % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
MOD = 10 ** 9 + 7
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    t = 0
    for i, Ai in enumerate(A[:-1]):
        t = (t + sum(Ai ^ Aj for Aj in A[i + 1:])) % MOD
    print(t)

main()

Submission status: Time Limit Exceeded

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

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

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

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:
def main():
    N = int(input())
    A = list(map(int, input().split()))

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

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

if __name__ == '__main__':
    main()