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: Runtime Error

Solution code:
N=int(input())
a_l=[int(i) for i in input().split()]

sum1=0
for (i,j) in it.combinations(a_l, 2):
        sum1+=i^j
print(sum1%(7+10**9))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
for _ in range(N):
  A.append(int(input()))
  
xorA=0
for i in range(N):
  for j in range(i+1,N):
    xorA+=A[i]^A[j]

print(xorA/(10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np

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

res = 0
for b in range(60):
  bs = int((A >> b) & 1).sum()
  res = (res + bs*(N-bs) * (1 << b)) % 1000000007

print(res)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n = int(input())
A = np.fromstring(input(),dtype=np.int64,sep=" ")
rng = int(math.log2(np.max(A)))+1
sum = 0
d = 10**9+7
for bit in range(64):
    c = int((A & 1).sum())
    sum += c *(n-c)*pow(2,bit,d)%d
    A >>= 1

print(sum %(d))

Submission status: Runtime Error

Solution code:

import numpy as np
import math
n = int(input())
A = np.fromstring(input(),dtype=np.int64,sep=" ")
rng = int(math.log2(np.max(A)))+1
sum = 0
d = 10**9+7
for bit in range(64):
    c = int((A & 1).sum())
    sum += c *(n-c)*(1<<bit)%d
    A = A>>1

print(sum %(d))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n = int(input())
A = np.fromstring(input(),dtype=np.int64,sep=" ")
rng = int(math.log2(np.max(A)))+1
sum = 0
for bit in range(64):
    c = int((A & 1).sum())
    sum += c *(n-c)*(1<<bit)
    A = A>>1

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

Submission status: Runtime Error

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

bit2 = [0] * 20
for i in range(N):
  bin_a = bin(A[i])
  #print(bin_a)#2なら0b10と返す
  str_bin_a = str(bin_a)[2:]
  #print(str_bin_a)
  l = len(str_bin_a)
  for j in range(l):
    bit2[j] += int(str_bin_a[-(j + 1)])
    
#print(bit2)
ans = 0
for i in range(20):
  count1 = bit2[i]
  count0 = N - count1
  ans += (2 ** i) * count0 * count1
  
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(200000)

import numpy as np
import math
n = int(input())
A = np.fromstring(input(),dtype=np.int64,sep=" ")
rng = int(math.log2(np.max(A)))+1
sum = 0
for bit in range(rng):
    c = int((A & 1).sum())
    sum += c *(n-c)*(1<<bit)
    A = A>>1

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

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n = int(input())
A = np.fromstring(input(),dtype=np.int64,sep=" ")
rng = int(math.log2(np.max(A)))+1
sum = 0
for bit in range(rng):
    c = int((A & 1).sum())
    sum += c *(n-c)*(1<<bit)
    A = A>>1

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

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n = int(input())
A = np.fromstring(input(),dtype=np.int64,sep=" ")
rng = int(math.log2(np.max(A)))+1
sum = 0
for bit in range(60):
    c = int((A & 1).sum())
    sum += c *(n-c)*(1<<bit)
    A = A>>1

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

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n = int(input())
A = np.fromstring(input(),dtype=np.int64,sep=" ")
rng = int(math.log2(np.max(A)))+1
sum = 0
for bit in range(rng):
    c = (A & 1).sum()
    sum += c *(n-c)*(2**bit)
    A = A>>1

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

Submission status: Runtime Error

Solution code:
import math

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

ans = 0
a_max = max(a)
alog = int(math.log2(a_max))+1

for i in range(alog):
    cnt0 = 0
    cnt1 = 0
    for j in a:
        p = pow(2, i)
        cnt1 += ((j & p) == p)
        cnt0 += ((j & p) == 0)
    ans += (cnt0 * cnt1)*(2**i)%(10**9+7)

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

Submission status: Runtime Error

Solution code:
"""
今回の問題（AtcoderのランクDの問題）
→sum_{i=1}^{N-1} sum_{j=i+1}^{N} (A_{i} XOR A_{k}) = ? (mod 10^{9} + 7)
"""

# 方針を立てる
"""
①：まず、2つの変数で和をとるようにするので、これは配列を用意して行列を
　　作る（Numpyモジュールの利用）
②：あまりに関しては、10^{9}+7を何か変数に格納しておいて計算すれば良い。
③：排他的論理和に関しては、各和に対して2で割ったあまりの判定を行なって、
　　それを改めて格納することにする（for文での繰り返し処理で一旦補う。）

このアルゴリズムによって今回のプログラムを作成していく。
"""

import numpy as np
from tqdm import tqdm

divided_num = 10^9 + 7
nums = int(input())  # 入力される数字の個数を入力している。
input_nums = input().split(" ")  # これにて、入力された数字を格納する。
input_nums2 = input_nums  # 二つの計算をするので、もう一つコピーを作っておく。

xor_result = []  # 排他的論理和の計算を格納しておく場所

for j in tqdm(range(0, len(input_nums2)-1)):
  #print('Wait...')
  for i in tqdm(range(j, len(input_nums))):
    xor_input_nums = []
    xor_input_nums2 = []
    # ここで、対象の2つの数字を二進表記にする。
    a = int(input_nums[i])
    while a >= 2:
      xor_input_nums.append(a%2)  # 2進法の配列を作成（ただし、ここでは逆順になっている。）
      a = int(a / 2)  # 2で割った時の整数部分を格納する。
    b = int(input_nums2[j])
    while b >= 2:
      xor_input_nums2.append(b%2)
      b = int(b / 2)  # 2で割った時の整数部分を格納する。
 """
 2進法での表記を格納したので、ここからはif文
 によって排他的論理和の計算を行う。
 """
    if len(xor_input_nums) != len(xor_input_nums2):
      if len(xor_input_nums) > len(xor_input_nums2):
          for n in range(0,len(xor_input_nums)-len(xor_input_nums2)):
              xor_input_nums2.append(0)
      else:
          for n in range(0,len(xor_input_nums2)-len(xor_input_nums)):
              xor_input_nums.append(0)
        
  xor_suc_array = []
  #print('Wait...')
  for p in tqdm(range(0, len(xor_input_nums2))):
      xor_suc_array.append((int(xor_input_nums[p]) + int(xor_input_nums2[p])) % 2)  # 排他的論理和の計算の結果
  l = 0
  m = 0
  for k in xor_suc_array:
      m += k * (2^l)
      l += 1
  xor_result.append(m)

sums = np.sum(xor_result)
print(sums % divided_num)

Submission status: Runtime Error

Solution code:
import numpy as np
from tqdm import tqdm

divided_num = 10^9 + 7
nums = int(input())  # 入力される数字の個数を入力している。
input_nums = input().split(" ")  # これにて、入力された数字を格納する。
input_nums2 = input_nums  # 二つの計算をするので、もう一つコピーを作っておく。

xor_result = []  # 排他的論理和の計算を格納しておく場所

for j in tqdm(range(0, len(input_nums2)-1)):
    print('Wait...')
    for i in tqdm(range(j, len(input_nums))):
        xor_input_nums = []
        xor_input_nums2 = []
        # ここで、対象の2つの数字を二進表記にする。
        a = int(input_nums[i])
        while a >= 2:
            xor_input_nums.append(a%2)  # 2進法の配列を作成（ただし、ここでは逆順になっている。）
            a = int(a / 2)  # 2で割った時の整数部分を格納する。
        b = int(input_nums2[j])
        while b >= 2:
            xor_input_nums2.append(b%2)
            b = int(b / 2)  # 2で割った時の整数部分を格納する。
        """
        2進法での表記を格納したので、ここからはif文
        によって排他的論理和の計算を行う。
        """
        if len(xor_input_nums) != len(xor_input_nums2):
            if len(xor_input_nums) > len(xor_input_nums2):
                for n in range(0,len(xor_input_nums)-len(xor_input_nums2)):
                    xor_input_nums2.append(0)
            else:
                for n in range(0,len(xor_input_nums2)-len(xor_input_nums)):
                    xor_input_nums.append(0)
        
        xor_suc_array = []
        print('Wait...')
        for p in tqdm(range(0, len(xor_input_nums2))):
            xor_suc_array.append((int(xor_input_nums[p]) + int(xor_input_nums2[p])) % 2)  # 排他的論理和の計算の結果
        l = 0
        m = 0
        for k in xor_suc_array:
            m += k * (2^l)
            l += 1
        xor_result.append(m)

sums = np.sum(xor_result)
print(sums % divided_num)

Submission status: Runtime Error

Solution code:
"""
今回の問題（AtcoderのランクDの問題）
→sum_{i=1}^{N-1} sum_{j=i+1}^{N} (A_{i} XOR A_{k}) = ? (mod 10^{9} + 7)
"""

# 方針を立てる
"""
①：まず、2つの変数で和をとるようにするので、これは配列を用意して行列を
　　作る（Numpyモジュールの利用）
②：あまりに関しては、10^{9}+7を何か変数に格納しておいて計算すれば良い。
③：排他的論理和に関しては、各和に対して2で割ったあまりの判定を行なって、
　　それを改めて格納することにする（for文での繰り返し処理で一旦補う。）

このアルゴリズムによって今回のプログラムを作成していく。
"""

import numpy as np
from tqdm import tqdm

divided_num = 10^9 + 7
nums = int(input())  # 入力される数字の個数を入力している。
input_nums = input().split(" ")  # これにて、入力された数字を格納する。
input_nums2 = input_nums  # 二つの計算をするので、もう一つコピーを作っておく。

xor_result = []  # 排他的論理和の計算を格納しておく場所

for j in tqdm(range(0, len(input_nums2)-1)):
    print('Wait...')
    for i in tqdm(range(j, len(input_nums))):
        xor_input_nums = []
        xor_input_nums2 = []
        # ここで、対象の2つの数字を二進表記にする。
        while int(input_nums[i]) >= 2:
            a = int(input_nums[i])
            xor_input_nums.append(a%2)  # 2進法の配列を作成（ただし、ここでは逆順になっている。）
            a = int(a / 2)  # 2で割った時の整数部分を格納する。
        while int(input_nums2[j]) >= 2:
            b = int(input_nums2[j])
            xor_input_nums2.append(b%2)
            b = int(b / 2)  # 2で割った時の整数部分を格納する。
        """
        2進法での表記を格納したので、ここからはif文
        によって排他的論理和の計算を行う。
        """
        if len(xor_input_nums) != len(xor_input_nums2):
            if len(xor_input_nums) > len(xor_input_nums2):
                for n in range(0,len(xor_input_nums)-len(xor_input_nums2)):
                    xor_input_nums2.append(0)
            else:
                for n in range(0,len(xor_input_nums2)-len(xor_input_nums)):
                    xor_input_nums.append(0)
        
        xor_suc_array = []
        print('Wait...')
        for p in tqdm(range(0, len(xor_input_nums2))):
            xor_suc_array.append((int(xor_input_nums[p]) + int(xor_input_nums2[p])) % 2)  # 排他的論理和の計算の結果
        l = 0
        m = 0
        for k in xor_suc_array:
            m += k * (2^l)
            l += 1
        xor_result.append(m)

sums = np.sum(xor_result)
print(sums % divided_num)

Submission status: Runtime Error

Solution code:
import numpy as np

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

na = np.array(a)

mat = np.bitwise_xor(na.reshape(N,1),na)

print(sum(sum(mat))//2%(10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np

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

na = np.matrix(a)

mat = np.bitwise_xor(na.T,na)

mat_lst = list(mat)

print(((mat.sum())//2)%(10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np

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

na = np.matrix(a)

mat = np.bitwise_xor(na.T,na)

print(((mat.sum())//2)%(10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np

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

na = np.matrix(a)

mat = np.bitwise_xor(na.T,na)

print((np.sum(mat)//2)%(10**9+7))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
m=math.ceil(math.log(max(a),2))

ans=0
for i in range(m):
  sum0=0
  sum1=0
  for j in range(n):
    if (a[j]>>i)&1:
      sum1+=1
    else:
      sum0+=1
  ans+=2**i*sum1*sum0
print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = ("{:060b}".format(_a) for _a in a)
    m = 10**9 + 7
    ans = 0
    for s in map(str.count("1"), zip(*a)):
        ans <<= 1
        ans += s * (n - s)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Runtime Error

Solution code:
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    *s, = map(lambda x: x.count("1"), zip(*a))
    return str(sum(s * (n - _s) * pow(2, 59 - i, m) for i, _s in enumerate(s)) % m)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

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

    mod = 10 ** 9 + 7

    a_bin = [format(i, 'b') for i in a]

    m = len(max(a_bin, key = len))

    ans = 0

    for i in range(n):
        a_bin[i] = '0' * (m - len(a_bin[i])) + a_bin[i]

    for i in range(1, m+1):
        count = [0, 0]
        for j in a_bin:
            count[int(j[-i])] += 1
        ans += count[0] * count[1] * 2 ** (i-1)

    print(ans % mod)

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

    a = np.array(a)
    ans = 0
    mod = 10**9 + 7

    for i in range(60):
        count = np.count_nonzero(a & 1)
        ans += count * (n - count) * 2 ** i
        a >>= 1

    print(ans % mod)

if __name__ == '__main__':
    main2()

Submission status: Runtime Error

Solution code:
import numpy as np
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
A = np.array(A, dtype = np.int64)
tmp = 0
for i in range(61):
    tmp_1 = np.count_nonzero
    tmp += ((tmp_1)*(N - tmp_1)*(2**i)) % mod
    A = A >> 1
print(tmp % mod)

Submission status: Runtime Error

Solution code:
N = 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: Runtime Error

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

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

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

dst = xor_sum % (10**9+7)
print(dst)

Submission status: Runtime Error

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


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

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

dst = xor_sum % (10**9+7)
print(dst)

Submission status: Runtime Error

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


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

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

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

Submission status: Runtime Error

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


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

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

Submission status: Runtime Error

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


N = input()
A = input().split()

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

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

Submission status: Runtime Error

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


N = input()
A = [input().split() for i in range(N)]

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

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

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()])
c = np.reshape(a, (len(a), 1))

print(int(np.sum(a^c)/2)%(10**9 + 7))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()], dtype = 'int64')
c = np.reshape(a, (len(a), 1))

print(int(np.sum(a^c)/2)%(10**9 + 7))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()], dtype = 'int64')
c = np.reshape(a, (len(a), 1))

print(int(np.sum(a^c)/2))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()], dtype = 'int64')
c = np.reshape(a, (3, 1))

print(int(np.sum(a^c)/2))

Submission status: Runtime Error

Solution code:

sum = 0
num = input()
list = [int(i) for i in input().split()]

#list2 = [3,1,4,1,5,9,2,6,5,3]
#list2 = [1,2,3]

for i in range(num):
    for j in range(i+1,num):
        sum += list[i]^list[j]
print(sum % 1000000007)

Submission status: Runtime Error

Solution code:
N = int(input())
from collections import defaultdict
d = defaultdict(int)
for i in map(int,input().split()):
  for idx,j in enumerate(reversed('{:b}'.format(i))):
    if j == "1":
      d[idx]+=1

m = max( set(d.keys()) )
print(int(sum([((2**i)* (N-d[i])*d[i])%(1e9+7) for i in range(m+1)])%(1e9+7)))

Submission status: Runtime Error

Solution code:
N = int(input())
from collections import defaultdict
d = defaultdict(int)
for i in map(int,input().split()):
  for idx,j in enumerate(reversed('{:b}'.format(i))):
    if j == "1":
      d[idx]+=1

m = max( set(d.keys()) )

A=1
res=0
for i in range(m+1):
  res += (A* (N-d[i])*d[i])%(1e9+7) 
  A = int((A*2) %(1e9+7))
  
print(int(res%(1e9+7)))

Submission status: Runtime Error

Solution code:
nums = int(input())
a = list(map(int, input().split(" ")))
xor = 0

for i in range(0, nums - 1):
    for j in range(i + 1, nums):
       xor += a[i] ^ a[j]

print(xor / (7 + 1000000000)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a=int(input())
n=list(map(int,input().split()))
mod=10**9+7
import numpy as np
a=np.array(a)
md = len(bin(max(a)))
ans = 0
for d in range(md):
    cnt1 = np.count_nonzero((a>>d)&1)
    ans += cnt1 * (n-cnt1) * (1<<d)
    ans %= mod

print(ans%mod)

Submission status: Runtime Error

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

for i in range(60):
    zeroCnt = 0
    oneCnt = 1
    
    for j in range(n):
        if (a[j] >> i) & 1 == 1:
            oneCnt += 1
        else:
            zeroCnt += 0
    ans += zeroCnt * oneCnt * pow(2, i, mod)
    ans %= mod

pirnt(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	ll MOD = 1e9 + 7;
	ll ans = 0LL;
	for(ll i = 0LL; i < 62; i++){
		vector<vector<ll>> v(n+1, vector<ll>(2, 0LL));
		for(ll j = n-1; j >= 0; j--){
			ll x = (a[j] >> i) & 1LL;
			v[j][x] = v[j+1][x] + 1LL;
			v[j][1-x] = v[j+1][1-x];
		}

		// rep(i, n+1) rep(j, 2) cout << v[i][j] << (j == 1 ? "\n" : " ");

		ll t = 0LL;
		rep(j, n-1){
			ll x = (a[j] >> i) & 1LL;
			t += v[j+1][1-x];
			t %= MOD;
		}

		// cout << b << " " << t << endl;
		ll b = 1LL << i;
		b %= MOD;
		ll y = t * b;
		y %= MOD;
		ans += y;
		ans %= MOD;
	}

	cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
import sys
mod = int(1e9+7)
input=sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2

for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*pow(2, idx, mod)%mod

        else:
            ans += S[i+1][idx]*pow(2, idx, mod)%mod

        idx += 1
        tmp //= 2
        ans %= mod

    rest = S[i+1][idx:]
    for x in rest:
        ans += xpow(2, idx, mod)%mod
        idx += 1
        ans %= mod

print(ans)

Submission status: Runtime Error

Solution code:
#ABC147_D
#N個の数字から2個選ぶの全組み合わせのXORを足してmodする問題

import numpy as np

N = int(input())
arr = np.array([int(i) for i in input().split()])
ans = 0
mod=10**9+7


for i  in range(60):
    c1=np.count_nonzero(arr&1)#arrの最下位bitの論理和。arrの最下位bitが1の数をカウント
    c0=n-c1#arrの最下位bitが0の数
    ans+=2**i*c1*c0#c1個の中から1つ選ぶ組み合わせとc0個の中から1つ選ぶ組み合わせの掛け算が、該当bitがXOR＝１となる組み合わせの数
    arr>>=1#最下位bitを変更
print(s%mod)

Submission status: Runtime Error

Solution code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=0
    temp=0
    MOD=10**9+7
    leng=0
    bin_a=[[0] * n for i in range(60)]
    for i in range(n):
        tmp=str(bin(a[i]))
        # print(a[i])
        # print(len(tmp))
        leng=max(leng,len(tmp))
        for j in range(len(tmp)-2):
            if tmp[len(tmp)-j-1] == 'b':
                break
            # print(tmp[len(tmp)-i-1])
            bin_a[j][i]=int(tmp[len(tmp)-j-1])

    for i in range(leng):
        cnt1=sum(bin_a[i])
        cnt0=n-cnt1
        ans+=cnt1*cnt0*2**i%MOD
    print(ans%MOD)

if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())

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

m = len(bin(max(a))) - 2

ans = 0
for i in range(60):
    k = 1 << i
    i_1 = sum([k & a for a in ass]) >> i
    ans += i_1 * (n - i_1) << i
    ans = ans % ((10**9) + 7)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.fromstring(input(), np.int64, ' ')

result = 0
for bit in range(60):
    c = int((A & 1).sum())
    A >>= 1
    result = (result + c * (N - c) * (1 << bit)) % 1000000007
print(result)

Submission status: Runtime Error

Solution code:
import sys
from math import ceil, log2

input = sys.stdin.readline

def main():
    MOD = 10**9 + 7
    
    N = int(input())
    A = list(map(int, input().split()))
    K = ceil(log2(max(A)))
    
    nums = [[0,0] for i in range(K)]
    ks = [(i, 2**i) for i in range(K)]
    
    A_ = [[] for i in range(N)]
    
    for i, a in enumerate(A):
        for j, k in ks:
            n = a & k > 0
            A_[i].append(n)
            nums[j][n] += 1
            
    ans = 0
    
    for a in A_:
        for i, n in enumerate(a):
            nums[i][n] -= 1
            ans += ks[i][1] * nums[i][not n] % MOD
            
    print(ans%MOD)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.fromiter(map(int, input().split()))

result = 0
for b in range(60):
  bs = int(((A >> b) & 1).sum())
  result = (result + bs * (N - bs) * (1 << b)) % 1000000007
print(result)

Submission status: Runtime Error

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

result = 0
for b in range(60):
  bs = sum((e >> b) & 1 for e in A)
  result = (result + bs * (N　- bs) * (1 << b)) % 1000000007
print(result)

Submission status: Runtime Error

Solution code:
imoprt numpy as np 
n = int(input())
A = list(map(int,input().split()))
a=np.array(A)
mod = 10**9+7
md = len(bin(max(a)))
ans = 0
for d in range(md):
    cnt1 =np.count_nonzero(a)        
    ans += cnt1 * (n-cnt1) * (1<<d)         
    ans %= mod                              
    
print(ans%mod)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# from heapq import heappush, heappop, heapify
# from collections import deque, defaultdict, Counter
# import itertools
# from itertools import permutations, combinations, accumulate
import sys
# import bisect
# import string
# import math
# import time
# from fractions import gcd
#import random


def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False

# xor
# n + i = n ^ i implies n & i = 0


# def sumXOR(arr,  n):
#     _sum = 0
#     for i in range(0, 64):
#         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)
#         print(zc, oc, idsum)

#         # final sum
#         _sum = _sum + idsum
#         _sum %= MOD

#     return _sum


def main():
    N = I()
    A = list(MI())
    BIT = 61
    C = [[0] * (N+1) for i in range(BIT)]
    ans = 0

    for i in range(N):
        for j in range(BIT):
            bit = 1 << j
            if A[i] & bit:
                C[j][i+1] = C[j][i] + 1
            else:
                C[j][i+1] = C[j][i]

    for i in range(N):
        for j in range(BIT):
            oc = C[j][N] - C[j][i]
            bit = 1 << j
            # print('b', ans, i, j, bit, oc)
            if A[i] & bit:
                zc = N - i - oc
                ans += bit * zc
            elif oc != 0:
                ans += bit * oc
            ans %= MOD
            # print('a', ans, i, j, bit, oc)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]
A = np.array(A)
B = A[:, np.newaxis]
x = (np.sum(np.sum(A^B, axis=1))) // 2
print(x % (10**9 + 7))

Submission status: Runtime Error

Solution code:
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


length = int(fetch_one_line())
nums = fetch_int_input()

bit_nums = [bin(i)[2:] for i in nums]
max_length = max([len(i) for i in bit_nums])

bit_nums = [list(i.zfill(max_length)) for i in bit_nums]
bit_nums = list(zip(*bit_nums))
sum_ones = [lst.count("1") for lst in bit_nums]
sum_zeros = [length - o for o in sum_ones]
multiples = [i * (length - i) for i in zip(sum_ones)]

result = sum([pow(2, i) * m for i, m in enumerate(reversed(multifrom sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


length = int(fetch_one_line())
nums = fetch_int_input()

bit_nums = [bin(i)[2:] for i in nums]
max_length = max([len(i) for i in bit_nums])

bit_nums = [list(i.zfill(max_length)) for i in bit_nums]
bit_nums = list(zip(*bit_nums))
sum_ones = [lst.count("1") for lst in bit_nums]
sum_zeros = [length - o for o in sum_ones]
multiples = [i * (length - i) for i in sum_ones]

result = sum([pow(2, i) * m for i, m in enumerate(reversed(multiples))])
print(result % (pow(10, 9) + 7))

ples))])
print(result % (pow(10, 9) + 7))

Submission status: Runtime Error

Solution code:
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


length = int(fetch_one_line())
nums = fetch_int_input()

bit_nums = [bin(i)[2:] for i in nums]
max_length = max([len(i) for i in bit_nums])

bit_nums = [list(i.zfill(max_length)) for i in bit_nums]
bit_nums = list(zip(*bit_nums))
sum_ones = [lst.count("1") for lst in bit_nums]
sum_zeros = [length - o for o in sum_ones]
multiples = [i * (length - i) for i in zip(sum_ones)]

result = sum([pow(2, i) * m for i, m in enumerate(reversed(multiples))])
print(result % (pow(10, 9) + 7))

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split()))
mod = 10 ** 9 + 7
ans = 0
m = 1　#1の桁のbitからスタート
for _ in range(60):
    bit = sum(a & m for a in x) #フラグが立ってる桁を合計
    bit //= m #1の個数を数えるためにmで割る
    non_bit = n - bit #0の個数を出す
    ans = (ans + bit * non_bit * m) % mod #桁の合計出す
    m <<= 1 #桁を1増やす
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a = map(int, input().split())
A = list(a)
OB = [[0 for i in range(61)] for j in range(N)]

def sumup(num):
    if num == 0:
        return 0
    else:
        return (num + sumup(num-1))

XOR = [[0 for i in range(61)] for j in range(sumup(N-1))]

for n in range(N):
    m = 0
    while A[n] > 0:
        OB[n][60-m] = A[n]%2
        A[n] = A[n]//2
        m = m+1

xor = 0
for n in range(0,(N-1)):
    for k in range(1,(N-n)):
        for m in range(61):
            if abs(OB[n][60-m]-OB[n+k][60-m]) == 1:
                XOR[xor][60-m] = 1
            else:
                XOR[xor][60-m] = 0
        xor = xor+1

summary = 0
for j in range(sumup(N-1)):
    for i in range(61):
        summary = summary + XOR[j][60-i]*(2**(i))
print(summary%(10**9+7))

Submission status: Runtime Error

Solution code:
import numpy as np

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

mod = 10 ** 9 + 7

ans = 0
for i in range(60):
    c1 = np.count_nonzero(arr & 1)
    ans += 2 ** i * c1 * (n - c1)
    arr >>= 1

print(ans%mod)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))
digit = math.floor(math.log2(max(A))) + 1

ans = 0
fil = 1
for i in range(digit):
    num1 = len([1 for j in range(N) if A[j] & fil])
    num0 = N - num1
    ans += (num1 * num0) * fil
    fil <<= 1

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

Submission status: Runtime Error

Solution code:
import math

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

digit = math.floor(math.log2(max(A))) + 1

ans = 0
for i in range(digit):
    num1 = len([1 for j in range(N) if A[j] & 2**i])
    num0 = N - num1

    ans += ((num1 * num0) * (2 ** i))

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

Submission status: Runtime Error

Solution code:
import math

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

digit = math.floor(math.log2(max(A))) + 1
bin_A = [format(Ai, '0' + str(digit) + 'b') for Ai in A]

ans = 0

for i in range(digit):
    num0 = 0
    num1 = 0
    for j in range(N):
        if bin_A[j][i] == '1':
            num1 += 1
        else:
            num0 += 1
    ans += ((num1 * num0) * (2**(digit-i-1))) % (10**9+7)

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

Submission status: Runtime Error

Solution code:
import math

N = int(input())
A = list(map(lambda x: int(x)%(10**9+7), input().split()))

digit = math.floor(math.log2(max(A))) + 1
bin_A = [format(Ai, '0' + str(digit) + 'b') for Ai in A]

ans = 0

for i in range(digit):
    num0 = 0
    num1 = 0
    for j in range(N):
        if bin_A[j][i] == '1':
            num1 += 1
        else:
            num0 += 1
    ans += (num1 * num0) * (2**(digit-i-1))

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