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:
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep4(i, a, b, c) for (int i = int(a), i##__b = int(b), i##__c = int(c); i < i##__b; i += i##__c)
#define rep1(n) rep4(i, 0, n, 1)
#define rep2(i, n) rep4(i, 0, n, 1)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define REP(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep3(i, a, b) for (int i = int(b) - 1, i##__a = int(a); i >= i##__a; i--)
#define rrep1(n) rrep3(i, 0, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep4(i, a, b, c) for (int i = int(a + (b - a - 1) / c * c), i##__a = int(a), i##__c = int(c); i >= i##__a; i -= i##__c)
#define RREP(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define FOREACH(i, x) for (auto &i : x)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define print(x) cout << x << endl;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
template <class T> using vv = vector<vector<T>>;
template <class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return 1;}return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return 1;}return 0;}
// clang-format on

int main() {
    int N;
    cin >> N;
    vint keta_flag_kazu(60);
    REP(_, N) {
        ll A;
        cin >> A;
        REP(i, 60) {
            keta_flag_kazu[i] += A >> i & 1;
        }
    }
    ll ans = 0;
    REP(i, 60) {
        ll k = keta_flag_kazu[i] * (N - keta_flag_kazu[i]) % MOD;
        ll b = (1ll << i) % MOD;
        ans += k * b % MOD;
    }
    cout << ans;
}

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
S = input()
cnt = 1
counts = []

if S[0]=='0':
  counts.append(0)
if N == 1:
  counts.append(1)
  
for i in range(1,N):
  if S[i-1]!=S[i]:
    counts.append(cnt)
    cnt = 1
  else:
    cnt += 1
  #print(i)
  if i == N-1:
    counts.append(cnt)

#print(counts)
m = 0
K = min(K,len(counts)//2)
for i in range(len(counts)//2-K+1):
  m = max(m,sum(counts[2*i:2*(i+K)+1]))
print(m)

Submission status: Runtime Error

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

for i in range(60):
    for j in A:
        tmp = format(i, '060b')
        if tmp[j] == "1":
            cnt[j] += 1

ans = 0

lst = [1 for i in range(60)]

for i in range(59):
    lst[58-i] = (lst[59-i] * 2) % mod

for i in range(60):
    ans += (lst[i] * cnt[i] * (N -cnt[i])) % mod
    
ans %= mod

print(ans)

Submission status: Runtime Error

Solution code:
import sys

N = int(input())
A = sys.stdin.readline().rstrip()
lst = [0 for i in range(60)]
q = 0
for i in A:
    a = list(str(format(i, '08b')))
    a.reverse()
    for j in range(len(a)):
        lst[j]+=int(a[j])
for i in range(60):
    k = lst[i]
    l = k*(k-1)
    q+=(2**i)*l
p = sum(A)*(N-1)
print((p-q)%((10**9)+7))

Submission status: Runtime Error

Solution code:
import sys

N = int(input())
A = lambda: sys.stdin.readline().rstrip()
lst = [0 for i in range(60)]
q = 0
for i in A:
    a = list(str(format(i, '08b')))
    a.reverse()
    for j in range(len(a)):
        lst[j]+=int(a[j])
for i in range(60):
    k = lst[i]
    l = k*(k-1)
    q+=(2**i)*l
p = sum(A)*(N-1)
print((p-q)%((10**9)+7))

Submission status: Runtime Error

Solution code:
from math import log2,ceil
import sys
input=sys.stdin.readline
n=int(input())
a=tuple(map(int,input().split()))
mod=10**9+7
cnt=[0]*60

for temp in a:
    if temp==0:continue
    digit=len(bin(temp))-2
    for j in range(ceil(digit)+1):
        if (temp>>j)&1:
            cnt[j]=cnt[j]+1

#print(cnt)
ans=0
for i in range(60):
    if cnt[i]==0:continue
    ans=(ans+pow(2,i)*cnt[i]*(n-cnt[i]))%mod
print(ans%mod)

Submission status: Runtime Error

Solution code:
from math import log2,ceil
from collections import defaultdict
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
cnt=defaultdict(lambda :0)

for i in range(n):
    temp=a[i]
    if temp==0:continue
    digit=log2(temp)
    for j in range(ceil(digit)+1):
        if (temp>>j)&1:
            cnt[j]+=1

#print(cnt)
ans=0
for digit,count in cnt.items():
    ans+=pow(2,digit)*count*(n-count)
print(ans%mod)

Submission status: Runtime Error

Solution code:
from math import log2,ceil
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
cnt=defaultdict(lambda :0)

for i in range(n):
    temp=a[i]
    digit=log2(temp)
    for j in range(ceil(digit)+1):
        if (temp>>j)&1:
            cnt[j]+=1

#print(cnt)
ans=0
for digit,count in cnt.items():
    ans+=pow(2,digit)*count*(n-count)
print(ans%mod)

Submission status: Runtime Error

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

digits_cnt1 = [0]*60
for ai in A:
    for d in range(int(log2(ai))+1):
        if ai>>d & 1:
            digits_cnt1[d] += 1

ans = 0
for i in range(60):
    ans += digits_cnt1[i]*(N-digits_cnt1[i])*2**i
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
keta = len(bin(max(A))) - 2
ans = 0
shift = 0
for _ in range(keta):
num_1=sum([a>>shift&1 for a in A])
    ans += num_1 * ((N-num_1)<<shift%INF)
    shift += 1
print(ans % INF)

Submission status: Runtime Error

Solution code:
    import sys, re, os
    from collections import deque, defaultdict, Counter
    from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
    from itertools import permutations, combinations, product, accumulate
    from operator import itemgetter, mul
    from copy import deepcopy
    from string import ascii_lowercase, ascii_uppercase, digits
    from fractions import gcd
     
    def input(): return sys.stdin.readline().strip()
    def INT(): return int(input())
    def MAP(): return map(int, input().split())
    def S_MAP(): return map(str, input().split())
    def LIST(): return list(map(int, input().split()))
    def S_LIST(): return list(map(str, input().split()))
     
    sys.setrecursionlimit(10 ** 9)
    INF = float('inf')
    mod = 10 ** 9 + 7
     
    N = INT()
    A = LIST()
     
    max_length = len("{:b}".format(max(A)))
     
    cnt = [defaultdict(int) for _ in range(max_length)]
     
    for i in range(N):
        num = "{:b}".format(A[i]).zfill(max_length)
        for j in range(len(num)):
            # [i桁目][numのj番目の数，(0 or 1)]
            # 0, 1 の数を数える
            cnt[max_length-1-j][num[j]] += 1
     
    ans = 0
     
    for i in range(max_length):
        # 1を左にiシフト(2 ** i 倍)
        # 桁内で0の個数 * 桁内で1の個数 が，XOR = 1になる数 (0 xor 1 = 1)
        ans = ans + (1 << i) * cnt[i]["0"] * cnt[i]["1"]
    ans = ans % mod
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()] , dtype=np.int64)
a_ = list(map(int, input().split()))
m = 10**9+7
ans = 0
for k in range(60):
    b = (a>>k) & 1
    res = np.count_nonzero(b)
    ans += res*(n-res)*2**k
print(ans%m)

Submission status: Runtime Error

Solution code:
def main():
    n =int(input())
    al = list(map(int,input().split()))

    res = 0
    bits = [[0]*2 for _ in range(60)]
    for a in al:
        i = 0
        while a > 0:
            bits[i][a&1] += 1
            a = a >> 1
            d += 1

    res = 0

    for i in range(60):
        res += bits[i][0] * bits[i][1]  * (2 ** i)

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

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    n =int(input())
    al = list(map(int,input().split()))

    res = 0
    bits = [[0]*2 for _ in range(60)]
    for a in al:
        i = 0
        while a > 0:
            bits[i][a&1] += 1
            a == a >> 1
            d += 1

    res = 0

    for i in range(60):
        res += bits[i][0] * bits[i][1]  * (2 ** i)

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

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    ans = 0
    MOD = 10**9+7
    k = 1
    n = int(np.log2(np.max(A)))+1

    for i in range(n):
        c = np.count_nonzero(A%2)
        A >>= 1
        ans = (ans + c * (N-c) * k) % MOD
        k = (2*k) % MOD

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

from math import * 

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

    ans = 0
    MOD = 10**9+7
    k = 1
    n = ceil(log2(max(A)))
    for i in range(n):
        c = 0
        for j in range(N):
            c += A[j] & 1
            A[j] >>= 1
        ans = (ans + c * (N-c) * k) % MOD
        k = (2*k) % MOD

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
ba = np.array([list(format(i,'b').zfill(60)) for i in a])
print(ba)
mod = 10**9+7


#2^iをmodで割った余りを出しておく
twos = [1]
for i in range(1,60):
    twos.append((twos[i-1]*2)%mod)

#各baのbitごとに0の個数を求める
c0 = np.sum(ba, axis=1)


#答えは各bitごとの(0の数)*(1の数)より求まる
ans = 0
for i in range(60):
    ans += (((c0[59-i]*(n-c0[59-i]))%mod)*twos[i])%mod

ans %= mod
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
ba = np.array(list(format(i,'b').zfill(60)) for i in a])
#print(ba)
mod = 10**9+7


#2^iをmodで割った余りを出しておく
twos = [1]
for i in range(1,60):
    twos.append((twos[i-1]*2)%mod)

#各baのbitごとに0の個数を求める
c0 = np.sum(ba, axis=1)


#答えは各bitごとの(0の数)*(1の数)より求まる
ans = 0
for i in range(60):
    ans += (((c0[59-i]*(n-c0[59-i]))%mod)*twos[i])%mod

ans %= mod
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
ba = np.array(list(format(i,'b').zfill(60)) for i in a])
mod = 10**9+7

"""
#2^iをmodで割った余りを出しておく
twos = [1]
for i in range(1,60):
    twos.append((twos[i-1]*2)%mod)

#各baのbitごとに0の個数を求める
c0 = np.sum(ba, axis=1)
"""

#答えは各bitごとの(0の数)*(1の数)より求まる
ans = 0
for i in range(60):
    ans += (((c0[59-i]*(n-c0[59-i]))%mod)*twos[i])%mod

ans %= mod
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
ba = np.array([[int(j) for j in list(format(i,'b').zfill(60))] for i in a])
mod = 10**9+7

"""
#2^iをmodで割った余りを出しておく
twos = [1]
for i in range(1,60):
    twos.append((twos[i-1]*2)%mod)

#各baのbitごとに0の個数を求める
c0 = np.sum(ba, axis=1)
"""

#答えは各bitごとの(0の数)*(1の数)より求まる
ans = 0
for i in range(60):
    ans += (((c0[59-i]*(n-c0[59-i]))%mod)*twos[i])%mod

ans %= mod
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
ba = np.array([[int(j) for j in list(format(i,'b').zfill(60))] for i in a]).T
mod = 10**9+7

"""
#2^iをmodで割った余りを出しておく
twos = [1]
for i in range(1,60):
    twos.append((twos[i-1]*2)%mod)

#各baのbitごとに0の個数を求める
c0 = np.sum(ba, axis=1)
"""

#答えは各bitごとの(0の数)*(1の数)より求まる
ans = 0
for i in range(60):
    ans += (((c0[59-i]*(n-c0[59-i]))%mod)*twos[i])%mod

ans %= mod
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
mod = 10**9+7

#2^iをmodで割った余りを出しておく
twos = np.ones(60)
for i in range(1,60):
    twos[i] = (twos[i-1]*2)%mod

"""
#各baのbitごとに0の個数を求める
c0 = np.zeros(60)
for i in range(n):
    ins0 = list(format(a[i],'b').zfill(60))
    ins1 = np.array(ins0,dtype=int)
    c0 += ins1
"""

#答えは各bitごとの(0の数)*(1の数)より求まる
ans = 0
for i in range(60):
    ans += (((c0[59-i]*(n-c0[59-i]))%mod)*twos[i])%mod

ans %= mod
print(int(ans))

Submission status: Runtime Error

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

maxdig = 60
mod = 10**9+7

ans = 0
for i in range(60+1):
  cnt1 = 0
  for a in A:
    if (a >> i) & 1:
      cnt1 += 1
  ans += (cnt1*(N-cnt1)*(1<<j))
  ans = ans%mod

print(ans)

Submission status: Runtime Error

Solution code:
from math import log2

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

maxdig = int(log2(max(A)))


ans = 0
for i in range(maxdig, -1, -1):
  d = 2**i
  cnt1 = 0
  for j in range(N):
    if A[j]//d > 0:
      cnt1 += 1
      A[j] -= d
  ans += (cnt1*(N-cnt1)*d)%1000000007

print(ans)

Submission status: Runtime Error

Solution code:
from math import log2

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

maxdig = int(log2(max(A)))

ans = 0
for i in range(maxdig, -1, -1):
  d = 2**i
  cnt1 = 0
  for j in range(N):
    if A[j]//d > 0:
      cnt1 += 1
      A[j] -= d
  ans += cnt1*(N-cnt1)*d

print(ans%1000000007)

Submission status: Runtime Error

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

max_digist = 60
MOD = 10**9 + 7

ans = 0
for i in range(max_digits):
    one_num = np.count_nonzero((a >> i) & 1)
    radix_mod = 2**i % MOD
    ans += (radix_mod * one_num * (n - one_num)) % MOD
print(ans%MOD)

Submission status: Runtime Error

Solution code:
ef main():
  n=int(input())
  num=[int(i) for i in input().split()]
  mod=10**9+7

  import math
  if max(num)==0:
    print(0)
    exit()
  l=math.ceil(math.log(max(num),2))

  ans=[0]*l
  tmp1,tmp2,tmp3=0,0,0
  for i in range(l):
    ans[i]=tmp3
    cnt=0
    for j in range(n):
      if (num[j]>>i)&1:
        cnt+=1
    tmp1=cnt*(n-cnt)
    tmp2=(ans[i]+tmp1)%2
    tmp3=(ans[i]+tmp1)//2
    ans[i]=tmp2

  a_append=ans.append
  while tmp3>0:
    a_append(tmp3%2)
    #print(tmp3)
    tmp3//=2
  #print(ans)
  ans=int(''.join([str(i) for i in ans[::-1]]),2)%mod
  print(ans)
  
if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:
n=int(input())
num=[int(i) for i in input().split()]
mod=10**9+7

import math
l=math.ceil(math.log(max(num),2))

ans=[0]*l
tmp1,tmp2,tmp3=0,0,0
for i in range(l):
  ans[i]=tmp3
  cnt=0
  for j in range(n):
    if (num[j]>>i)&1:
      cnt+=1
  tmp1=cnt*(n-cnt)
  tmp2=(ans[i]+tmp1)%2
  tmp3=(ans[i]+tmp1)//2
  ans[i]=tmp2

while tmp3>0:
  ans.append(tmp3%2)
  #print(tmp3)
  tmp3//=2
#print(ans)
ans=int(''.join([str(i) for i in ans[::-1]]),2)%mod
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
mod = 10**9+7
SUM = 0

maxA = max(A)
d = 0
while 1:
    if maxA < 2**d:
        break
    d += 1

BitA = [[0]*d for _ in range(N)]
for i in range(N):
    for j in range(d):
        BitA[i][j] = int(bin(A[i]|2**d)[3+j])

BitSumB = 0
for i in range(d):
    tmp = sum([BitA[j][i] for j in range(N)])
    BitSumB += 2 ** (d-i-1) * (tmp * (N - tmp))
    BitSumB = BitsumB % mod

print(BitSumB)

Submission status: Runtime Error

Solution code:
n = int(input())
li = []
for i in range(n):
  a = int(input())
  li_2 = [list(map(int, input().split())) for _ in range(a)]
  li.append(li_2)
def judge(bit): 
  b =1
  """正直者と嘘つきの決め方を一つ固定"""
  for i in range(n):
    if bit & (1<<i) == False:
      continue
    else:
      for xy in li[i]:
        x = xy[0]
        y = xy[1]
        if y == 1 and bit & (1<<x)==False:
          b = 0
        if y == 0 and bit & (1<<x):
          b = 0
      if b == 1:
        return True
      else:
        return False
res = 0
for bit in range(n):
  if judge(bit):
    count = 0
    for i in range(n):
      if bit & (1<<i):
        count += 1
    res = max(res,count)
print(res)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
b = [[0]*60 for i in range(2)]
max_a = math.ceil(math.log(max(A),2))
for i in range(N):
    x = A[i]
    j = 0
    for j in range(max_a):
        b[x % 2][j] += 1
        x //= 2

x = 0
for i in range(max_a):
    x += b[0][i] * b[1][i] * 2**i
    x %= 10 ** 9 + 7

print (x)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
b = [[0]*60 for i in range(2)]
max_a = math.ceil(math.log2(max(A)))
for i in range(N):
    x = A[i]
    j = 0
    for j in range(max_a):
        b[x % 2][j] += 1
        x //= 2

x = 0
for i in range(max_a):
    x += b[0][i] * b[1][i] * 2**i
    x %= 10 ** 9 + 7

print (x)

Submission status: Runtime Error

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + n%2
        n//=2

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        b = N-a-i # 0

        if n%2:
            ans += b*(2**j)
        else:
            ans += a*(2**j)
        n//=2
	ans %= mod

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
*A, = map(int, input().split())

d1 = np.ndarray([[0]*60 for _ in range(N+1)])
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j]
        if n%2:
            d1[i][j] += 1
        n//=2

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        b = N-a-i # 0

        if n%2:
            ans += b*(2**j)
        else:
            ans += a*(2**j)
        ans %= mod
        n//=2

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split( )))
ans = 0
mod = 10**9+7
Bit = [0 for j in range(60)]# for i in range(n+1)
for j in range(60):#ループ交換
	for i in range(1,n):##1から

        if not ((a[i-1]>>j)&1):#a[i-1]のjビット目0
            Bit[j] += 1
        if ((a[i]>>j)&1):#aiのjビット目1
            ans += Bit[j]<<j
            ans %=mod
        else:
            ans += (i-Bit[j])<<j
            ans %= mod
    
print(ans)

Submission status: Runtime Error

Solution code:
#python3

graph = [[-1 for _ in range(15)] for _ in range(15)]

def main():
    n = int(input())
    for i in range(n):
        a = int(input())
        for j in range(a):
            x, y = map(int, input().split())
            graph[i][x-1] = y
            
    ans = 0
    for i in range(1<<15):
        h = [0]*15
        for k in range(n):
            if (i >> k) & 1:
                h[k] = 1

        f = True
        for i in range(15):
            if h[i] == 1:
                for j in range(n):
                    if graph[i][j] == -1:
                        continue
                    if graph[i][j] != h[j]:
                        f = False

        if f:
            ans = max(ans, sum(h))

    print(ans)
main()

Submission status: Runtime Error

Solution code:
import math

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

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

abit = [bin(an)[2:].zfill(A) for an in a]

amari = 0
for i in range(A):
    zero_count = 0
    for j in range(n):
        if abit[j][A - 1 - i] == "0":
            zero_count += 1
    amari = (amari + (zero_count * (n - zero_count) * (2 ** i)) % (10 ** 9 + 7)) % (10 ** 9 + 7) 

print(amari)

Submission status: Runtime Error

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

    largest = max(As)
    digits = len(bin(largest))-2

    binaries = [format(i, f'0{digits}b') for i in As]

    total = 0
    for i in range(digits):
        t = [int(n[i]) for n in binaries]
        ones = sum(t)
        zeros = N - ones
        r = ones * zeros
        total += (2 ** (digits-i-1)) * r
        total = total % (10**9 + 7)

    print(total)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

import heapq
import collections
import math
import sys
N =  int(input())
input = sys.stdin.readline

nums = list(map(int,input().split(" ")))
keta = [0] * 61
# ある桁の1の出現回数
# keta[k] → 2**k の桁
jijou = [1]
MOD = 10 ** 9 + 7
for i in range(60):
    temp = jijou[i] * 2
    temp%= MOD
    jijou.append(temp)

for num in nums:
    s = format(num,"b")
    l = math.floor(math.log2(num)) + 1

    for i in range(0,l):
        keta[i] += int(s[l - i - 1 ])
ans = 0
for j,num in  enumerate(nums[:-1]):
    s = format(num, "b")
    l = math.floor(math.log2(num)) + 1
    for i in range(0,61): #i →  2 ** i 乗 桁目に対応
        if l <= i:
            ans += (keta[i] * jijou[i]) % MOD
        else:
            if s[l - i - 1 ] == "0":
                ans += (keta[i] * jijou[i]) % MOD
            else:
#              (N - j + 1) - (keta[i] + 1 ) → 0が経っているところの個数
                ans += (( (N - j + 1) - (keta[i] + 1)  ) * ( jijou[i]) ) % MOD
                keta[i] -= 1
        ans %= MOD
    ans %= MOD


print(ans)

Submission status: Runtime Error

Solution code:

import heapq
import collections
N =  int(input())
nums = list(map(int,input().split(" ")))
keta = [0] * 60
# ある桁の1の出現回数
# keta[k] → 2**k の桁
jijou = [1]
MOD = 10 ** 9 + 7
for i in range(60):
    temp = jijou[i] * 2
    temp%= MOD
    jijou.append(temp)

for num in nums:
    s = format(num,"b")
    l = len(s)
    for i in range(0,l):
        keta[i] += int(s[l - i - 1 ])
ans = 0
for j,num in  enumerate(nums[:-1]):
    s = format(num, "b")
    l = len(s)
    for i in range(0,61): #i →  2 ** i 乗 桁目に対応
        if l <= i:
            ans += (keta[i] * jijou[i]) % MOD
        else:
            if s[l - i - 1 ] == "0":
                ans += (keta[i] * jijou[i]) % MOD
            else:
#              (N - j + 1) - (keta[i] + 1 ) → 0が経っているところの個数
                ans += (( (N - j + 1) - (keta[i] + 1)  ) * ( jijou[i]) ) % MOD
                keta[i] -= 1
        ans %= MOD
    ans %= MOD


print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

zero_each_dig = [0 for _ in range(60)]
one_each_dig = [0 for _ in range(60)]

for i in range(n):
     for j in range(60):
        if (A[i] >> j) & 1 == 1:
            one_each_dig[j] += 1
        else:
            zero_each_dig[j] += 1

Multi = []
for k in range(n):
    Multi.append(zero_each_dig[k] * one_each_dig[k] * (2**k) % (10**9 +7))

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

Submission status: Runtime Error

Solution code:
N = int(input())
plus = sums([int(s) for s in input().split()])
minus = N - plus

print(plus * minus)

Submission status: Runtime Error

Solution code:
N = int(input())
C = {i:0 for i in range(20)}
A = input().split()
for i in range(N):
    a = bin(int(A[i]))[2:]
    n = len(a)
    for j in range(n):
        if a[j]=="1":
            C[n-1-j] += 1
cnt = 0
for i in range(20):
    if C[i]>0:
        cnt += C[i]*(N-C[i])*2**i
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
As = [int(i) for i in input().split(" ")]
 
total = 0
for k in range(Nmax):
    
    #counter = [0,0]
    o = 0
    z = 0
    
    for i in range(N):
        
        # k桁を取り出す
        ai_k = As[i] >> k & 1
        
        # 0と1の個数を数える
        #counter[ai_k] += 1
        if ai_k == 0:
            o += 1
        else:
            z += 1
        
    total += (2**k)*o*z #counter[0]*counter[1]
    
print(total%int(1e9+7))

Submission status: Runtime Error

Solution code:
import random
N = int(input())
As = [int(i) for i in input().split(" ")]

total = 0
for k in range(Nmax):
    
    #counter = [0,0]
    o = 0
    z = 0
    
    for i in range(N):
        
        # k桁を取り出す
        ai_k = As[i] >> k & 1
        
        # 0と1の個数を数える
        #counter[ai_k] += 1
        if ai_k == 0:
            o += 1
        else:
            z += 1
        
    total += (2**k)*o*z #counter[0]*counter[1]
    
print(total%int(1e9+7))

Submission status: Runtime Error

Solution code:
a=list(map(int,input().split()))
su=0
#a=[]
#for i in range(1,n):
#    c=int(input())
#    a.append(c) 
for i in range (1,a[0]):
    for j in range(i+1,a[0]+1):
        su+=a[i]^a[j]
print(su%(1000000000+7))

Submission status: Runtime Error

Solution code:
n=int(input())
su=0
a=[]
for i in range(n):
    c=int(input())
    a.append(c) 
for i in range (n-1):
    for j in range(i+1,n):
        su+=a[i]^a[j]
print(su%(1000000000+7))

Submission status: Runtime Error

Solution code:
#bin()やformat(数字 ,"b")を使うとstr型になる
#bin()とformat(数字 ,"#b")は同意

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

for i in range(N): A[i] = format(A[i], "059b") #ここで全て60ビットの二進数に変換

mod = 10**9+7

sum = 0
for i in range(1,61):
    count0 = 0
    count1 = 0
    for j in range(N):
        if A[j][-i] == "0": #str型であることに注意！
            count0 += 1
        else:
            count1 += 1 
    sum += (count0 * count1) << (i-1) #左シフトだが，2**(i-1)でもOK
print(sum%mod)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline()
N = int(input())
A = [int(i) for i in input().split()]
count0 = [0 for i in range(60)]
count1 = [0 for i in range(60)]
for a in A:
    a_tmp = bin(a).replace("0b","")
    a_tmp = a_tmp.zfill(60)
    for i,b in enumerate(a_tmp):
        if b == "1":
            count1[i] += 1
        else:
            count0[i] += 1
cnt = 0
ans = 0
for c0,c1 in zip(count0[::-1],count1[::-1]):
    ans += c0*c1*(2**cnt)
    cnt += 1
print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
    import numpy as np
    n = int(input())
    a = list(map(int, input().split()))
    l1 = np.zeros(61, dtype=np.int64)
    mod = 10**9+7
    for i in a:
        j = list(map(int, reversed(bin(i)[2:])))
        l1[:len(j)] += j
    l0 = n-l1
    ans = 0
    for i in range(len(l1)):
        ans = (ans+l0[i]*l1[i]*pow(2, i, mod)) % mod
    print(ans)


main()

Submission status: Runtime Error

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


bit= [[0]*60 for i in range(n)]
for i in range(n):
    a=A[i]
    j=1
    if a!=0:    
    while a//2>0:
        if a%2==1:
            bit[i][60-j]=1
            j+=1
            a=a//2
        else:
            j+=1
            a=a//2
    bit[i][60-j]=1
      
xor=[0]*60
    
for j in range(60):
    l=0
    for i in range(n):
        l+=bit[i][j]
    xor[j]=l*(n-l)
    
L=10**9+7
ans=xor[0]
for j in range(60-1):
    ans=((2*ans)+xor[j+1])%L
print(ans)

Submission status: Runtime Error

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

n = int(input())
a = [int(i) for i in input().split()]
bound = int(math.log2(max(a)) + 1)

k = [0] * bound

for i in a:
    for j in range(bound):
        if (i >> j) & 1:
            k[j] += 1

ans = 0
c = 0
for d in k:
    ans += (d * (n - d) * 2**c)  % (10**9 + 7)
    c += 1
    
print(ans % (10**9 + 7))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
mod = 10 ** 19 + 7
print(mod)
ans = 0
for i in range(60):
    tmp = (A >> i)
    x = np.count_nonzero(tmp)
    x *= n - x
    ans = (ans + pow(2, i, mod) * x) % mod
print(ans)

Submission status: Runtime Error

Solution code:
    from fractions import gcd
    # from datetime import date, timedelta
    from heapq import*
    import math
    from collections import defaultdict, Counter, deque
    from bisect import *
    import itertools
    import sys
    sys.setrecursionlimit(10 ** 7)
    MOD = 10 ** 9 + 7
    # input = sys.stdin.readline
     
     
    def main():
        n = int(input())
        a = list(map(int, input().split()))
     
        ans = 0
        for i in range(60):
            one,zero = 0,0
            for j in range(n):
                if ((1 << i) & a[j]) == (1 << i):
                    one +=1
                else:
                    zero += 1
            ans += (1 << i) * one * zero
            ans %= MOD
        print(ans)
     
     
    if __name__ == '__main__':
        main()

Submission status: Runtime Error

Solution code:
import numpy as np

MAX = 10**9+7

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


ary = np.tril((l.reshape((-1,1))^l)) % MAX

ary = ary.sum(axis=0) % MAX

sum_xor = ary.sum() % MAX
sum_xor = int(sum_xor)

print(sum_xor)

Submission status: Runtime Error

Solution code:
import numpy as np

MAX = 10**9+7

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


#sum_xor = (l.reshape((-1,1))^l).sum() / 2
#sum_xor = int(sum_xor)

ary = l.reshape((-1,1))^l % MAX
ary = ary.sum(axis=0) % MAX
sum_xor = ary.sum() % MAX
sum_xor = int(sum_xor)

print(sum_xor)

Submission status: Runtime Error

Solution code:
import numpy as np

MAX = 10**9+7

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


#sum_xor = (l.reshape((-1,1))^l).sum() / 2
#sum_xor = int(sum_xor)

ary = l.reshape((-1,1))^l % MAX
ary = ary.sum(axis=0) % MAX
sum_xor = ary.sum() % MAX
sum_xor = int(sum_xor)

print(sum_xor)

Submission status: Runtime Error

Solution code:
import numpy as np

MAX = 10**9+7

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


#sum_xor = (l.reshape((-1,1))^l).sum() / 2
#sum_xor = int(sum_xor)

ary = l.reshape((-1,1))^l % MAX
ary = ary.sum(axis=0) % MAX
sum_xor = ary.sum % MAX
sum_xor = int(sum_xor)

print(sum_xor)

Submission status: Runtime Error

Solution code:
import numpy as np

MAX = 10**9+7

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


#sum_xor = (l.reshape((-1,1))^l).sum() / 2
#sum_xor = int(sum_xor)

ary = l.reshape((-1,1))^l
ary = ary.sum(axis=0) % MAX
sum_xor = ary.sum % MAX
sum_xor = int(sum_xor)

print(sum_xor)

Submission status: Runtime Error

Solution code:
import numpy as np

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

sum_xor = (l.reshape((-1,1))^l).sum() / 2
sum_xor = int(sum_xor)

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

Submission status: Runtime Error

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

sum_xor = 0
for i in range(n):
  for j in range(i+1, n):
    sum_xor += l[i]^l[j]
  	sum_xor %= 10**9+7

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

Submission status: Runtime Error

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

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

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