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:
import itertools

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

s = 0

for i in range(61):
    z ,o = 0
    for n in l:
        if (n >> i)%2 == 0:
            z += 1
        else:
            o += 1
    s += (z*o)*(2**i)
    s = s % (10**9+7)

print(s)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct ModInt {
  using M = ModInt;
  long long v;
  ModInt(long long _v = 0) : v(_v % MOD + MOD) { norm(); }
  M& norm() {
    v = (v < MOD) ? v : v - MOD;
    return *this;
  }
  M operator+(const M& x) const { return M(v + x.v); }
  M operator-(const M& x) const { return M(v + MOD - x.v); }
  M operator*(const M& x) const { return M(v * x.v % MOD); }
  M operator/(const M& x) const { return M(v * x.inv().v); }
  M& operator+=(const M& x) { return *this = *this + x; }
  M& operator-=(const M& x) { return *this = *this - x; }
  M& operator*=(const M& x) { return *this = *this * x; }
  M& operator/=(const M& x) { return *this = *this / x; }
  friend istream& operator>>(istream& input, M& x) {
    return input >> x.v, x.norm(), input;
  }
  friend ostream& operator<<(ostream& output, const M& x) {
    return output << x.v;
  }
  M pow(long long n) const {
    M x(v), res(1);
    while (n) {
      if (n & 1) res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  M inv() const { return this->pow(MOD - 2); }
  // M inv() const {
  //   int x, y;
  //   extgcd(this->v, MOD, x, y);
  //   return *this + M(x);
  // }

  static long long MOD;
  static vector<M> fact, finv;
  static void build(int n) {
    fact.assign(n + 1, 1);
    for (int i = 1; i < n + 1; i++) fact[i] = fact[i - 1] * M(i);
    finv.assign(n + 1, fact[n].inv());
    for (int i = n; i > 0; i--) finv[i - 1] = finv[i] * M(i);
  }
  static M comb(int n, int k) {
    if (n < k || k < 0) return M(0);
    return fact[n] * finv[n - k] * finv[k];
  }
  static M extgcd(int a, int b, int* x, int* y) {
    M d(a);
    if (b) {
      d = extgcd(b, a % b, y, x);
      *y -= (a / b) * *x;
    } else {
      *x = 1, *y = 0;
    }
    return d;
  }
};
vector<ModInt> ModInt::fact = vector<ModInt>();
vector<ModInt> ModInt::finv = vector<ModInt>();
long long ModInt::MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<int>> o(120, vector<int>(n + 1, 0));
  vector<vector<int>> x(120, vector<int>(n + 1, 0));
  for (int b = 0; b < 120; b++) {
    for (int i = 0; i < n; i++) {
      o[b][i + 1] += o[b][i];
      x[b][i + 1] += x[b][i];
      if (a[i] >> min(60, b) & 1) {
        o[b][i + 1]++;
      } else {
        x[b][i + 1]++;
      }
    }
  }
  vector<ll> v(120);
  ll nxt = 0;
  for (int b = 0; b < 120; b++) {
    ll c = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] >> min(60, b) & 1) {
        c += x[b][i];
      } else {
        c += o[b][i];
      }
    }
    v[b] = (nxt + c) % 2;
    nxt = (nxt + c) / 2;
  }
  ModInt ans = 0;
  for (int b = 119; b >= 0; b--) {
    ans *= 2;
    ans += v[b];
  }
  cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
An = list(map(int,input().split(' '))) 

bit_list = [1]
for i in range(100000):
    bit_list.append(bit_list[i]*2)
    if bit_list[i+1] > 10**12:
        break
start_point = bisect.bisect_right(bit_list,max(An))
keta_list = [0] * start_point

for A in An:
    abin = format(A, 'b')
    for i in range(len(abin)):
        if abin[i] == '1':
            keta_list[len(abin)-1-i] += 1
count = 0
for idx,keta_count in enumerate(keta_list):
    count += (N-keta_count) * bit_list[idx] * keta_count
    count = count % (1000000000+7)
print(count)

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
An = list(map(int,input().split(' '))) 

bit_list = [1]
for i in range(100000):
    bit_list.append(bit_list[i]*2)
    if bit_list[i+1] > 10**12:
        break
start_point = bisect.bisect_left(bit_list,max(An))
keta_list = [0] * start_point

for A in An:
    abin = format(A, 'b')
    for i in range(len(abin)):
        if abin[i] == '1':
            keta_list[len(abin)-1-i] += 1
count = 0
for idx,keta_count in enumerate(keta_list):
    count += (N-keta_count) * bit_list[idx] * keta_count % (1000000000+7)
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
sum=0
for i in range(len(a)-1):
  b=[int(a[k]) for k in range(n-1) if k!=i]
  for j in range(len(b)-1):
    n=(bin(a[i]^b[j]).format(18))
    sum+=n
print(sum)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
b = 0
num = 1000000007
N_1 = N.pop(-1)
N_2 = N.pop(0)
for i in N_1:
    for j in N_2:
        b += N_1 ^ N_2
print(b%num)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(_) for _ in input().split()]
b = []
ans = 0
for i in range(1,n):
    q = a[0] ^ a[i]
    b.append(q)
    ans += q
b = sorted(b)
s_b = [0] * n
for i in range(n-1):
    s_b[i+1] = b[i] + s_b[i]
for i in range(n-2):
    ans += s_b[n] - s_b[i+1] * (n-i)
print(ans)

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
An = list(map(int,input().split(' '))) 

bit_list = [1]
for i in range(100000):
    bit_list.append(bit_list[i]*2)
    if bit_list[i+1] > 10**12:
        break
start_point = bisect.bisect_right(bit_list,An[-1])
keta_list = [0] * start_point

for A in An:
    abin = format(A, 'b')
    for i in range(len(abin)):
        if abin[i] == '1':
            keta_list[len(abin)-1-i] += 1
count = 0
for idx,keta_count in enumerate(keta_list):
    count += (start_point-keta_count) * bit_list[idx] % (1000000000+7)
print(count)

Submission status: Runtime Error

Solution code:
int_i = int(input())
    # int_i = 10
    result = 0
    s_x = input().split(' ')
    # s_x = '3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820'.split(' ')
    # i_x = list([int(n) for n in s_x])
    for x,y in enumerate(s_x):
        for z in s_x[x:]:
            result += int(bin(int(y) ^ int(z)), 2)
    # for i in range(int_i):
    #     for hoge in i_x[i + 1:]:
    #         if i_x[i] == hoge:
    #             continue
    #         result += int(bin(i_x[i] ^ hoge), 2)
    print(result % (10 ** 9 + 7))

Submission status: Runtime Error

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

    print(sum(int(ans,2))%(10**9 + 7))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


def xor(x, y):
    X = bin(max(x, y))
    Y = bin(min(x, y))
    w = int(X) ^ int(Y)

    return int(w, 2)


for i in itertools.combinations(a, 2):
    Ans = Ans + xor(i[0], i[1])

print(Ans % mod)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
import numpy as np

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

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

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

Submission status: Runtime Error

Solution code:
def two(number):
    c0 = 0
    while number >=2:
        number = number //2
        c0 += 1
    return c0

def binary_system(number):
    digit = two(number)
    n = '1'
    if number == 2:
        n = '10'
    else:
        for i in range(1,digit+1):
            number = number - 2**digit
            if two(number) == digit - i:
                n = n + '1'
            else:
                n = n + '0'
            digit = digit - 1
    print(int(n))

def xor(num10,num20):
    #num1,num2は文字列
    l1 = len(num10)
    l2 = len(num20)
    l = max(l1,l2)
    num1 = list(num10)
    num2 = list(num20)
    if l1 < l2:
        num1.insert(0,'0'*(l2-l1))
    elif l2 < l1:
        num2.insert(0,'0'*(l1-l2))
    for i in range(l):
        if num1[i] == num2[i]:
            num1[i] = '0'
        else:
            num1[i] = '1'
    num1 = "".join(num1)
    print(num1)

n = input()
l = input().split()
for i in range(n):
    l[i] = two(l[i])
c = 0
for i in range(n):
    for j in range(n):
        c = c + xor(l[i],l[j])

a = c % ((10**9)+ 7 )
print (a)

Submission status: Runtime Error

Solution code:
import numpy as np
 
mod = 10**9 + 7
N = input()
A = np.array(list(map(int, input().split())))
A = np.atleast_2d(A)

print((np.sum((A ^ A.T) % mod) % mod) // 2)

Submission status: Runtime Error

Solution code:
import sys

N = int(sys.stdin.readline())
A = tuple(map(int, sys.stdin.readline().split()))
B = []
ans = 0
for i in A:
    B.append(list(bin(i)[2:]))
C = (0 for i in range(60))
for i in B:
    for l in range(len(i)):
        if i[-(l+1)] == '1':
            C[l] += 1
for i in range(60):
    ans = (ans + C[i]*(N-C[i])*(2**i))%(10**9+7)
print(ans)

Submission status: Runtime Error

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

n = int(input())
a = list(map(int, input().split( )))
a = array.array("i",a)
ans = 0
mod = 10**9+7
Bit = [[0]*2 for j in range(60)]# for i in range(n+1)

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

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

Submission status: Runtime Error

Solution code:
mod = int(1e9 + 7)
N = int(input())
A = list(map(int, input().split()))
S = 0
j = 0
while A != []:
  m = 0
  n = len(A)
  k = []
  for i in range(n):
    if A[i] % 2 == 1:
      m += 1
    A[i] //= 2
    if A[i] == 0:
      k.append(i)
  for g in range(len(k)):
    A.remove(k[len(k)-1-g])
  S += (m * (N - m)) * (2 ** j)
  S %= mod
  j += 1
print(S)

Submission status: Runtime Error

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


def xor(x, y):
    X = bin(max(x, y))
    Y = bin(min(x, y))
    w = X ^ Y

    return int(w, 2)


for i in itertools.combinations(a, 2):
    Ans = Ans + xor(i[0], i[1])

print(Ans % mod)

Submission status: Runtime Error

Solution code:
import math

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

m = int(math.log2(max(a))) + 1

total = 0
num = 1
while True:
    if num == n:
        break
    p, q = 0, 0
    for i in range(0, n - num):
        p += (a[i] << m * (n-num-i-1)) % 1000000007
        q += a[num + i] << m * (n-num-i-1) % 1000000007
    r = p ^ q
    for i in range(0, n - num):
        total += r % (2 ** m)
        r = r >> m
    num += 1

print(total % 1000000007)

Submission status: Runtime Error

Solution code:
import numpy as np

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

pure_total = sum(As)
# pure_total = 0

sabun_mat = np.zeros((N, 60), np.int)

# exp2total = {}
for i in range(60):
    tmp_total = 0
    for j, a in enumerate(As[::-1]):
        tmp_total += (2**i ^ a) - a
        sabun_mat[N-1-j, i] = tmp_total
    # exp2total[i] = tmp_total

# print(sabun_mat)
total = 0
for i, a in enumerate(As[:-1]):
    pure_total -= a
    total += pure_total
    # print(bin(a))
    for j,b in enumerate(bin(a)[2:][::-1]):
        # print("b",b)
        # print("type", type(b))
        if b == "1":
            total += sabun_mat[i+1, j]
            # print(sabun_mat[i, j])
            # print()

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

Submission status: Runtime Error

Solution code:
N = int(input())

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

for i in range(0, N):
    for q in range(i, N):
        count += int(AList[i] ^ AList[q])
print(count % (10 ** 9 + 7))

Submission status: Runtime Error

Solution code:
import itertools
import scipy.misc as scm

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

loopnum = scm.comb(n, 2, exact=True)
c = itertools.combinations(nums, 2)
ans=[]
for i in range(loopnum):
  temp = next(c)
  ans.append(temp[0]^temp[1])
sum= sum(ans)
print(sum%(10**9+7))

Submission status: Runtime Error

Solution code:
import math
import numpy as np
n = int(input())
a = list(map(int, input().split()))

dgt = int(math.sqrt(max(a)))+1
dp = np.zeros(dgt)

for i in range(n):
    k = np.array(list( bin(a[i])[2:].zfill(dgt)), dtype=int)
    dp += k

res = 0
for i in range(dgt):
    if dp[-i-1] > 0:
        res += 2**i*int(dp[-i-1])*int(n-dp[-i-1]) % (10**9+7)
print(res)

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
a = list(map(int, input().split()))
a.reverse()
mod = 7 + 10**9
leng = 61
data = [[0 for i in range(leng+1)]for j in range(n)]
#pre
for i in range(n):
    k = deque(bin(a[i]))
    k.reverse()
    for j in range(1, leng+1):
        if j - 1 >= len(k):
            data[i][j] = data[i - 1][j]
            continue
        if k[j - 1] == "1":
            data[i][j] = data[i - 1][j] + 1
        else:
            data[i][j] = data[i-1][j]
ans = 0
a.reverse()
data.reverse()
for i in range(n-1):
    k = deque(bin(a[i]))
    k.reverse()
    k.pop()
    k.pop()
    k = deque((map(int, k)))
    k = k + deque([0 for i in range(leng - len(k))])
    for j in range(leng):
        if k[j] == 1:
            ans += ((n - i - 1) - data[i+1][j+1]) * (2**j)
            ans %= mod
        else:
            ans += data[i+1][j+1] * (2**j)
            ans %= mod
print(ans)

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

m = int(math.log2(max(a))) + 1

total = 0
num = 1
while True:
    if num == n:
        break
    p, q = 0, 0
    for i in range(0, n - num):
        p += a[i] << m * (n-num-i-1)
        q += a[num + i] << m * (n-num-i-1)
    r = p ^ q
    for i in range(0, n - num):
        total += (r % (2 ** m)) % 1000000007
        r = r >> m
    num += 1

print(total % 1000000007)

Submission status: Runtime Error

Solution code:
import numpy as np
 
mod = 10**9 + 7
N = input()
A = np.array(list(map(int, input().split())), dtype='uint64') % mod
A = np.atleast_2d(A)

print((np.sum((A ^ A.T) % mod) % mod) // 2)

Submission status: Runtime Error

Solution code:
import math

p = 10 ** 9 + 7

def comb(n):
  if n < 2:
    return(0)
  else:
    a = n % p
    b = (n-1) % p
    c = int((a * b / 2)) % p
    return(c)

n = input()
n = int(n)
a = input().split(" ")

a = [int(i) for i in a]

bmax = math.ceil(math.log2(max(a)))

r = 0

for j in range(bmax):
  b = [k>>j & 1 for k in a] # 各ビットを取り出す
  n_one = sum(b)
  n_zero = n - n_one
  r_tmp = comb(n) - (comb(n_zero) + comb(n_one))
  r_tmp = r_tmp << j
  #b_tmp = (2 ** j) % p
  r = (r + r_tmp) % p
  
print(r)

Submission status: Runtime Error

Solution code:
import numpy as np

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

def xor_(x, y):
    p, q = tuple(sorted([x, y]))
    p = np.array(list(bin(p)))
    q = np.array(list(bin(q)))

    i = -1
    r = str()
    while p[i] != 'b':
        if p[i] == q[i]:
            r = '0' + r
        else:
            r = '1' + r
        i -= 1

    while q[i] != 'b':
        r = q[i] + r
        i -= 1
    
    r = '0b' + r

    return(int(r, 0))

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

print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

lis = [0]*60

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

print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import scipy.misc as scm

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

loopnum = scm.comb(n, 2)
c = itertools.combinations(nums, 2)
ans=[]
for i in range(loopnum):
  temp = next(c)
  ans.append(temp[0]^temp[1])
sum= sum(ans)
print(sum%(10**9+7))

Submission status: Runtime Error

Solution code:
def XOR(a,b):
    s=0
    n=0
    while max(a,b)<=2**n:
        n+=1

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

Solution code:
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect
import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()

count_list = [0 for i in range(61)]
def counts(count_list, a):
    for i in range(61):
        if a <= 0:
            break
        count_list[i] += a % 2
        a = a // 2
    return count_list

A.reverse()
ans = 0
ans_list = [0 for i in range(61)]
for i in range(N-1):
    count_list = counts(count_list, A[i])
    hikaku = counts([0 for i in range(61)], A[i + 1])
    for j in range(61):
        if hikaku[j] == 1:
            ans_list[j] += i+1 - count_list[j]
        else:
            ans_list[j] += count_list[j]

for i in range(61):
    ans += ans_list[i] * (2 ** i % mod)
    ans = ans % mod
print(ans)

Submission status: Runtime Error

Solution code:
import math

p = 10 ** 9 + 7

def comb(n):
  if n < 2:
    return(0)
  else:
    a = n % p
    b = (n-1) % p
    c = int((a * b / 2)) % p
    return(c)

n = input()
n = int(n)
a = input().split(" ")

a = [int(i) for i in a]

bmax = math.ceil(math.log2(max(a)))

r = 0

for j in range(bmax):
  b = [k>>j & 1 for k in a] # 各ビットを取り出す
  b = [int(k != 0) for k in b]
  n_one = sum(b)
  n_zero = n - n_one
  r_tmp = comb(n) - (comb(n_zero) + comb(n_one))
  b_tmp = (2 ** j) % p
  r = r + ((r_tmp * b_tmp) % p)
  
print(r % p)

Submission status: Runtime Error

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

def jouyo(X):
    return X%1000000007

MAX=A[0]
for i in range(N):
    if MAX<=A[i]:
        MAX = A[i]
    else:
        MAX = MAX

p = 1
M = 1
for i in range(60):
    if 2*p <= MAX:
        p = 2*p
        M = M+1
    else:
        break

List = []
count(M+1) = 0
for j in range(N):
    if A[j]%(2**i) >= 2**(i-1):
            count(M+1) = count(M+1) +1
        else:
            count(M+1) = count(M+1)
    List.append(count(M+1))
    
ans = 0   
for i in range(M):
    ans = jouyo(ans) + jouyo(jouyo((2**i))*jouyo(List[i])*jouyo((N-List[i])))
    
print(jouyo(ans))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
mod = 10 ** 9 + 7
n = int(input())
lis = list(map(int, input().split()))
ans = 0
x = comb(n, 2, exact=True)
for i in range(60):
    temp = 0
    for j in range(n):
        if format(lis[j],'060b')[i] == "1":
            temp += 1
    ans += 2**(59-i)*(x - comb(n-temp, 2, exact=True)-comb(temp, 2, exact=True))
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a_2 = []
for i in range(n):
a_2.append(int(format(a[i],'b')))
total = 0
for i in range(n):
  for j in range(n):
    if i != j:
      t = str(a_2[i] + a_2[j])
      t_10 = int(t.replace('2','0'), 2)
      total += t_10
print(total % (10**9+7))

Submission status: Runtime Error

Solution code:
import math

p = 10 ** 9 + 7

def comb(n):
  if n < 2:
    return(0)
  else:
    a = n % p
    b = (n-1) % p
    c = int((a * b / 2)) % p
    return(c)

n = input()
a = input().split(" ")

a = [int(i) for i in a]

bmax = math.ceil(math.log2(max(a)))

r = 0

for j in range(bmax):
  b = [k & (2 ** j) for k in a] # 各ビットを取り出す
  b = [int(k != 0) for k in b]
  n_tot = len(b)
  n_one = sum(b)
  n_zero = n_tot - n_one
  r_tmp = comb(n_tot) - (comb(n_zero) + comb(n_one))
  b_tmp = (2 ** j) % p
  r = r + ((r_tmp * b_tmp) % p)
  
print(r % p)

Submission status: Runtime Error

Solution code:
import numpy as np

mod = 10**9 + 7
N = input()
A = np.atleast_2d(list(map(int, input().split()))) % mod

print((np.sum((A ^ A.T) % mod) % mod) // 2)

Submission status: Runtime Error

Solution code:
# An efficient Python3 program to compute
# sum of bitwise OR of all pair

# Returns sum of bitwise OR
# of all pairs
def sumXOR( arr,  n):
    sum = 0
    for i in range(0, 60):
        #  Count of zeros and ones
        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] = int(arr[j] / 2)
        # calculating individual bit sum
        idsum = oc * zc * (1 << i)
        # final sum
        sum = (sum + idsum)%(1e9+7);
    return sum



# driver function
sum = 0
n = int(input())
arr = []
for _ in range(n):
    arr.append(int(input())
sum = sumXOR(arr, n);
print(sum)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a_2 = int(format(a,'b'))
total = 0
for i in range(n):
  for j in range(n):
    if i != j:
      t = str(a_2[i] + a_2[j])
      t_10 = int(t.replace('2','0'), 2)
      total += t_10
print(total % (10**9+7))

Submission status: Runtime Error

Solution code:
# An efficient Python3 program to compute
# sum of bitwise OR of all pair

# Returns sum of bitwise OR
# of all pairs
def sumXOR( arr,  n):
    sum = 0
    for i in range(0, 61):
        #  Count of zeros and ones
        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] = int(arr[j] / 2)
        # calculating individual bit sum
        idsum = oc * zc * (1 << i)
        # final sum
        sum = (sum + idsum)%(1e9+7);
    return sum



# driver function
sum = 0
n = int(input())
arr = []
for _ in range(n):
    arr.append(int(input())
sum = sumXOR(arr, n);
print (sum)

Submission status: Runtime Error

Solution code:
import numpy as np

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

pure_total = sum(As)

sabun_mat = np.zeros((N, 60), np.int)

exp2total = {}
for i in range(60):
    tmp_total = 0
    for j, a in enumerate(As[::-1]):
        tmp_total += (2**i ^ a) - a
        sabun_mat[N-1-j, i] = tmp_total
    exp2total[i] = tmp_total

# print(sabun_mat)
total = 0
for i, a in enumerate(As[:-1]):
    pure_total -= a
    total += pure_total
    # print(bin(a))
    for j,b in enumerate(bin(a)[2:][::-1]):
        # print("b",b)
        # print("type", type(b))
        if b == "1":
            total += sabun_mat[i+1, j]
            # print(sabun_mat[i, j])
            # print()

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

Submission status: Runtime Error

Solution code:
# An efficient Python3 program to compute
# sum of bitwise OR of all pair

# Returns sum of bitwise OR
# of all pairs
def sumXOR( arr,  n):

    sum = 0
    for i in range(0, 61):

        #  Count of zeros and ones
        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] = int(arr[j] / 2)


        # calculating individual bit sum
        idsum = oc * zc * (1 << i)

        # final sum
        sum = sum + idsum;

    return sum%(1e9+7)



# driver function
sum = 0
n = int(input())
arr = []
for _ in range(n):
    arr.append(int(input())
sum = sumXOR(arr, n);
print (sum)

Submission status: Runtime Error

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(59)]
    ans = 0
    for i in range(59):
        kaizyo_append(kaizyo[i] * 2 % MOD)
    for i in a_s:
        for i, v in enumerate(bin(i)[:1:-1]):
            keta[i] += int(v)
    # print(kaizyo)
    # print(keta)
    for i, v in enumerate(keta):
        c = v * (n-v) % MOD
        ans += c * kaizyo[i]
        ans = ans % MOD
        # print(ans, c, kaizyo[i])

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# An efficient Python3 program to compute  
# sum of bitwise OR of all pair

# Returns sum of bitwise OR
# of all pairs
def sumXOR( arr,  n):

    sum = 0
    for i in range(0, 32):

        #  Count of zeros and ones
        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] = int(arr[j] / 2)


        # calculating individual bit sum
        idsum = oc * zc * (1 << i)

        # final sum
        sum = sum + idsum;

    return sum%(1e9+7)



# driver function
sum = 0
n = int(input())
arr = []
for _ in range(n):
    arr.append(int(input())
sum = sumXOR(arr, n);
print (sum)

Submission status: Runtime Error

Solution code:
n = int(input())

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

mod = 10 ** 9 + 7

b = [0] * n
b[0] = a[0]

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

print(b%mod)

Submission status: Runtime Error

Solution code:
import itertools
def main():
	x = 10**9
	S = int(input())
	a = [int(i) for i in input().split()]

	xor = 0
	patern = list(itertools.combinations(a, 2))
	for p in patern:
    	xor += p[0] ^ p[1]
	if xor >= x:
    	print(np.mod(xor, (x + 7)))
	else:
    	print(xor)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
mport itertools

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

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

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

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;
const int MOD = 1000000007;

int N;
int A1[61], A0[61];
int main(void){
    cin >> N;
    REP(j,N){
        ll A;
        cin >> A;
        for(int i=0;i<60;i++){
            if(A%2==0) A0[i]++;
            else A1[i]++;
            A /= 2;
        }
    }

    ll count = 0;
    for(ll i=0;i<60;i++){
        ll r = pow(2, i);
        count += (((A1[i]*A0[i])%MOD)*(r%MOD))%MOD;
        count %= MOD;
    }
    cout << count % MOD << endl;
    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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