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 sys
import numpy as np

input = sys.stdin.buffer.readline
N = int(input())
A = np.array(list(map(int, input().split())))

MOD = 10**9 + 7

answer = 0
for n in range(63):
    B = (A >> n) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    for _ in range(n):
        x = x * 2 % MOD
    answer += x
answer %= MOD
print(answer)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    for i in range(60):
        cnt_one = 0
        for a in A:
            if (a >> i) & 1:
                cnt_one += 1
        res += (n - cnt_one) * cnt_one * pow(2, i)
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

ans = 0
mmm = int(1e9 + 7)
#for i in range(n):  # 1e5 ^ 2 なので...
#    for j in range(i+1, n):
#        ans = (ans + (aaa[i] ^ aaa[j])) % mmm

# 日本語的には自分より後ろのもの全部と xor を取った和

# 1 1 2 3 4 => 34
# 0 0 1
# 0 0 1
# 0 1 0 
# 0 1 1
# 1 0 0
#=======
# 4 2 1
#
# 4 * (4*1) + 2 * (3*2) * 1 * (2*3) = 34 (sum(ケタ * (0の数*1の数)) で合ってるっぽい?)
def get_bit_array(num):
    res = []
    while num > 0:
        res.append(num%2)
        num //= 2
    return res

bits = {}  # n がいくつあるか (n=1,2,4,8,...)
for i in range(n):
    t = aaa[i]
    bit_array = get_bit_array(t)
    r = 1
    for i in range(len(bit_array)):  # TLEかも
        bits[r] = bits.get(r, 0) + bit_array[i]
        r *= 2

# print(bits, n)
ans = 0
for k, v in bits.items():
    ans = (ans + k * (v * (n-v))) % mmm

print(ans)

Submission status: Accepted

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

for x in A:
  temp = bin(x)[2:]
  for i in range(len(temp)):
    if temp[-1-i] == "1":
      B[i] += 1

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np


def solve():
    ans = 0
    mask = 1
    for i in range(60):
        one_cnt = np.sum(A >> i & 1)
        tmp = one_cnt * (N - one_cnt)
        tmp %= MOD
        ans += tmp * mask
        ans %= MOD
        mask <<= 1
        mask %= MOD
    return ans


N, *A = map(int, open(0).read().split())
A = np.array(A, dtype=np.int64)
MOD = 1_000_000_007
print(solve())

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(len(bin(max(a)))):
  num_1 = np.count_nonzero((a>>i)&1)
  num_0 = n - num_1
  ans += (2**i)*(num_1*num_0) % mod
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
def main():
    N = int(stdin.readline().rstrip())
    A = list(map(int,stdin.readline().split()))
    mod = 10**9+7
    ans = 0
    for i in range(61):
        bits = 0
        for x in A:
            if (x>>i)&1:
                bits += 1
        ans += ((bits*(N-bits))* 2**i) %mod
    ans %= mod
    print(ans)
main()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
def main():
    N = int(stdin.readline().rstrip())
    A = list(map(int,stdin.readline().split()))
    mod = 10**9+7
    ans = 0
    for i in range(61):
        bits = 0
        for x in A:
            if (x>>i)&1:
                bits += 1
        ans += ((bits*(N-bits))* 2**i) %mod
    ans %= mod
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
mod = 10**9 + 7
 
def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
 
def main():
    n = ni()
    a = na()
    ans = 0
    for i in range(61):
        cnt = 0
        for ai in a:
            if (ai >> i) & 1:
                cnt += 1
        ans += ((cnt * (n - cnt)) * 2**i) % mod
    ans %= mod
    print(ans)
 
 
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#create date: 2020-07-05 10:13

import sys
stdin = sys.stdin

mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    ans = 0
    for i in range(61):
        cnt = 0
        for ai in a:
            if (ai >> i) & 1:
                cnt += 1
        ans += ((cnt * (n - cnt)) * 2**i) % mod
    ans %= mod
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    MOD = 10 ** 9 + 7
    two_factor = 1
    ans = 0
    for i in range(60):
        bit_count = 0
        for a in A:
            if (a>>i) & 1:
                bit_count += 1
        ans += bit_count*(N-bit_count)*two_factor
        ans %= MOD
        two_factor *= 2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
MOD = 10**9 + 7


def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter()
    for a in A:
        s = "{:0>63b}".format(a)[::-1]
        for i, s in enumerate(s):
            c[i] += int(s)
    ans = sum(A) * (N-1)
    for k, v in c.items():
        if v > 1:
            ans -= 2*(2**k)*(v*(v-1)//2)
    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def calculate(n,arr):

    maxValue = max(arr)

    if maxValue == 0:
        maxNum = 1
    else:
        maxNum = math.ceil(math.log(maxValue,2))

    arr = np.array(arr)

    oneArray =  [0]*(maxNum+1)
    zeroArray = [0]*(maxNum+1)

    for i in range(maxNum+1):
        s = (arr >> i) & 1

        a = np.count_nonzero(s)

        oneArray[i] = a
        zeroArray[i] = n - a


    finalResult = 0
    for  i in range(maxNum + 1):
        finalResult += 2**i * oneArray[i] * zeroArray[i]

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





calculate(N, ARR)

Submission status: Accepted

Solution code:
import math
import numpy as np

N = 10
ARR = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]

N = 10
ARR = [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]


# N = 3
# ARR = [1, 2, 3]

# N = 5
# ARR = [3, 6, 8, 9, 10]

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


def calculate(n, arr):
    if max(arr) == 0:
        mathNum = 1
    else:
        mathNum = math.ceil(math.log(max(arr), 2))

    oneArray =  [0] * mathNum
    zeroArray = [0] * mathNum

    result = 0
    arr = np.array(arr)
    for i in range(mathNum):
        s = (arr >> i) & 1

        oneCount = np.count_nonzero(s)
        zeroCount = n - oneCount
        oneArray[i] = oneCount
        zeroArray[i] = zeroCount

    for i in range(mathNum):
        result += (2 ** i) * (oneArray[i] * zeroArray[i])

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


calculate(N, ARR)

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())

mod = 10 ** 9 + 7
ans = 0
for bit in range(60):
    ctr = [0, 0]
    for i in range(N):
        ctr[A[i] >> bit & 1] += 1
    ans += (1 << bit) * (ctr[0] * ctr[1])
    ans %=mod
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque
import itertools


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


def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    l = [0] * 62
    n = [0] * 62
    for i in A:
        di = 0
        while i:
            if i % 2 == 1:
                l[di] += 1
            else:
                n[di] += 1
            i = i // 2
            di += 1
    di = 1
    ans = 0
    for j in range(61):
        ans += l[j] * (N - l[j]) * di

        di *= 2
        ans %= mod
    ans %= mod
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# 解説を参考に作成
# 提出 #14841909 を参考に作成

# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, As):
    import math
    x = 1 if max(As) == 0 else math.ceil(math.log2(max(As)))
    ans = 0
    mod = 10 ** 9 + 7

    for i in range(x):
        cnt = sum((A >> i) % 2 for A in As)
        ans += (cnt * (N - cnt)) * pow(2, i, mod)
        ans = ans % mod
    print(ans)


if __name__ == '__main__':
    N = int(input())
    As = [int(i) for i in input().split()]
    # N = 3 * 10 ** 5
    # import random
    # As = [random.randint(2 ** 59, 2 ** 60) for _ in range(N)]
    solve(N, As)

Submission status: Accepted

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

for bit in range(60):
    m = 1 << bit
    # bit桁目のbitが立っている時の数
    c = sum(a&m for a in A) >> bit
    # bit桁目の1の合計
    ans += (c*(N-c))<<bit
    # 繰り上がりのない足し算
    ans %= mod
print(ans)

Submission status: Accepted

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

bit = [0] * 60
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    n1 = np.count_nonzero((a >> i) & 1)
    n0 = n - n1
    ans += (2 ** i) * n1 * n0 % mod
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(60):
  cnt_zero = 0
  cnt_one = 0
  for j in range(n):
    if a[j] >> i & 1:
      cnt_one += 1
    else:
      cnt_zero += 1
  ans += 2**i*cnt_zero*cnt_one
  ans %= mod
print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from functools import reduce, lru_cache
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

class ModInt:
    def __init__(self, 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 inverse(self):
        return pow(self.x, MOD - 2, MOD)

def main():
    N = I()
    A = LI()

    C0, C1 = [0] * 60, [0] * 60

    for d in range(60):
        for ai in A:
            C0[d] += (ai >> d & 1) == 0
            C1[d] += (ai >> d & 1) == 1

    ans = ModInt(0)
    for (d, (a, b)) in enumerate(zip(C0, C1)):
        ans += a * b * (1 << d)
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from functools import reduce, lru_cache
import functools
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N = I()
    A = LI()

    C0, C1 = [0] * 60, [0] * 60

    for d in range(60):
        for ai in A:
            C0[d] += (ai >> d & 1) == 0
            C1[d] += (ai >> d & 1) == 1

    ans = 0
    for (d, (a, b)) in enumerate(zip(C0, C1)):
        ans = (ans + a * b * (1 << d % MOD)) % MOD
    print(ans % MOD)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(60):
    j = 1 << i
    cnt = sum((k & j) >> i for k in A)
    ans += (cnt * (N - cnt)) << i
    ans %= mod
    
print(ans)

Submission status: Accepted

Solution code:
#昔はtleの回答、今は通る？
import sys
input=sys.stdin.readline
n=int(input())
lists=list(map(int,input().split()))
aa=[0 for i in range(n)]
bb=[0 for i in range(n)]
length=61
use=[0 for i in range(61)]
for  j in range(n):
    k=format(lists[j],"0%ib"%length)
    k=k[::-1]
    aa[j]=k[:30]  
    bb[j]=k[30:]
for p in aa:    
    for some in range(30):
        use[some]+=int(p[some])
for q in bb:    
    for some in range(31):
        use[some+30]+=int(q[some])
answer=0

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    M = 60

    ans = 0
    p = 1
    for d in range(M):
        n = 0
        for i in range(N):
            if A[i] & (1 << d):
                n += 1
        ans = (ans + n * (N - n) * p) % MOD
        p = p * 2 % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    M = 60

    ans = 0
    p = 1
    for _ in range(M):
        n = 0
        for i in range(N):
            A[i], d = A[i] // 2, A[i] % 2
            n += d
        ans = (ans + n * (N - n) * p) % MOD
        p = p * 2 % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    M = 60

    ans = 0
    p = 1
    for _ in range(M):
        n = 0
        for i, a in enumerate(A):
            if not a:
                continue
            A[i], d = a // 2, a % 2
            if d:
                n += 1
        ans = (ans + n * (N - n) * p) % MOD
        p = p * 2 % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    M = 61
    C = [0] * M
    for a in A:
        for i in range(M):
            if not a:
                break
            a, r = a // 2, a % 2
            if r:
                C[i] += 1

    ans = 0
    p = 1
    for c in C:
        ans = (ans + c * (N - c) * p) % MOD
        p = p * 2 % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    M = 61
    C = [0] * M
    for a in A:
        a = str(format(a, 'b'))
        for i, d in enumerate(reversed(a)):
            if d == '1':
                C[i] += 1

    ans = 0
    p = 1
    for c in C:
        ans = (ans + c * (N - c) * p) % MOD
        p = p * 2 % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    M = 61
    for i, a in enumerate(A):
        A[i] = list(map(int, str(format(a, 'b')).zfill(M)[::-1]))

    csum = [[0] * M for _ in range(N)]
    csum[0] = A[0]
    for i in range(1, N):
        for j in range(M):
            csum[i][j] = csum[i - 1][j] + A[i][j]

    p2 = [0] * M
    p2[0] = 1
    for i in range(M - 1):
        p2[i + 1] = p2[i] * 2 % MOD

    B = [0] * M
    for i, a in enumerate(A[1:], 1):
        for j in range(M):
            B[j] += csum[i - 1][j] if a[j] == 0 else i - csum[i - 1][j]

    ans = 0
    for j in range(M):
        ans = (ans + B[j] * p2[j]) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    M = 61
    for i, a in enumerate(A):
        A[i] = list(map(int, str(format(a, 'b')).zfill(M)[::-1]))

    csum = [[0] * M for _ in range(N)]
    csum[0] = A[0]
    for i in range(1, N):
        for j in range(M):
            csum[i][j] = csum[i - 1][j] + A[i][j]

    p2 = [0] * M
    p2[0] = 1
    for i in range(M - 1):
        p2[i + 1] = p2[i] * 2 % MOD

    ans = 0
    for i, a in enumerate(A[1:], 1):
        for j in range(M):
            n = csum[i - 1][j] if a[j] == 0 else i - csum[i - 1][j]
            ans = (ans + n * p2[j]) % MOD

    print(ans)
    return


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 i in range(60):
  n1 = np.count_nonzero((A>>i)&1)
  n0 = n-n1
  ans += (2**i)*n1*n0 % mod
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0

for j in range(61):
    one = 0
    zero = 0
    for i in a:
        if (i >> j) & 1 == 1:
            one += 1
        else:
            zero += 1
    ans += one*zero*2**j
    ans %= 10**9 + 7

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d=0
m=10**9+7
for i in range(60):b=1<<i;l=len([1for j in a if j&b]);d+=l*(n-l)*b%m;d%=m
print(d)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = 10**9+7
for i in range(60):
  j = 1<<i
  cnt = sum((k & j) >> i for k in a)
  ans += (cnt*(n-cnt))<<i
  ans%= mod
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())))
 
 
tmp = 0
for n in range(len(bin(max(A)))-2):   # 最大桁数は、最も大きい数値の2進数の桁数
    num_1 = np.count_nonzero((A >> n)&1)   # 1の数をカウント
    num_0 = N - num_1                      # 0の数をカウント
    mul = num_1 * num_0   # 0 XOR 1の回数
    tmp += ((2 ** n)*mul) % mod
ans = tmp%mod
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
mod = 10**9 + 7
n = int(input())
dat = list(map(int, input().split()))
cnt0 = [0] * 64
cnt1 = [0] * 64
for i in range(n):
    for j in range(62):
        if ((dat[i] >> j) & 1) == 1:
            cnt1[j] += 1
        else:
            cnt0[j] += 1
#print(cnt0)
#print(cnt1)
res = 0
for i in range(62):
    res += (cnt0[i] * cnt1[i]) << i
    res %= mod
print(res)

Submission status: Accepted

Solution code:
import numpy as np 
# 初期入力
mod = 10**9 +7
ans =0
N =int(input())
A =list(map(int,input().split()))
A_np =np.array(A,dtype=np.int64)

# xor 各桁の０と1の数を求め
for i in range(60):
    c =np.count_nonzero(A_np &1)
    ans +=2**i*c*(N-c)
    A_np >>=1
print(ans %mod)

Submission status: Accepted

Solution code:
mod = pow(10, 9) + 7
N = int(input())
# 制約が a<2**60 なので
L = 60

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

counter = [0] * L
for a in A:
    for i in range(L):
        counter[i] += a & 1
        a >>= 1

tmp = 0
for i in range(L):
    tmp += counter[i] * (N - counter[i]) * (2 ** i)
    tmp %= mod

print(tmp)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

a.sort(reverse = True)

#l = len(bin(a[0])[2:])

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


print(ans%mod)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
num_list = np.array(input().split(), dtype="int")

max_num = max(num_list)
max_bit_num = format(max_num, "b")
max_bit_num_length = len(max_bit_num)
ans = 0
radix = 1
for i in range(max_bit_num_length):
  new_num_list = (num_list >> i) & 1
  one_amount = np.count_nonzero(new_num_list == 1)
  zero_amount = len(num_list) - one_amount
  ans += (one_amount*zero_amount)*radix
  radix *= 2
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    for i in range(60):
        cnt = 0
        for a in A:
            cnt += (a >> i) & 1
        res += (cnt * (n - cnt)) % mod * (1 << i) % mod
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

ans = 0
for i in range(60):
    mask = 1 << i
    cnt = sum([1 for x in arr if x & mask == mask])
    ans += mask * cnt * (n - cnt) % MOD

print(ans % MOD)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    ans = 0
    for i in range(61):
        p = 1
        for _ in range(i):
            p *= 2
            p %= MOD
        x = 0
        for a in A:
            if a >> i & 1:
                x += 1
        t = x * (N - x)
        t %= MOD
        t *= p
        t %= MOD
        ans += t
        ans %= MOD
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())
mod = 10**9 + 7
 
ans = 0
for i in range(60):
    mask = 1 << i
    cnt = 0
    for a in A:
        if a & mask:
            cnt += 1
    x = cnt * (N-cnt)
    x *= mask % mod
    ans += x
    ans %= mod
 
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, *A = map(int, open(0).read().split())
A = np.array(A, dtype=np.int64)
mod = 10**9 + 7

ans = 0
for i in range(60):
    mask = 1 << i
    cnt = np.count_nonzero(A&mask)
    x = cnt * (N-cnt)
    x *= mask % mod
    ans += x
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())
mod = 10**9 + 7

ans = 0
for i in range(60):
    mask = 1 << i
    cnt = 0
    for a in A:
        if a & mask:
            cnt += 1
    x = cnt * (N-cnt)
    x *= mask % mod
    ans += x
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())
mod = 10**9 + 7

batch = 8
rg = tuple(range((63//batch)+1))
mask = (1<<batch) - 1
B = [[0]*(1<<batch) for _ in rg]
for a in A:
    for i in rg:
        B[i][a & mask] += 1
        a >>= batch

xr = [[] for _ in [0]*(1<<batch)]
for i in range(1<<batch):
    for j in range(i+1, 1<<batch):
        xr[i].append(i^j)

ans = 0
shift = 1
for b in B:
    x = sum(xr[i][j]*bi*bj for i, bi in enumerate(b) for j, bj in enumerate(b[i+1:]))
    x %= mod
    x *= shift
    x %= mod
    shift <<= batch
    shift %= mod
    ans += x
    ans %= mod
print(ans)