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: Accepted

Solution code:
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = np.array(read().split(), np.int64)

mod = 10 ** 9 + 7
ans = 0

for i in range(61):
    b = a >> i & 1
    x = np.count_nonzero(b)
    y = n - x
    z = x * y
    z *= 2 ** i
    z %= mod
    ans += z
ans %= mod

print(ans)

Submission status: Accepted

Solution code:
MOD = 10**9+7
n = int(input())
A = ['{:060b}'.format(a)[::-1] for a in map(int, input().split())]
c = [a.count('1') for a in zip(*A)]
print(sum(c[d]*(n-c[d])*pow(2, d, MOD) %
          MOD for d in range(60)) % MOD)

Submission status: Accepted

Solution code:
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))
n_bit = 60
bit_cnt = [0]*n_bit
for i in range(n):
    for d in range(n_bit):
        if (A[i] >> d) & 1:
            bit_cnt[d] += 1

ans = 0
for d, one_cnt in enumerate(bit_cnt):
    ans = ans + one_cnt*(n-one_cnt)*pow(2, d, MOD) % MOD
print(ans % MOD)

Submission status: Accepted

Solution code:
MOD = 10**9+7
n = int(input())
A = ['{:060b}'.format(a)[::-1] for a in map(int, input().split())]
A_d = []
for col in zip(*A):
    one_cnt = col.count('1')
    A_d.append(one_cnt*(n-one_cnt))

ans = 0
for d in range(60):
    ans = ans + A_d[d]*pow(2, d, MOD) % MOD
print(ans % MOD)

Submission status: Accepted

Solution code:
MOD = 10**9+7
n = int(input())
A = ['{:060b}'.format(a)[::-1] for a in map(int, input().split())]
A_d = []
for col in zip(*A):
    zero_cnt = col.count('0')
    A_d.append(zero_cnt*(n-zero_cnt))

ans = 0
for d in range(60):
    ans = ans + A_d[d]*pow(2, d, MOD) % MOD
print(ans % MOD)

Submission status: Accepted

Solution code:
import numpy as np
 
mod = 10**9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   
    n_1 = np.count_nonzero((A >> n)&1)   
    n_0 = N - n_1                       
    ans += ((2 ** n)*n_1*n_0) % mod

print(ans%mod)

Submission status: Accepted

Solution code:
import numpy as np
 
mod = 10 ** 9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   # 最大桁数は、最も大きい数値の2進数の桁数
    num_1 = np.count_nonzero((A >> n)&1)   # 1の数をカウント
    num_0 = N - num_1                      # 0の数をカウント
    mul = num_1 * num_0   # 0 XOR 1の回数
    ans += ((2 ** n)*mul) % mod
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
 
data = int(input())
array = np.fromiter(map(int, input().split()), np.int64)
 
result = 0
for bit in range(60):
    array01 = int((array & 1).sum())
    result = (result + array01 * (data - array01) * (1 << bit)) % 1000000007
    array >>= 1
print(result)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
d = [0]*60
for i in range(n):
    for j in range(60):
        if a[i] >> j & 1 == 1:
            d[j] += 1

ans = 0
for j in range(60):
    ans += 2**j * d[j] * (n - d[j]) % mod

print(ans % mod)

Submission status: Accepted

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

MOD = 10**9 + 7

dig = 60
Abn = [[0]*dig for _ in range(n)]

b0 = [0]*dig
b1 = [0]*dig
for i in range(n):
  for j in range(dig):
    if A[i]>>j&1:
      b1[j] += 1
    else:
      b0[j] += 1
      
pow2 = [pow(2, i, MOD) for i in range(dig)]

ans = 0
for i in range(dig):
  ans += b1[i]*b0[i]*pow2[i]%MOD
  
print(ans%MOD)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
def main():
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    a = np.array(a)
    mod = 10**9+7
    point = 0
    for i in range(61):
        b = (a >> i)&1
        x = np.count_nonzero(b)
        y = n-x
        point += x*y*(2**i)%mod
    print(point%mod)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    mod = 10**9+7
    point = 0
    for i in range(61):
        now = sum(1 for j in a if(j >> i)&1)
        point += now*(n-now)*(2**i)%mod
        point %= mod
    print(point)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
point = 0
for i in range(61):
    now = 0
    for j in a:
        now += (j >> i&1)
    now *= n-now
    now %= mod
    for k in range(i):
        now *= 2
        now %= mod
    point += now
    point %= mod
print(point)

Submission status: Accepted

Solution code:
M = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
pow2 = [2 ** i % M for i in range(60)]
ans = 0
a1 = [(A[0] >> i) & 1 for i in range(60)]
a0 = [1 - x for x in a1]
for i in range(1, N):
    a = A[i]
    for j in range(60):
        b1 = a & 1
        a >>= 1
        if b1:
            ans += pow2[j] * a0[j] % M
            a1[j] += 1
        else:
            ans += pow2[j] * a1[j] % M
            a0[j] += 1
        ans %= M
print(ans)

Submission status: Accepted

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

zero = [0] * 60
one = [1] * 60
pow2 = [2 ** i % M for i in range(60)]


def bitcnt(a):
    j = 0
    bits = [0] * 60
    while a:
        bits[j] = a & 1
        a >>= 1
        j += 1
    return bits


ans = 0
a1 = bitcnt(A[0])
a0 = [(x + 1) % 2 for x in a1]
for i in range(1, N):
    a = A[i]
    for j in range(60):
        b1 = a & 1
        a >>= 1
        if b1:
            ans += pow2[j] * a0[j] % M
            a1[j] += 1
        else:
            ans += pow2[j] * a1[j] % M
            a0[j] += 1
        ans %= M

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
bits = [0] * 60
MOD = 10**9 + 7

for a in A:
    div = a
    i = 0
    while True:
        div, mod = div // 2, div % 2
        bits[i] += mod
        i += 1
        if div == 0:
            break

ans = 0
for i in range(60):
    ans += bits[i] * (n-bits[i]) * 2 ** i % MOD
print(ans % MOD)

Submission status: Accepted

Solution code:
import numpy as np
from math import ceil,log2
N = int(input())
a = np.array(list(map(int,input().split())),dtype=np.int64)
ans = 0
count = 1
if max(a) == 0:
    x = 1
else:
    x = ceil(log2(max(a)))

for i in range(x):
    b = a%2
    s = np.count_nonzero(b==1)*np.count_nonzero(b==0)*count
    ans +=s
    count *= 2
    a = a//2
    ans %= 10**9+7
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
 
data = int(input())
array = np.fromiter(map(int, input().split()), np.int64)
 
result = 0
for bit in range(60):
    array01 = int((array & 1).sum())
    result = (result + array01 * (data - array01) * (1 << bit)) % 1000000007
    array >>= 1
print(result)

Submission status: Accepted

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

ans = 0
for i in range(61):
    zero, one = 0, 0
    for j in range(N):
        if (A[j] >> i) & 1 == 0:
            zero += 1
        else:
            one += 1
    ans += zero * one * (1 << i)
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

data = int(input())
array = np.array(list(map(int, input().split())))
mod = 10 ** 9 + 7
counter = 0
for i in range(60):
    tmp = array & 1
    array >>= 1
    x = np.count_nonzero(tmp)
    x *= data - x
    counter = (counter + pow(2, i, mod) * x) % mod
print(counter)

Submission status: Accepted

Solution code:
import numpy as np

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

res=0
mod=10**9+7
for i in range(61):
  cnt=np.count_nonzero(A>>i & 1)
  res+=cnt*(N-cnt)<<i
  res%=mod
print(res)

Submission status: Accepted

Solution code:
M=10**9+7
n,*l=map(int,open(0).read().split())
a=0
for i in range(60):
  t=sum(j>>i&1 for j in l)
  a+=t*(n-t)*pow(2,i,M)
print(a%M)

Submission status: Accepted

Solution code:
import numpy as np

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

res = 0
mod = 10**9 + 7
for i in range(61):
    cnt = np.count_nonzero(a >> i & 1)
    res += cnt * (n-cnt) << i
    res %= mod

print(res)

Submission status: Accepted

Solution code:
#xorの性質
#AxorA=0、交換法則、結合法則が成立、bitごとに独立して考える！

import numpy as np

n=int(input())
a=np.array(list(map(int,input().split())))
res=0
for j in range(60):
  s=0 #1の数
  """
  for i in a:
    if (i>>j & 0b1)==0b1:
      s+=1
  """
  s=np.count_nonzero(a>>j&1)
  r=2**j*(n-s)*s
  res=(res+r)%(10**9+7)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
MOD = 10 ** 9 + 7

n = int(sys.stdin.readline().rstrip())
a = np.array(sys.stdin.readline().split(), dtype=np.int64)

def main():
  x = a[:, None] >> np.arange(60) & 1
  x = x.sum(axis=0)
  y = n - x
  res = x * y  % MOD * ((1 << np.arange(60)) % MOD)
  print(res.sum() % MOD)

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys
import numpy as np
MOD = 10 ** 9 + 7

n = int(sys.stdin.readline().rstrip())
a = np.array(sys.stdin.readline().split(), dtype=np.int64)

def main():
  x = a[:, None] >> np.arange(61) & 1
  x = x.sum(axis=0)
  y = n - x
  res = x * y  % MOD * ((1 << np.arange(61)) % MOD)
  print(res.sum() % MOD)

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import numpy as np
MOD = 10 ** 9 + 7
N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
for n in range(60): # または、range(60)またはrange(len(bin(max(A))))
    cnt_1 = np.count_nonzero((A>>n)&1)
    cnt_0 = N - cnt_1
    ans += (cnt_1 * cnt_0 * (2 ** n)) % MOD
ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = np.array(input().split(), np.int64)
MOD = 10**9 + 7

max_num = np.max(a)
max_digit = len(format(max_num, 'b'))

ans = 0

for digit in range(max_digit):
    b = (a >> digit) & 1
    one = np.count_nonzero(b)
    zero = n - one
    ans += 2 ** digit *  (one * zero)
    ans %= MOD

print(ans)

Submission status: Accepted

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

pl = [0 for i in range(61)]

for a in al:
    turn = 0
    while a:
        if a % 2 == 1:
            pl[turn] += 1
        a //= 2
        turn += 1

ans = 0
k = 1
for p in pl:
    ans += p * (n - p) * k
    ans %= 10**9 + 7
    k *= 2
    k %= 10 ** 9 + 7

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
p = 10**9 + 7
ans = 0
for i in range(60):
  c = np.count_nonzero(a & 1)
  ans = (ans + c*(n-c)*2**i) % p
  a = a >> 1
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import collections
mod = 10 ** 9 + 7
 
N = int(readline())
A = [int(i) for i in readline().split()]
 
answer = 0
for n in range(62):
    B = [(i >> n) & 1 for i in A]
    C = collections.Counter(B)
    x = C[1]
    y = N - x
    x *= y
    for _ in range(n):
        x *= 2
        x %= mod
    answer += x
    answer %= mod
print(answer)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import collections

def binary(n):
    return bin(n)[2:]

def pow_by_binary(a, x, n): # a^x mod n
    x = [int(b) for b in binary(x)]
    y = a
    for i in range(1, len(x)):
        y = (y**2) % n
        if x[i] == 1:
            y = (y * a) % n
    return y 
  
mod = 10 ** 9 + 7
 
N = int(readline())
A = [int(i) for i in readline().split()]
 
answer = 0
for n in range(62):
    B = [(i >> n) & 1 for i in A]
    C = collections.Counter(B)
    x = C[1]
    y = N - x
    x *= y
    if n >= 1:
      x = x*pow_by_binary(2,n,mod)
    x %= mod
    answer += x
    answer %= mod
print(answer)

Submission status: Accepted

Solution code:
def main():
    MOD = 10 ** 9 + 7

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

    b = [0] * 60
    for x in a:
        for j in range(60):
            b[j] += (x & 1) > 0
            x >>= 1

    t = 1
    ans = 0
    for j in range(60):
        ans = (ans + b[j] * (N - b[j]) * t) % MOD
        t <<= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
*A, = map(int, input().split())
p = 10**9+7
A = [format(a, '060b') for a in A]
s = 0
for i in range(60):
    Ai = [a[i] for a in A]
    c0 = Ai.count('0')
    c1 = n-c0
    c = c0*c1
    s = (s+c*(2**(59-i))) % p
print(s)

Submission status: Accepted

Solution code:
import numpy as np
 
mod = 10 ** 9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   # 最大桁数は、最も大きい数値の2進数の桁数
    num_1 = np.count_nonzero((A >> n)&1)   # 1の数をカウント
    num_0 = N - num_1                      # 0の数をカウント
    mul = num_1 * num_0   # 0 XOR 1の回数
    ans += ((2 ** n)*mul) % mod
ans %= mod
print(ans)

Submission status: Accepted

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

N = int(input())
A = list(map(int, input().split()))
x = [0] * 60
y = [0] * 60
for a in A:
    for i in range(60):
        if a >> i & 1:
            x[i] += 1
        else:
            y[i] += 1
ans = 0
mod = 10**9 + 7
for i in range(60):
    ans += x[i] * y[i] * (1 << i) % mod
    ans %= mod
print(ans)

Submission status: Accepted

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

    M = max(A)
    L = M.bit_length()
    ans = 0
    mod = 10**9 + 7
    k = [0]*max(1, L)
    k[0] = 1
    for i in range(1, L):
        k[i] = k[i-1]*2
    for j in range(L):
        count = 0
        for x in A:
            if (x >> j) % 2 == 1:
                count += 1
        ans += count*(N - count)*k[j]
    ans %= mod
    print(ans)


main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
mod = 10 ** 9 + 7

n = INT()
a = LIST()
arr = [0 for _ in range(61)]
for i in range(n):
    ai = a[i]
    for j in reversed(range(61)):
        arr[j] += ai % 2
        ai //= 2
ans = 0
for i in range(61):
    ans *= 2
    arri = arr[i]
    ans += arri * (n - arri if arri != 0 else 0)
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
mod=10**9+7
A=np.array(list(map(int, input().split())))
ans=0
for i in range(60):
  ones=np.count_nonzero(A>>i&1)
  zeros=N-ones
  ans+=ones*zeros*2**(i)%mod
  ans%=mod
  
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
a.sort()
lmx = len(bin(a[-1])) - 2
cnt = [[0,0] for _ in range(lmx)]
for i in a:
    for j in range(lmx):
        tt = 1 if (i>>j)&1 else 0
        cnt[j][tt] += 1

res = 0
for i,bit in enumerate(cnt):
    x,y = bit
    res += x*y*pow(2,i)
    res %= mod
print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
cnt = [0] * 65
ans = 0
for i in range(61):
    for x in a:
        if (x>>i)%2 == 1:
            cnt[i] +=1
for i in range(65):
    ans += (cnt[i]*(n-cnt[i])*(2**i))%mod
    ans %=mod
print(ans)

Submission status: Accepted

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

ans = 0
for d in range(62):
    mask = (1 << d)
    zero = len([0 for a in A if (a & mask) == 0])
    ans += zero * (N - zero) * mask % MOD
print(ans % MOD)

Submission status: Accepted

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

data=[0 for i in range(0,60)]

for i in range(0,N):
    for j in range(0,60):
        data[j]+=(A[i]>>j &1)

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

print(ans)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    max_bin_digits = len(bin(max(A))[2:])
    ans = 0
    for i in range(max_bin_digits):
        cnt = 0
        m = 1 << i
        for a in A:
            if m & a:
                cnt += 1
        
        ans += cnt * (N - cnt) * m
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    max_bin_digits = len(bin(max(A))[2:])
    ans = 0
    for i in range(max_bin_digits):
        cnt = 0
        for a in A:
            if 1 << i & a:
                cnt += 1
        ans += cnt * (N - cnt) * 2 ** i
        ans %= MOD

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    max_bin_digits = len(bin(max(A))[2:])
    cnts = [0] * max_bin_digits

    for a in A:
        for i in range(max_bin_digits):
            if 1 << i & a:
                cnts[i] += 1

    ans = 0
    for i in range(max_bin_digits):
        ans += cnts[i] * (N - cnts[i]) * 2 ** i
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

import numpy as np

def solve():
    n = II()
    A = np.array(LI())
    # print([bin(a) for a in A])
    mod = 1000000007
    ans = 0
    for i in range(0, 61):
        # i桁目が1の個数を数える
        x = np.count_nonzero(A & 1)
        y = n - x       # i桁目が0の個数
        # print(i, x, y)
        # XORなので x*y 通りの組み合わせ
        ans = ans + pow(2, i) * x * y % mod
        A = A >> 1
    print(ans % mod)



if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

import numpy as np

def solve():
    n = II()
    A = np.array(LI())
    # print([bin(a) for a in A])
    mod = 1000000007
    ans = 0
    for i in range(0, 61):
        # i桁目が1の個数を数える
        x = np.count_nonzero((A >> i) & 1)
        y = n - x       # i桁目が0の個数
        # print(i, x, y)
        # XORなので x*y 通りの組み合わせ
        ans = ans + pow(2, i) * x * y % mod
        # A = A >> 1
    print(ans % mod)



if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    A = LI()
    # print([bin(a) for a in A])
    mod = 1000000007
    ans = 0
    for i in range(0, 61):
        # i桁目が1の個数を数える
        x = 0
        for a in A:
            if (a >> i) & 1:
                x += 1
        y = n - x       # i桁目が0の個数
        # print(i, x, y)
        # XORなので x*y 通りの組み合わせ
        ans = ans + pow(2, i) * x * y % mod
    print(ans % mod)



if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
bittable=[0]*60
x=0
p=10**9+7
for i in range(N):
    x=A[i]
    for j in range(60):
        if (x>>j)&1:
            bittable[j]=bittable[j]+1
#print(bittable)
ans=0
for i in range(60):
    if bittable[i]!=0:
        ans=(ans+((N-bittable[i])*bittable[i]*pow(2,i,p))%p)%p
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
MOD = 1000000007
ans = 0
for d in range(60):
    ones = 0
    for a in l:
        if a >> d & 1:
            ones += 1
    zeroes = n - ones
    ans += pow(2, d, MOD) * ones % MOD * zeroes % MOD
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    _ = int(input())
    A = [int(x) for x in input().strip().split()]
    MOD = 10 ** 9 + 7
    ans = 0

    for i in range(60+1):
        zero = 0
        one = 0
        m = 1 << i
        for a in A:
            if a & m:
                one += 1
            else:
                zero += 1
        ans += (one * zero) * m
        ans = ans % MOD
    print(ans % MOD)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

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

print(s % mod)

Submission status: Accepted

Solution code:
import numpy as np
import sys
n = int(input())
a = np.array(sys.stdin.read().split(), dtype=np.int64)
mod = 10 ** 9 + 7
ans = 0
for i in range(63):
    b = (a >> i) & 1
    x = np.count_nonzero(b)
    x = x * (n - x)
    ans += x * pow(2, i, mod) % mod
print(ans % mod)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
mod = 10**9+7
a = np.array(list(map(int,input().split())))
ans = 0
for i in range(60):
    #aをiビット右にずらす、iは60桁目まで、&1で対象のビットが1のもの以外を0にその数をカウントする。
    b = np.count_nonzero(a >>i&1)
    ans += ((2**i)*(n-b)*b)%mod
print(ans%mod)

Submission status: Accepted

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

mod = 10**9 + 7
bit_num = [0] * 60
bit_0 = [0] * 60
bit_1 = [0] * 60
for i in a:
    for j in range(60):
        if( (i>>j)&1 == 1 ):
            bit_num[j] += bit_0[j]
            bit_1[j] += 1
        else:
            bit_num[j] += bit_1[j]
            bit_0[j] += 1

ans = 0
for i in bit_num[::-1]:
    ans *= 2
    ans += i
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys

def main():
  input = sys.stdin.readline
  n = int(input())
  a = np.array([int(x) for x in input().split()])
  inf = pow(10, 9)+7
  max_a = np.max(a)
  bit = 1
  ans = 0
  num = 0
  while max_a:
    num += 1
    max_a //= 2
  for _ in range(num):
    bit_count = np.sum(a%2)
    ans += ((((bit_count%inf)*((n-bit_count)%inf))%inf)*(bit%inf))%inf
    ans %= inf
    a //= 2
    bit *= 2
  print(ans)
  
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
num_one = [0 for i in range(61)]
num_zero = [0 for i in range(61)]
for num in l:
    for i in range(61):
        if (num>>i)&1 == 1:
            num_one[i] +=1
        else:
            num_zero[i] +=1
ans  = 0
for i in range(61):
    ans += (num_one[i] *num_zero[i])%(10**9+7) * (2**i%(10**9+7))
    ans = ans%(10**9+7)
print(ans)

Submission status: Accepted

Solution code:
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
  N = int(readline())
  A = np.array(read().split(), np.int64)
  ans = 0
  for i in range(63):
    B = (A>>i)&1
    x = np.count_nonzero(B)
    y = N - x
    x = x*y
    for _ in range(i):
      x *= 2
      x %= MOD
    ans += x
  ans %= MOD
  print(ans)
  
  
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        if isinstance(x, str):
            x = int(x)
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )

def calc(N, A, max_k):
    ret = ModInt(0)
    for k in range(max_k):
        count = 0
        for i in A:
            if i & (1 << k):
                count += 1
        ret += 2 ** k * count * (N - count)
    return ret

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

print(calc(N, A, max_k))

Submission status: Accepted

Solution code:
MOD, res = int(1E9 + 7), 0
n = int(input())
a = list(map(int, input().split()))
for i in range(60):
    cnt = 0
    for j in a:
        if j & (1 << i):
            cnt += 1
    res = (res + cnt * (n - cnt) * pow(2, i, MOD)) % MOD
print(res)

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
import numpy as np
A = np.array(alis,dtype=np.int64)
b = [0] * 61
count = 0
ans = 0
MOD = 10**9 + 7
while A.any():
    one = np.count_nonzero(A & 1)
    k = (1<<count) % MOD
    #ans += (one * (n - one) * pow(2, count, MOD)) % MOD
    ans += (one * (n - one)) * k % MOD
    ans %= MOD
    A >>= 1
    count += 1
 
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

import numpy as np

input = sys.stdin.readline
P = 10 ** 9 + 7


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

    ans = 0
    for b in range(60 + 1):
        cnt_1 = int(np.sum((A >> b) & 1))
        ans += 2 ** b * cnt_1 * (N - cnt_1)
        ans %= P
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    b = sum(map(lambda x: (x >> i)&1, a))
    c = n - b
    ans += b * c * (1<<i) % mod
print(ans%mod)