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
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = [int(x) for x in readline().rstrip().split()]
B = [0] * 60
ans = 0
for i in range(N):
    i_bin = list(bin(A[i]))
    i_bin = i_bin[2:]
    i_bin = i_bin[::-1]
    k = 0
    for j in i_bin:
        if j == "1":
            B[k] += 1
        k += 1

for q in range(60):
    temp = B[q] * (N - B[q])
    ans += (temp % (7 + 10 ** 9)) * ((2 ** q) % (7 + 10 ** 9))
    ans %= 7 + 10 ** 9
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  one = [0]*62
  zero = [0]*62
  for number in a:
    for i in range(62):
      if number >> i &1 == 1:
        one[i] +=1
      else:
        zero[i] += 1
  ans = 0
  mod = 10**9+7
  for i in range(62):
    ans += one[i]*zero[i]*int(2**i)
    ans %= mod
  print(ans)
        
solve()

Submission status: Accepted

Solution code:
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
A = np.array(rl())
answer = 0
MOD = 10 ** 9 + 7

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

print(answer%MOD)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
md = 60
ans = 0
for d in range(md):
    cnt1 = sum([1 for i in a if ((i>>d)&1)]) # a内の全ての要素の d bit目の1の個数を数える
    ans += cnt1 * (n-cnt1) * (1<<d)          # 求めるべきは (0の個数)*(1の個数)をd bit目にそのまま収めたものを足し合わせたもの (?)
    ans %= mod                               # mod 取っておく

print(ans%mod)

Submission status: Accepted

Solution code:
import subprocess
import gzip, base64, os
import stat

gz = b'H4sIALyY7V0C/+19f2BU1ZX/m5n8GH5lBkQbEGTAIKASZiCERKskgYE3MAlIAlIrPpLJhKROZrIzbyDgj6JJLOMYZf261nW3lm+767bu1lK3tWgtBFGC1iqoIIo/UAFniEjEChGE+Z5z732T+968F6Ht7vcfn5I753PP/XHOPffcH+/H/aHbO89sMgnKZRauF5AyjSkjdBnDN/rSLICVCIPg7zhhjJADdDbHVyaUqcI+lrUSWhmfBf5lwb8SM6VLzGWqcAzjU0ITF2YL/FWmCmuWCqpQEBzpdFjX/Ssoun/FSlWYn0VxZ646nZml62Pp+hi/EgpmQRUq8mWxfzUMr2FyKeFcxjeX48dr8WG5Hn+3LqJ066IyVXg747tdk+4GSJcjnP9lZ+ESVp6RXiaz+iuh0g7TAk11xUXTAvVTA03BaOvU1p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OqNVy6Zx5rDUMEE/xkhknPmfaGzkoOBPmjrDW5l8fCUmNMPqC8ujJtIbejk2r/o5HbWv9FjvRVmst6qOitdJlHrKsFbEuEuEsIn3OeEZjnNfhw2Vl3Mm5mUcm63qRjPOTMzNRnzGtl4v6AHd1DrrHvhuclp4xwvmaW3QcxF93arim6/tDDVpzSp+trpaAjO9/3cndmjLJC8cZJnTeB2frDMs6p9kbdXeDQ8n12pM71VyjCvLEmd5x5Jlm83c4dltnYNSRLn3mvSZOddY1xLFDp7VH2WdqVTmVXGeGQ88V16mE9tD1TFNuWdvf8q6izLO7tfOOpqBA/dr/A8wdtFhjiwAA'
bin = gzip.decompress(base64.b64decode(gz))
p = os.path.dirname(__file__)
pymain = os.path.join(p, "a.out")
with open(pymain, "wb") as f:
    f.write(bin)
os.chmod(pymain, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
if p == "":
    pymain = "./" + pymain
subprocess.call(pymain)


# compiled by pythran
'''
#pythran export main2()
import numpy as np
i8 = np.int64
i4 = np.int32

def main2():
    stdin = open('/dev/stdin')
    N = int(stdin.readline())
    x = np.zeros(60, i8)
    for d in map(int, stdin.readline().split()):
        for j in range(x.shape[0]):
            if d & 1:
                x[j] += 1
            d >>= 1
    ans = 0
    for i in range(x.shape[0] - 1, -1, -1):
        ans = (ans * 2 + x[i] * (N - x[i])) % 1000000007
    print(ans)

'''

Submission status: Accepted

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

mod = 10**9 + 7
total = 0
for i in range(60):
  cnt = sum([1 for a in A if (a>>i & 1)])
  total += cnt * (n-cnt) * (1 << i)
  total %= mod
print(total)

Submission status: Accepted

Solution code:
def solve(a_s) -> int:
  # def get_ret_from_xs(xs) -> int:
  #   # 繰り上がり処理ありバージョン
  #   ret = 0
  #   for i, x in enumerate(xs):
  #     ret += 2**i * (x % 2)
  #     ret %= 10**9 + 7
  #   return ret
  #
  # def get_ret_from_xs2(xs) -> int:
  #   ret = 0
  #   for i, x in enumerate(xs):
  #     ret += 2**i * x
  #     ret %= 10**9 + 7
  #   return ret

  # zeros = [1, 1] + [0] * 58  # 各要素 0 ~ n. 要素iは、下 i +1 桁目が0である A_? の個数
  # ones = [2, 2] + [0] * 58 # 各要素 0 ~ n. 要素iは、下 i +1 桁目が0である A_? の個数
  zeros = [0] * 60

  ret = 0
  for i in range(60):
    ones = sum([(a >> i) & 0b1 for a in a_s])
    ret += 2**i * (ones * (len(a_s) - ones))
    ret %= 10**9 + 7
  return ret

  # for a in a_s:
  #   for i in range(len(zeros)):
  #     # a_bin = format(a, '060b')
  #     # a_i_digit_from_right = a_bin[60 - i - 1]
  #     # if a_i_digit_from_right == '0':
  #     #   zeros[i] += 1
  #     # else:
  #     #   ones[i] += 1
  #
  #     a_i_digit_from_right = (a >> i) & 0b1
  #     if a_i_digit_from_right == 0:
  #       zeros[i] += 1
  #
  # # 繰り上がり処理しないでも、各桁で収めてもいいんだ！
  # xs = [zeros[i] * (len(a_s) - zeros[i]) for i in range(60)]
  # return get_ret_from_xs2(xs)
  #
  #
  # # # 繰り上がりのせいで、xsの要素数は60を超えることがあるので注意
  # # xs = []
  # # i = 0
  # # while True:
  # #   x_i = 0
  # #   if i <= 59:
  # #     x_i = (zeros[i] * ones[i])
  # #   if i >= 1:
  # #     x_i += xs[i - 1] // 2
  # #   xs.append(x_i)
  # #
  # #   if i >= 60 and x_i // 2 == 0:
  # #     break
  # #
  # #   i += 1
  #
  # #xs = [2, 3, 1]
  # #return get_ret_from_xs(xs)


n = int(input().strip())
a_s = [int(s) for s in input().split()]

#a_s = [1, 2, 3]
#a_s = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]
#a_s = [3, 14, 159, 2653, 58979, 323846, 2643383, 27950288, 419716939, 9375105820]

print(solve(a_s))

Submission status: Accepted

Solution code:
import sys


def main():
    n = int(sys.stdin.readline().strip())
    a = [int(s) for s in sys.stdin.readline().strip().split(' ')]
    b = []

    maxlen = -1
    for i in range(n):
        ai = a[i]
        bi = format(ai, 'b')
        b.append(bi)
        if maxlen < len(bi):
            maxlen = len(bi)

    ans = 0
    for i in range(maxlen):
        ones = 0
        zeros = 0
        for j in range(n):
            if len(b[j]) < i + 1:
                zeros += 1
            else:
                target = b[j][-1-i]
                if target == '1':
                    ones += 1
                else:
                    zeros += 1
        ans += (2 ** i) * (ones * zeros)
        ans = ans % (10 ** 9 + 7)
    print(ans)


main()

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
c=0
for i in range(61):t=sum(2**i&b>0for b in a);c+=t*(n-t)*2**i
print(c%(10**9+7))

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
c=0
for i in range(61):t=sum(2**i&b>0for b in a);c=(c+t*(n-t)*2**i)%(10**9+7)
print(c)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
c=0
for i in range(61):
  i=2**i
  t=sum(i&b and 1for b in a)
  c=(c+t*(n-t)*i)%(10**9+7)
print(c)

Submission status: Accepted

Solution code:
def main():
  n,*a=map(int,open(0).read().split())
  c=0
  for i in range(61):
    i=2**i
    t=sum(i&b and 1for b in a)
    c=(c+t*(n-t)*i)%(10**9+7)
  print(c)
main()

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))
num=l[-1]
b1=[]

while num!=0:
  b1.append(num%2)
  num//=2
d={}
for i in range(len(b1)):
  d[i]=b1[i]

for i in range(2,n+1):
  num=l[-i]
  count=0
  while num!=0 or count<len(b1):
    d[count]+=num%2
    num//=2
    count+=1

ans=0
table=[1]
for i in range(60):
  table.append((2*table[-1])%(10**9+7))
for i in d: 
  ans=(ans+table[i]*(n-d[i])*d[i])%(10**9+7)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)

@mt
def slv(N, A):
    ans = 0
    M = Mod(10**9+7)
    for i in range(0, 60):
        m = 1 << i
        c = 0
        for a in A:
            if m & a > 0:
                c += 1
        ans = M.add(M.mul(M.mul(c, N-c), m), ans)
    return ans

def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))

    # N = 3 * (10**5)
    # A = [random.randint(0, 2**60) for _ in range(N)]
    # print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin, stdout
 
ii = lambda: int(stdin.readline())
mi = lambda: map(int, stdin.readline().strip().split())
li = lambda: list(mi())

MOD = int(10 ** 9 + 7)

n = ii()
A = li()

ans = 0
for j in range(60):
	cnt = [0] * 2
	for i in range(int(n)):
		c = (A[i] >> j) & 1
		ans += cnt[c ^ 1] << j
		cnt[c] += 1

ans %= MOD

stdout.write(str(ans) + "\n")

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
lists=list(map(int,input().split()))
length=61
use=[0 for i in range(61)]
a,b=divmod(n,9)
anslist=[0 for i in range(a+1)]
for  j in range(n):
    k=format(lists[j],"0%ib"%length)
    k=k[::-1]
    p,q=divmod(j,9)
    if p>a:
        anslist.append(str(k))
    else:
        anslist[p]+=int(k)
answer=0
for some in anslist:
    some=str(some)
    some=some.zfill(61)
    for j in range(61):
        if int(some[j])!=0:
            use[j]+=int(some[j])

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:
n = int(input())
xs = [int(x) for x in input().split()]
M = 10**9 + 7
r = 0
for i in range(61):
    k = 0
    for x in xs:
        k += (x >> i) % 2
    r = (r + ((n-k) * k % M) * pow(2, i) )% M

print(r)

Submission status: Accepted

Solution code:
n=int(input())
lists=list(map(int,input().split()))
length=61
use=[0 for i in range(61)]
a,b=divmod(n,9)
anslist=[0 for i in range(a+1)]
for  j in range(n):
    k=format(lists[j],"0%ib"%length)
    k=k[::-1]
    p,q=divmod(j,9)
    if p>a:
        anslist.append(str(k))
    else:
        anslist[p]+=int(k)
answer=0
for some in anslist:
    some=str(some)
    some=some.zfill(61)
    for j in range(61):
        if int(some[j])!=0:
            use[j]+=int(some[j])

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

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

ans = 0
for i in range(60):
    b = (a >> i) & 1
    cnt = np.sum(b[b > 0])
    tmp = cnt * (n - cnt)
    for _ in range(i):
        tmp = tmp * 2 % mod
    ans += tmp
print(ans % mod)

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):
    assert np.count_nonzero(arr & 1) == np.sum(arr & 1)
    c1 = np.count_nonzero(arr & 1)
    s += 2 ** i * c1 * (n - c1)
    arr >>= 1
print(s % mod)

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 >>= 1
print(s % mod)

Submission status: Accepted

Solution code:
import sys
import numpy as np
 
n = int(input())
lst = [int(i) for i in sys.stdin.readline().split()]
arr = np.array(lst, np.int64)
mod = 10 ** 9 + 7
s = 0

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
 
n = int(input())
lst = [int(i) for i in sys.stdin.readline().split()]
arr = np.array(lst, np.int64)
mod = 10 ** 9 + 7
c = []

while arr.any():
    c1 = np.count_nonzero(arr & 1)
    c.append(c1 * (n - c1))
    arr >>= 1
print(sum([(v * 2 ** i) for i, v in enumerate(c)]) % mod)

Submission status: Accepted

Solution code:
import sys
import numpy as np
 
n = int(input())
lst = [int(i) for i in sys.stdin.readline().split()]
arr = np.array(lst, np.int64)

mod = 10 ** 9 + 7
x_sum = 0

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

Submission status: Accepted

Solution code:
N = int(input())

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

ones = [0] * 60
m = 10 ** 9 + 7

for Ai in A:
    for digit in range(60):
        ones[digit] += ((Ai >> digit) & 1)

res = 0
for i, num in enumerate(ones):
    res += (1 << i) * num * (N - num)

print(res % m)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n = II()
    a = LI()
    maxa = max(a)
    bitmax = len(bin(maxa)) - 2
    ans = 0
    for i in range(bitmax):
        zero_num = 0
        one_num = 0
        for ai in a:
            if ai & (1 << i):
                one_num += 1
            else:
                zero_num += 1
        ans += (one_num * zero_num * (1 << i)) % mod
        ans %= mod
    print(ans)

    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

if __name__ == '__main__':
    main()