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, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
L = max(A).bit_length()
l = [0]*L

for a in A:
	for i, x in enumerate("{:b}".format(a).zfill(L)[::-1]):
		if x == "1":
			l[i] += 1

ans = 0

for i, x in enumerate(l):
	ans += (N-x)*x * pow(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(60):
    mask = 1 << d
    Z = len([0 for a in A if (a & mask) == 0])
    ans += mask * Z * (N - Z)
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
maxketa = max([len(bin(a[i])) for i in range(n)])-2
mod = 10**9+7
ans = 0
for i in range(maxketa):
	ones = 0
	for j in range(n):
		if (a[j] >> i) & 1:
			ones += 1
	ans = (ans + (n-ones)*ones*(2**i)) % mod
 
print(ans)

Submission status: Accepted

Solution code:
import sys
import  math
from heapq import *
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
A.sort(reverse=True)

mod=10**9+7
keta=[0]*60

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

ans=0

mod_div2=[0]*60
mod_div2[0]=1
for i in range(1,60):
    mod_div2[i]=(2*mod_div2[i-1])%mod
    
for i in range(len(A)):
    keta_max=0
    for j in range(60):
        if((A[i]>>j)&1):
            keta_max=j+1
    for j in range(keta_max):
            if((A[i]>>j)&1):
                keta[j]-=1
                ans+=mod_div2[j]*(len(A)-i-1-keta[j])
            else:
                ans+=mod_div2[j]*keta[j]
            ans%=mod


print(ans%mod)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
res = 0
for i in range(61):
  zeros, ones = 0, 0
  for a in A:
    if (a>>i)&1:
      ones += 1
    else:
      zeros += 1
  res += (zeros*ones) * (1<<i)
  res %= mod

print(res)

Submission status: Accepted

Solution code:
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
ans = 0
i = 0
while i < 60:
  mask = 2**i
  n = sum([1 if a&mask > 0 else 0 for a in A])
  ans += n*(N-n)*pow(2, i, mod)
  ans %= mod
  i += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    two_factor = 1
    for d in range(60):
        even = 0
        odd = 0
        for i in range(n):
            if a[i] & (1 << d):
                odd += 1
            else:
                even += 1
        add = (odd * even) % Mod * two_factor % Mod
        ans += add
        ans %= Mod
        two_factor = (two_factor * 2) % Mod
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

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

for k in range(60):
    count1 = 0
    for i in range(N):
        if (A[i]>>k) & 1:
            count1 += 1
    count0 = N-count1
    ans = (ans + count0*count1*2**k) % MOD

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

MOD = 10 ** 9 + 7

N = int(readline())
A = np.array(read().split(),np.int64)

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 *= 2
        x %= MOD
    answer += x
answer %= MOD
print(answer)

Submission status: Accepted

Solution code:
# 0がX個、1がY個ある(ただしX+Y=N)とき、Xorの組み合わせ自体は N*(N-1)//2 通りある。
# しかし、それらの和をとることを考えてみた時
# (0,0)と(1,1)を選んだ場合はそのXORは0になることに注意すると、(0,1)の組み合わせの個数だけ数えれば良い。
# これは、たとえば　〇〇〇●●●●(X=3,Y=4)から〇と●を選ぶ組み合わせは何個あるか、という問いと同じことなので
# Nの値には依存することはなく、単純にX*Y通りとなる。
# よって
# ΣΣ A_i Xor A_j = X*Y
# この処理によって、O(N^2)が、O(N)(=Aの各数字を一通り調べる)に減らせる。
# これを各ケタについて計算し、合計すれば良い。
# ケタ数が60まで定まっているので 計算量は O(Nlog(max(A)))≦ O(N*60)
# あるケタのbitを取り出すには ビットシフト「>>」でずらして下1ケタだけを見ると便利。


N=int(input())
A=list(map(int,input().split()))
p=10**9+7

ans=0
for k in range(60):
    cnt_z=0
    cnt_o=0
    #print(A)
    for i in range(N):
        s=A[i]%2
        if s==0:
            cnt_z +=1
        else:
            cnt_o +=1
        A[i] >>= 1
    ans += ((2**k)*cnt_z*cnt_o)%p
       
print(ans%p)

Submission status: Accepted

Solution code:
import sys
N = int(sys.stdin.readline().rstrip())
A = list(map(int, sys.stdin.readline().rstrip().split()))
mod = 10**9 + 7

cnt_one = [0] * 60
cnt_zero = [0] * 60

def count_bin(a):
    base = 1
    for i in range(60):
        if a % (base * 2) > 0:
            cnt_one[i] += 1
            a -= base
        else:
            cnt_zero[i] += 1
        base *= 2

for a in A:
    count_bin(a)

base = 1
ans = 0
for one, zero in zip(cnt_one, cnt_zero):
    ans += one * zero * base
    ans %= mod
    base *= 2
    base %= mod
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
str_a = ''.join(['{:060b}'.format(a) for a in map(int, input().split())])
mod = 10**9 + 7

rest = 0
for d in range(60):
  ones = str_a[59-d::60].count('1')
  rest = (rest + 2**d * ones * (n - ones)) % mod
    
print(rest)

Submission status: Accepted

Solution code:
N = int(input())
A = ''.join(list(map(lambda x: format(int(x), '060b'), input().split(' '))))
mod = 10 ** 9 + 7
ans = 0
for n in range(60):
    one = A[59-n::60].count('1')
    ans = (ans + 2**n *one*(N-one))%mod
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n = int(readline())
    a = [int(i) for i in readline().split()]
    s = 0
    P = int(1e9)+7
    for k in range(60):
        cnt = 0    
        for e in a:
            if (e>>k) & 1:
                cnt += 1
        s += cnt*(n-cnt)*pow(2, k, P)
        s %= P
    print(s)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
import numpy as np
#======================================================#
MOD=10**9+7
def main():
    n = II()
    aa = np.array(MII(), dtype='uint64')
    ans = 0
    for i in range(60):
        cnt1 = (aa&1).sum()
        ans += (cnt1*(n-cnt1))%MOD*(2**i)%MOD
        aa >>= 1
    print(int(ans%MOD))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
import numpy as np
#======================================================#
MOD=10**9+7
def main():
    n = II()
    aa = np.array(MII())
    ans = 0
    for i in range(60):
        cnt1 = int((aa&1).sum())
        ans += (cnt1*(n-cnt1)*(2**i))%MOD
        aa >>= 1
    print(ans%MOD)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
import numpy as np
#======================================================#
MOD=10**9+7
def main():
    n = II()
    aa = np.array(MII())
    ans = 0
    for i in range(60):
        cnt1 = int((aa&1).sum())
        ans += cnt1*(n-cnt1)*(2**i)
        aa >>= 1
    print(ans%MOD)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
  n=int(input())
  #a=list(map(lambda x:list(map(int,list(bin(int(x))[2:]))),input().split()))
  a=list(map(int,input().split()))
  mod=pow(10,9)+7
  bit=[0]*61
  for ai in a:
    for j in range(61):
      if ((ai>>j)&1):
        bit[j]+=1
  ans=0
  for i in range(61):# 2^iの位
    ans+=(pow(2,i,mod)*bit[i]*(n-bit[i]))%mod
    ans%=mod
  print(ans)
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
def main():
    from itertools import zip_longest
    n, *a = map(lambda x: bin(int(x))[2:][::-1], open(0).read().split())
    n = int('0b' + n[::-1], 2)

    mod = 10 ** 9 + 7
    ans = 0
    
    for i, j in enumerate(zip_longest(*a)):
        o = j.count('1')
        z = n - o
        ans += z * o * pow(2, i, mod)
        ans %= mod

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()
mod = 10**9 + 7


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

    a_max = max(A)
    a_len = len(A)
    keta = 0

    while True:
        a_max = a_max // 2
        keta += 1
        if a_max == 0:
            break

    # print(keta)
    t = [[0 for _ in range(keta)] for _ in range(2)]

    for k in range(keta):
        for a in A:
            a = a & (2**k)
            a = a >> k
            t[a][k] += 1

    # print(t)

    ans = 0
    for k in range(keta):
        ans += (t[0][k] * t[1][k]) * pow(2, k, mod)
        ans %= mod

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7


n = int(input())
values = list(map(int, input().split()))
pops = [sum([(value >> i) & 1 for value in values]) for i in range(60)]
print(sum([(1 << i) * pops[i] * (n - pops[i]) for i in range(60)]) % MOD)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    counts = [0] * 60

    for ai in a:
        for i in range(60):
            if ai & (1 << i):
                counts[i] += 1

    ans = 0
    base = 0

    for c in counts:
        ans += c * (n - c) * (1 << base)
        ans %= mod
        base += 1

    print(ans % mod)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = [0]*60
ans = 0
for i in A:
    for j in range(60):
        if (i >> j) & 1 == 1:
            count[j] += 1

time = 1
for i in count:
    ans += i*(N-i)*time
    time = time*2
print(ans%(10**9+7))

Submission status: Accepted

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

  mod=10**9+7
  ans=0

  for i in range(60):
      a=0
      for x in A:
          if x>>i&1:
              a+=1
      ans+=a*(N-a)*pow(2,i,mod)
      ans%=mod
  print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

mod=10**9+7
ans=0
cnt=[[0]*2 for _ in range(60)]

for x in A:
    for i in range(60):
        a=x%2
        x//=2
        cnt[i][a]+=1

for p,q in enumerate(cnt):
    i,j=q
    ans+=((i*j)%mod)*pow(2,p,mod)
    ans%=mod
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

a = [0 for i in range(n)]
a = [int(s) for s in input().split()]
res = 0

dig_0 = [0 for i in range(60)]
dig_1 = [0 for i in range(60)]

for i in range(n):
    #print("----")
    for j in range(60):
        #print(bin(a[i]>>j))
        s = (a[i]>>j)%2
        if(s == 1):
            dig_1[j] += 1
        else:
            dig_0[j] += 1

#print((3>>1)%2)
for i in range(60):
    #print(dig_0[i],dig_1[i])
    res += dig_0[i]*dig_1[i]*2**i
    #print(res)
md = 10**9 + 7
print(res%md)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    mod = 10**9 + 7
    b = 1
    c = 0
    for k in range(60):
        s = sum(ai & b for ai in a) // b
        c = (c + s * (n - s) * b) % mod
        b *= 2
    print(c)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

def main():
    n = int(input())
    a = np.array([int(i) for i in input().split()])
    mod = 10**9 + 7
    c = 0
    for k in range(60):
        kc = len(a[a & 1 == 1])
        c = (c + kc * (n - kc) * pow(2, k, mod)) % mod
        a //= 2
    print(c)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

    two_factor = 1
    res = 0
    for d in range(60):
        odd = 0
        even = 0
        for i in range(N):
            if A[i] & (1<<d) > 0:
                odd += 1
            else:
                even += 1
        res += odd * even % MOD * two_factor % MOD
        two_factor = two_factor * 2 % MOD
    
    print(res%MOD)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    P = int(1e9)+7
    s = 0
    for k in range(60):
        cnt = 0
        for num in A:
            if (num>>k) & 1:
                cnt += 1
        s += cnt*(N-cnt) * 2**k
        s %= P
    print(s)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

result = 0
for bit in range(60):
    m = 1 << bit
    c = sum(a & m for a in A) >> bit
    result += (c * (N - c)) << bit
    result %= 1000000007
print(result)

Submission status: Accepted

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

b = [0]*60
for a in A:
    digit = 0
    while a > 0:
        if a % 2 == 1:
            b[digit] += 1
        a = a >> 1
        digit += 1

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

Submission status: Accepted

Solution code:
import numpy as np

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

mod = 10**9 + 7
ans = 0

for i in range(60):
    c = len(A[A&1==1])
    A >>= 1
    ans = (ans + c*(N-c)*pow(2,i,mod))%mod

print(ans)

Submission status: Accepted

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

for i, j in enumerate(K):
    ans += (2**i) * j * (N - j)
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    n=int(input())
    A=np.array(list(map(int,input().split())))
    mod=10**9+7
    ans=0
    for i in range(60):
        c=np.count_nonzero(A&1)
        A>>=1
        ans+=(c*(n-c))<<i%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
n,*a=map(int,open(0).read().split())
mod=10**9+7
a=np.array(a)
ans=0
for i in range(60):
  c=len(a[a&1==1])
  a>>=1
  ans+=c*(n-c)*pow(2,i,mod)
  ans%=mod
print(ans)

Submission status: Accepted

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

di = 10**9+7
lis = [0 for i in range(61)]

for i in a:
    for j in range(61):
        if (i>>j & 1):
            #print(i,j)
            lis[j]+=1

#print(lis)

su = 0
for j in range(61):
    su+=lis[j]*(n-lis[j])*2**j
    su=su%di

print(su)

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc147/submissions/12994515を見た

import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
mod = 10**9+7
m2 = [1 for i in range(60)]
for i in range(1,60):
    m2[i] = (m2[i-1]*2)%mod

ans = 0
for i in range(60):
    ni = np.count_nonzero(a&1)
    ans = (ans+ni*(n-ni)%mod*m2[i])%mod
    a >>= 1

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

# mod = 10**9+7

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

# max_digit = 61

# count_0 = [0 for _ in range(max_digit)]
# count_1 = [0 for _ in range(max_digit)]

# for i in range(len(a)):
#     num_str = bin(a[i])[2:]
#     # print(num_str)
#     for j in range(len(num_str)):
#         # print(num_str[-j-1])
#         if num_str[-j-1] == "1":
#             count_1[-j-1] += 1

# # for i in range(max_digit):
# #     count_0[i] = n-count_1[i]

# ans = 0
# count = 1
# for i in range(61):
#     # tmp = count_0[-i-1]*count_1[-i-1]
#     tmp = count_1[-i-1]*(n-count_1[-i-1])
#     ans += tmp*count
#     count = (count*2) % mod
# print(ans % mod)


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

mod = 10**9+7
max_digit = 61

ans = 0
m = 1
for _ in range(max_digit):
    bit = sum(x&m for x in a)
    bit //= m
    non_bit = n - bit
    ans = (ans+bit*non_bit*m)%mod
    m <<= 1
print(ans)

Submission status: Accepted

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

def solve(N, A):
    ans = 0
    for k in range(61):
        num1 = 0
        for a in A:
            if (a >> k) & 1:
                num1 += 1
        ans += (num1 * (N-num1)) << k
        ans %= mod
    return ans
    
print(solve(N, A))

Submission status: Accepted

Solution code:
MOD = 1000000007

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

ans = 0
for i in range(0,60,1):
    zero_count=0
    one_count =0
    for j in range(0,N,1):
        if((A[j]>>i)&1):
            one_count+=1
        else:
            zero_count+=1
    ans =(ans%MOD + (one_count%MOD)*(zero_count%MOD)*pow(2,i,MOD))%MOD

print(ans)

Submission status: Accepted

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

cnt = [[0] * 2 for _ in range(61)]

for i in range(61):
    mask = 1 << i
    for j in range(n):
        if mask & a[j] >= 1:
            cnt[i][1] += 1
        elif mask & a[j] == 0:
            cnt[i][0] += 1
        else:
            continue

ans = 0
mod = 10**9 + 7
for i in range(61):
    ans += cnt[i][1] * cnt[i][0] * pow(2, i, mod)
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left

import sys
# sys.setrecursionlimit(1000000)
# list(map(int, input().split()))
mod = 10 ** 9 + 7

N = getN()
A = getList()
# Aの各数字の（２進数における）各桁ごとに分解して排他的論理和を求める
# 例
# 3
# 1 2 3 →
# 1, 10, 11
# 2 ** 0の桁について(1 ^ 2) 1 ^ 0 = 1,(1 ^ 3) 1 ^ 1 = 0,(2 ^ 3) 0 ^ 1 = 1
# 2 ** 1の桁について 0(1の2 ** 1の桁は0) ^ 1 = 1, 0 ^ 1 = 1, 1 ^ 1 = 0
# 各桁について2 ** iの桁が1の数字の選び方 * 2 ** iの桁が0の数字の選び方 * 2 ** iを
# 足し合わせる
lista = [[0, 0] for i in range(61)]
# bitの各桁が１か０かをlistaに収納
def splitbit(n):
    for i in range(61):
        if n & (1 << i):
            lista[i][1] += 1
        else:
            lista[i][0] += 1
for i in A:
    splitbit(i)
ans = 0
for i in range(61):
    ans += ((lista[i][0] * lista[i][1]) * (2 ** i)) % mod
print(ans % mod)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left

import sys
# sys.setrecursionlimit(1000000)
# list(map(int, input().split()))
mod = 10 ** 9 + 7

N = getN()
A = getList()
lista = [[0, 0] for i in range(61)]
# bitの各桁が１か０かをlistaに収納
def splitbit(n):
    for i in range(61):
        if n & (1 << i):
            lista[i][1] += 1
        else:
            lista[i][0] += 1
for i in A:
    splitbit(i)
ans = 0
for i in range(61):
    ans += ((lista[i][0] * lista[i][1]) * (2 ** i)) % mod
print(ans % mod)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7
def main():
    N = int(input())
    A = [int(_) for _ in input().split()]
    s = (sum(A) * (N-1))%MOD
    bA = [[0]*61 for _ in range(N)]
    for i in range(N):
        a = A[i]
        for j in range(61):
            a, x = divmod(a, 2)
            bA[i][j] = x
    cc = [0] * 61
    for i in range(N):
        for j in range(61):
            cc[j] += bA[i][j]
    coef = 1
    for i in range(61):
        coef *= 2
        if cc[i] < 2: continue
        s = (s - coef*cc[i]*(cc[i]-1)//2)%MOD
    print((s+MOD)%MOD)
    return

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
ans = 0
 
for i in range(60):
    #一桁目が1か0か調べて1の個数をカウント
    c1 = np.count_nonzero(arr & 1) 
    #1の個数×0の個数(XORだから)
    ans += 2 ** i * c1 * (n - c1)
    #桁をシフト
    arr =arr >> 1

print(ans % mod)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split());c=0;i=1
for _ in[0]*61:t=sum(i&b and 1for b in a);c+=t*(n-t)*i;c%=10**9+7;i*=2
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+=t*(n-t)*i;c%=10**9+7
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(60):
    c_1 = int((A&1).sum())
    ans += c_1*(N-c_1)*(2**i)
    A >>= 1

print(ans%MOD)

Submission status: Accepted

Solution code:
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
mx = max(A)
d = {i:0 for i in range(len(str(bin(mx)))-2)}
for a in A:
  for i in range(len(str(bin(a)))-2):
    if (a>>i)&1:
      d[i] += 1

ans = 0
for k, v in d.items():
  ans += v*(N-v) * (2**k)
  ans %= mod
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
c1_list = [0]*60
for i in range(n):
  b = format(a[i], '060b')

  for j in range(len(b)):
    if b[j] == "1":
      c1_list[j] += 1
count = 0
for i in range(60):
  count = (count + c1_list[i]*(n-c1_list[i])*2**(59-i)) % 1000000007
print(count)

Submission status: Accepted

Solution code:
#標準入力の受け取り
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

#Aの各値を二進数にした時の桁ごとに配列にまとめる
bit_lis = [0] * 61
for i in range(61):
    bit_lis[i] = np.count_nonzero(A & 1)
    A >>=1
        
#各桁について値を計算する
ans = 0
bit_1 = 0
mod = 10 ** 9 + 7
for i in range(61):
    bit_1 = bit_lis[i]
    if bit_1 == 0:
        continue
    ans += pow(2, i, mod) * bit_1 * (N-bit_1) 
    ans = ans % mod
print(ans)

Submission status: Accepted

Solution code:
M = 1000000007
def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans %= M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int,input().split())))
bit = []
ans = 0
mod = 10**9+7
for i in range(60):
    bit.append(np.count_nonzero(a&1))
    a >>= 1
for i in range(60):
    ans += ((n-bit[i])*bit[i]) * pow(2,i,mod)
    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 = []
ans = 0
mod = 10**9+7
# for i in a:
#     cnt = 1
#     while i:
#         bit[-cnt] += i%2
#         i //= 2
#         cnt += 1
for i in range(60):
    bit.append(np.count_nonzero(a&1))
    a >>= 1
# print(bit)
for i in range(60):
    ans += ((n-bit[i])*bit[i]) % mod * pow(2,i,mod)
    ans %= mod
print(ans%mod)

Submission status: Accepted

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

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

abi=[0]*61
aze=[0]*61

for item in a:
    j=0
    #print(bin(item))
    while j<61:
        #print(j)
        if item>>j & 1:
            abi[j]+=1
        else:
            aze[j]+=1
        j+=1

        #print(abi)

result=0
i=0
while i<61:
    result+=(2**i)%MOD*abi[i]%MOD*(aze[i])%MOD

    i+=1

#print(abi[:4])

#print(aze[:4])
print(result%MOD)


"""
01
10
11
"""



"""
0001
0010
0011
0100
0101
0110
0111
"""

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(60):
    l=0
    for ai in a:
        l+=(ai>>i)&1
    ans=(ans + 2**i * l * (n-l))%(10**9+7)
print(ans)

Submission status: Accepted

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

ans = 0
mod = 1000000007

for i in range(60):
    one_count =0
    zero_count = 0
    for j in range(N):
        if A[j] >> i & 1 == 1:
            one_count+=1
        else:
            zero_count+=1
    ans += (one_count*zero_count)*(2**i)
    ans = ans%mod
print(ans)

Submission status: Accepted

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

for i in a:
    j = 0
    while i > 0:
        if len(onecnts) - 1 < j:
            onecnts.append(0)
        if i % 2 != 0:
            onecnts[j] += 1
        j += 1
        i >>= 1

ans = 0
mod = 10**9+7

for i, onecnt in enumerate(onecnts):
    ans += onecnt * (n-onecnt) * (2**i)
    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 i in range(60):
    X = sum([1 for x in A if (x >> i) & 1])
    ans += (1 << i) * X * (N - X)
    ans %= mod

print(ans)

Submission status: Accepted

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

max_len = len(bin(max(a))[2:])
l = [0] * max_len

ans = 0
mod = 10**9 + 7

for i in range(max_len):
    for x in a:
        l[i] += x >> i & 1
    ans += pow(2, i, mod) * l[i] * (N-l[i])

print(ans % mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
import numpy as np
a = np.array(list(map(int,input().split())))
g = []
ans = 0
for j in range(60):
    d = np.count_nonzero(a&1)
    a >>= 1
    g.append(d)
for i in range(60):
    ans += g[i]*(n-g[i])*(pow(2,i,1000000007))
    ans = ans % (1000000007)
print(ans%(1000000007))

Submission status: Accepted

Solution code:
import numpy as np


def main():
    MOD = 10**9 + 7
    A_UB = 2**60  # upper bound
    MAX_BIN_LENGTH = len('{:b}'.format(A_UB))

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

    bit = 1
    answer = 0
    for b in range(MAX_BIN_LENGTH):
        a_bits = A & 1
        one_num = np.count_nonzero(a_bits)
        answer += (one_num * (N - one_num) * bit) % MOD
        answer %= MOD
        bit *= 2
        bit %= MOD
        A >>= 1
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
mod = 1000000007

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

bit = 1
ans = 0
for i in range(60):
    a_and = a & 1
    cnt_one = np.count_nonzero(a_and)
    ans += (cnt_one * (n - cnt_one) * bit) % mod
    ans %= mod
    a >>= 1
    bit *= 2
    bit % mod

print(ans)

Submission status: Accepted

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

bit = [0] * 61
for i in range(N):
    for x in range(61):
        if 2**x > A[i]:
            break
        else:
            bit[x] += (A[i]>>x)&1

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

print(ans)