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,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
input=lambda: sys.stdin.readline().rstrip()

class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=1):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.node_size=len(ls)+1
                self.edges,_=GI(self.node_size,self.node_size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.node_size=int(input())
        else:
            self.node_size=inp_size
        self.edges,_=GI(self.node_size,self.node_size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.node_size=len(ls)+1
        self.edges,_=GI(self.node_size,self.node_size-1,ls,index=index)
        return
 
    def dfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.node_size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def bfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.node_size
        v[x]=root_v
        while q:
            c=q.popleft()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def parent(self,x):
        return self.dfs(0,func=lambda pr,prv,nx,dist:pr,root_v=-1)
 
    def topological_sort(self,x):  # return topological sort of the tree
        tps=[]
        q=deque([x])
        v=[None]*self.node_size
        v[x]=0
        while q:
            c=q.popleft()
            tps.append(c)
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=0
        return tps
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.node_size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.node_size
        self.ETout=[-1]*self.node_size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        #self.st=SegTree(self.node_size*2-1,self.ETdepth,function=min,ide=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]
 
    def __str__(self):
        return  str(self.edges)
 
    def show(self):
        if all([all([d==1 for nd,d in e]) for e in self.edges]):
            print( [[nd for nd,d in e] for e in self.edges] )
        else:
            print(self)

class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    # return boundary index of r such that func({table[i]} =< x , i in [pos,r]
    def right_bound(self,pos,x):
        k=(self.size-pos).bit_length()
        for j in range(k)[::-1]:
            nx=pos+(1<<j)
            if nx<n and self.query(pos,nx+1)<=x:
                pos+=(1<<j)
        return pos
    
    # return boundary index of l such that func({table[i]} =< x , i in [l,pos]
    def left_bound(self,pos,x):
        k=pos.bit_length()
        for j in range(k)[::-1]:
            nx=pos-(1<<j)
            if 0<=nx and self.query(nx,pos+1)<=x:
                pos-=(1<<j)
        return pos
 
    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)


show_flg=False
show_flg=True


ans=0
n=I()
a=LI()
for j in rep(61):
    b=[(i>>j)&1 for i in a]
    one=sum(b)
    zero=n-one
    ans+=(1<<j)*one*zero
    ans%=mo
    #show(b)
print(ans)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
import os
from operator import ixor

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = [list(map(int, input().split()))]
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n = int(input())
    a_s = list(map(int, input().split()))

    one_counts = [0 for i in range(61)]
    zero_counts = [0 for i in range(61)]

    # 以下、XORで便利と思われる処理。
    # -------------------------------------------
    # ループ回数の取得(最大の数値の桁数分、ループ処理を行うようにする)
    max_num = max(a_s)
    max_loop = 0
    for i in range(0, 61):
        if max_num < 1 << i:
            break
        max_loop += 1

    # ループ処理にて、各桁の0と1の個数を数え上げる。
    # 例：入力[1(01),2(10),3(11)] -> one_count=[2,2,0・・]とzero_counts[1,1,0・・]を得る。
    for a in a_s:
        for i in range(0, max_loop):
            if a & 1 << i:
                one_counts[i] += 1
            else:
                zero_counts[i] += 1
    # -------------------------------------------
    # 以上、XORで便利と思われる処理。

    # 結果を計算する処理
    ans = 0
    for i in range(0, max_loop):
        # 各桁の「0の個数」*「1の個数」*2^(0～桁数-1乗まで) を加算していく
        ans += (one_counts[i] * zero_counts[i] * pow(2, i)) % (pow(10, 9) + 7)
        ans = ans % (pow(10, 9) + 7)

    # 結果を出力
    print(ans)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
1 2 3"""
        output = """6"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """10
3 1 4 1 5 9 2 6 5 3"""
        output = """237"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820"""
        output = """103715602"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Accepted

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

m = 1000000007

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

Submission status: Accepted

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

m = 1000000007

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A = np.fromiter(map(int, input().split()), np.int64)

m = 1000000007

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

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):
    c=0
    for j in A:
      if j>>i&1:
        c+=1
    ans+=pow(2,i,mod)*c*(N-c)
    ans%=mod
  print(ans)
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

n = ir()
a = lr()

dp = [0 for i in range(60)]

for num in a:
    for j in range(60):
        if ((num >> j) & 1):
            dp[j]+=1
ans = 0
for i in range(60):
    k = dp[i]
    tmp = k*(n-k)*power(2,i,mod)%mod
    ans = (ans+tmp)%mod
print(ans)

Submission status: Accepted

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

ans = 0
for bit in range(60):
    m = 1 << bit
    c = sum(a & m for a in A) >> bit
    ans += (c * (n - c)) << bit
    ans %= (10**9+7)
print(ans)

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:
mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
keta = [[0,0] for _ in range(60)]
for i in a:
    for j in range(60):
        if (i >> j) & 1:
            keta[j][1] += 1
        else:
            keta[j][0] += 1
ans = 0
for i in range(len(keta)):
    lis = keta[i]
    ans += lis[0] * lis[1] * 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 i in range(60):
  X=1<<i
  n=len([1 for a in A if a&X])
  ans+=X*n*(N-n)%mod
  ans%=mod
print(ans)

Submission status: Accepted

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

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

    ans = 0
    for d in range(60):
        mask = 1<<d
        num1 = len([1 for A in As if A & mask])
        ans += num1 * (N-num1) * mask
        ans %= MOD

    print(ans)


solve()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    M = max(A)
    dig = len(bin(M)) - 2
    MOD = 10 ** 9 + 7
    ans = 0
    d = {i: [0, 0] for i in range(dig)}
    for a in A:
        a = bin(a)[2:].zfill(dig)
        for i in range(len(a)):
            if a[-(i+1)] == '0':
                d[i][0] += 1
            else:
                d[i][1] += 1
    for i in range(dig):
        ans += d[i][0] * d[i][1] * pow(2, i, MOD)
        ans %= MOD
    print(ans)
main()

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):
    cnt = 0
    for a in A:
        cnt += a>>i&1
    ans += cnt*(N-cnt)*2**i
    ans %= mod
    # print(ans)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
def main():
    mod = 1000000007
    n = int(input())
    A = np.array(list(map(int, input().split())), dtype = np.int)
    ans = 0
    for i in range(61):
        n1 = np.sum((A >> i) & 1)
        tmp = (n - n1) * n1
        for _ in range(i):
            tmp = (tmp * 2) % mod
        ans += tmp
    print(ans % mod)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

bitlist = [0] * 60

for i in A:
    for index, num in enumerate(reversed(bin(i)[2:])):
        if num == "1":
            bitlist[index] += 1
ans = 0
for bit, num in enumerate(bitlist):
    ans += num * (N-num) * (2 ** bit)
    ans %= (10**9+7)
print(ans)

Submission status: Accepted

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

sum_all = 0
p = 1
for i in range(60):
    ones = 0
    zeros = 0

    x = 1 << i
    for a in A:
        if a & x:
            ones += 1
        else:
            zeros += 1

    sum_all += p * ones * zeros % MOD
    p *= 2 % MOD


print(sum_all % MOD)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():

    N = int(input())
    A = list(map(int, input().split()))
    p = 10**9 + 7
    total = 0
    for i in range(60):
        cnt_1, cnt_0 = 0, 0
        for j in range(N):
            if (A[j]>>i)&1:
                cnt_1 += 1
            else:
                cnt_0 += 1
        total += pow(2, i, p) * cnt_0 * cnt_1 %p
    print(total%p)
main()

Submission status: Accepted

Solution code:
import numpy as np

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

ans = 0
MOD = 10**9+7

k = max(a)
j = 0
while k:
    bits = (a>>j)&1
    one = np.count_nonzero(bits)
    ans += (one%MOD)*((n-one)%MOD)*pow(2,j,MOD)
    ans %= MOD
    j += 1
    k >>= 1

print(ans)

Submission status: Accepted

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

ans = 0

po = 1
for i in range(61):
    bit = (a>>i) & 1
    s=np.count_nonzero(bit)
    ans+=s*(n-s)%N*po
    ans%=N
    po*=2
    po%=N
print(ans)

Submission status: Accepted

Solution code:
##かっこいい実装
import numpy as np
#mod = 10**9+7
#n = int(input())
#a = np.fromstring(input(), dtype = np.int64, sep = ' ')
#
#result = 0
#for i in range(60):
#    count_one = int((a&1).sum())
#    result += count_one*(n-count_one)*(2**i)
#    a >>= 1
#print(result%mod)

N = int(input())
A = np.fromstring(input(),dtype = np.int64, sep = ' ')
Large = 10**9 + 7
ans = 0
for i in range(60):
    sum1 = int((A&1).sum())
    ans += sum1*(N-sum1) * 2**i
    #ans %= Large
    A>>=1 # A = A>>1とする
print(ans%Large)

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction

# 10進数表記でnのk進数を求めてlength分0埋め
def ternary (n, k, length):
    if n == 0:
        nums = ['0' for i in range(length)]
        nums = ''.join(nums)
        return nums
    nums = ''
    while n:
        n, r = divmod(n, k)
        nums += str(r)
    nums = nums[::-1]
    nums = nums.zfill(length)
    return nums


def main():
    num = int(input())
    data = list(map(int, input().split()))
    mod = 10 ** 9 + 7

    max_length = len(bin(max(data))) - 2
    bit_count = [0 for i in range(max_length)]

    for i in range(num):
        now_bin = bin(data[i])[2:]
        now_bin = now_bin.zfill(max_length)
        for j in range(max_length):
            if now_bin[j] == "1":
                bit_count[j] += 1

    flg_data = [0 for i in range(max_length)]


    for i in range(max_length):
        flg_data[i] += bit_count[i] * (num - bit_count[i])

    ans = 0
    for j in range(max_length):
        pow_num = max_length - 1 - j
        bbb = pow(2, pow_num, mod)

        ans += bbb * flg_data[j]
        ans %= mod

    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

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

arr = [0] * 60
for a in A:
    for i in range(60):
        if a>>i & 1:
            arr[59-i] += 1

ans = 0
for i, a in enumerate(arr):
    b = N - a
    ans += (a*b) * (2**(59-i))
    ans %= MOD
print(ans)

Submission status: Accepted

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

res = 0
po2 = 1
for i in range(61):
    bit = (s >> i) & 1
    x = np.count_nonzero(bit)
    y = n - x
    res += x * y % mod * po2
    res %= mod
    po2 *= 2 % mod
print(res)

Submission status: Accepted

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

mod = 10 ** 9 + 7

res = 0
two_factor = 1
for i in range(60):
    cnt_1 = 0
    cnt_0 = 0
    for v in a:
        if (v >> i) & 1:
            cnt_1 += 1
        else:
            cnt_0 += 1
    res = (res + cnt_1 * cnt_0 % mod * two_factor % mod) % mod
    two_factor = two_factor * 2 % mod

print(res)

Submission status: Accepted

Solution code:
def mod_pow(a, n):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


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

mod = 10 ** 9 + 7

cnt = [0] * 60
for v in a:
    for i in range(60):
        if (v >> i) & 1:
            cnt[i] += 1

pow_2 = [1]
for i in range(60):
    pow_2.append(pow_2[-1] * 2 % mod)

res = 0
for v in a:
    for i in range(60):
        if (v >> i) & 1:
            res = (res + (n - cnt[i]) * pow_2[i] % mod) % mod
        else:
            res = (res + cnt[i] * pow_2[i] % mod) % mod

print(res * mod_pow(2, mod - 2) % mod)

Submission status: Accepted

Solution code:
import numpy as np
MOD = 10 ** 9 + 7
N = int(input())
A = np.array(input().split(), dtype=np.int64)
total = 0
for shamt in range(65):
    bits = np.count_nonzero(A & 1)
    total += (bits * (N - bits)) << shamt
    A >>= 1
    if not A.any():
        break
print(total % MOD)

Submission status: Accepted

Solution code:
def str2bitstr(chs):
    val = int(chs)
    tmp = bin(val)[2:]
    tmp2 = '0' * (60 - len(tmp))
    return tmp2 + tmp


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

cnts = [0] * 60

for item in a:
    for i, ch in enumerate(item):
        if ch == '1':
            cnts[i] += 1

ret = 0
now = 1

for i in range(1, 61):
    kumi = cnts[-i] * (n - cnts[-i]) % (10 ** 9 + 7)
    ret += kumi * now % (10 ** 9 + 7)
    now *= 2 % (10 ** 9 + 7)
    ret = ret % (10 ** 9 + 7)

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

Submission status: Accepted

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

N = int(readline())
A = np.array(readline().split(),dtype=int)
DIV = 10 ** 9 + 7

# 各桁の1と0の数を数えて、((1の数) * (0の数)) * (2 ** i桁目(1桁目を0とする))を数える

K = max(A)
  
j = 0
ans = 0
while K:
  bits = (A >> j) & 1
  one = np.count_nonzero(bits)
  ans += (one % DIV) * ((N - one) % DIV) * pow(2,j,DIV)
  ans %= DIV
  j += 1
  K >>= 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    mod=10**9+7
    n=int(readline())
    a=list(map(int,readline().split()))
    a=np.array(a,dtype=np.int64)

    b=np.array([((a>>i)&1).sum() for i in range(61)],dtype=np.int64)
    c=np.full(61,n,dtype=np.int64)-b
    d=b*c
    d%=mod

    ans=0
    now=1
    for i in range(60):
        ans+=d[i]*now
        ans%=mod
        now*=2
        now%=mod

    print(ans)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter 
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
import bisect
import sys
#import sympy
sys.setrecursionlimit(10**6)


def bfs(s,n,node):
    #頂点が探索済みかどうかのチェック配列
    check=[False for _ in range(n)]
    check[s]=True
    #次見る頂点を格納するキュー
    queue=deque([s])
    visited_num=1

    #問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color=[-1 for _ in range(n)]
    color[s]=0
    
    while visited_num<n:
        #グラフが全連結ではない場合
        if len(queue)==0:
            #空配列を返す
            #現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex=queue.popleft()
        #インデックスがない場合は
        for next_vertex in node[now_vertex]:


            if check[next_vertex]==True:
                continue

            queue.append(next_vertex)
            check[next_vertex]=True

            #問題固有の計算
            color[next_vertex]=color[now_vertex]+1
            visited_num+=1

    return color

#n=int(input())z
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))



n=int(input())
#n,m=input_list()
a=input_list()
f_num=60
z_arr=[0 for _ in range(f_num)]
o_arr=[0 for _ in range(f_num)]
#a=[bin(i)[2:].zfill(f_num) for i in tmp]
for each in a:
    cal=bin(each)[2:].zfill(f_num)
    for i in range(f_num):
        if (cal[i])=="0":
            z_arr[i]+=1
        else:
            o_arr[i]+=1
mod=10**9+7
ans=0



for keta_i in range(f_num):
    cal=((z_arr[keta_i]*o_arr[keta_i])%mod*pow(2,f_num-keta_i-1,mod))%mod
    ans+=cal
    ans%=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()))


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

# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *


def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1 / f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret

MOD = 10 ** 9 + 7
def solve():
    n = getN()
    bit_array = [[0, 0] for i in range(61)]
    nums = getList()
    for num in nums:
        digit = 0
        while(digit < 61):
            if num % 2 == 0:
                bit_array[digit][0] += 1
            else:
                bit_array[digit][1] += 1
            digit += 1
            num //= 2


    # print(bit_array)
    ans = 0
    for i, tgt in enumerate(bit_array):
        ans += pow(2, i, MOD) * tgt[0] * tgt[1]
        ans %= MOD

    print(ans   )

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

ans = 0
for keta in range(61):
    now = 0
    for x in a:
        if x & (1 << keta):
            now += 1
    ans += (now*(n-now))*2**keta
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

b = [((a>>i)&1).sum() for i in range(61)]
c = [n-b[i] for i in range(61)]
d = [c[i]*b[i]%mod for i in range(61)]

point = 0
now = 1

for i in range(61):
    point += now*d[i]
    point %= mod
    now *= 2
    now %= mod

print(point)

Submission status: Accepted

Solution code:
import numpy as np

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

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

print(point%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
p = 10**9+7
N = int(input())
A = list(input().split())
B = [0 for _ in range(N)]
for i in range(N):
    a = A[i]
    b = bin(int(a))[2:]
    b = "0"*(60-len(b))+b
    B[i] = b
C = {i:0 for i in range(60)}
for j in range(60):
    cnt = 0
    for i in range(N):
        if B[i][j]=="1":
            cnt += 1
    C[j] = cnt
tot = 0
for j in range(60):
    n = C[j]
    k = (N*(N-1))//2-(n*(n-1))//2-((N-n)*(N-n-1))//2
    tot = (tot+k*(2**(60-1-j)))%p
print(tot)

Submission status: Accepted

Solution code:
import numpy as np

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

ans = 0
mod = int(1e9+7)

for i in range(61):
    tmp = np.sum((A>>i)&1)
    p = (N-tmp)*tmp
    for j in range(i):
        p = (p*2)%mod
    ans += p
print(ans%mod)

Submission status: Accepted

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

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

for i in range(63):
    one, zero = 0, 0
    
    for Aj in A:
        if (Aj>>i)&1:
            one += 1
        else:
            zero += 1
    
    ans += 2**i*one*zero
    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 k in range(60):
  t=1<<k
  z=o=0
  for i in a:
    if i&t:o+=1
    else:z+=1
  ans=(ans+(z*o*t))%mod
print(ans)