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) .

Solution (Python):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
As=LI()

DIG_CUM = [[0]*60 for _ in range(N+1)]

for i in range(N):
    for s in range(60):
        DIG_CUM[i+1][s] = DIG_CUM[i][s] + ((As[i] >> s) & 1)




res = 0
for i in range(N-1):
    for s in range(60):
        coef = DIG_CUM[N][s] - DIG_CUM[i+1][s]
        if (As[i] >> s) & 1: coef = N - i - 1 - coef
        
        res += coef * (1 << s)
    res %= DVSR
print(res)

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    dp = [0] * 61
    for i in range(60, -1, -1):
        for v in a:
            dp[i] += v >> i & 1
    t = 0
    for i in range(61):
        t += dp[i] * (n - dp[i]) * pow(2, i)
        t %= mod
    print(t)


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
cnt = [0]*(66)
for num in a:
    for j in range(60):
        cnt[j] += (num >> j)%2
ans = 0
for b in range(60):
    ans += (cnt[b]*(n-cnt[b])) << b
    ans %= 10**9+7
print(ans)

Solution (Python):
MOD = 10**9 + 7


def main():
    N = int(input())
    AN = map(int, input().split())

    digits_ct = [(0, 0) for _ in range(65)]

    for A in AN:
        temp = A

        length = 0
        for _ in range(65):
            digit = temp & 0b1

            zero, one = digits_ct[length]
            if digit == 0:
                digits_ct[length] = (zero + 1, one)
            else:
                digits_ct[length] = (zero, one + 1)

            temp = temp >> 1
            length += 1

    ans = 0
    radix = 1
    for digit_ct in digits_ct:
        zero, one = digit_ct
        ans += (((zero * one) % MOD) * radix) % MOD
        ans = ans % MOD

        radix *= 2

    print(ans)


main()

Solution (Python):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

ans = 0
mod = 10 ** 9 + 7

for i in range(60):
    x, y = 0, 0
    B = A >> i & 1
    x = np.count_nonzero(B)

    y = N - x
    ans += (x * y) * (2 ** i)
print(ans%mod)

Solution (Python):
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res




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

for i in range(n):
    b.append(bitlist(a[i],61))

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

for i in range(61):
    for j in range(n):
        c[i] += b[j][i]
ans = 0
for i in range(61):
    ans += c[i]*(n-c[i])*2**i % 1000000007
print(ans % 1000000007)

Solution (Python):

import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res




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

for i in range(n):
    b.append(bitlist(a[i],61))

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

for i in range(61):
    for j in range(n):
        c[i] += b[j][i]
ans = 0
for i in range(61):
    ans += c[i]*(n-c[i])*2**i % 1000000007
print(ans % 1000000007)

Solution (Python):
import numpy as np

import sys
input = sys.stdin.readline

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

    A = np.array(A,np.int64)

    mod = 10**9 + 7

    res = 0

    for i in range(60):
        count = np.count_nonzero(A & 1)
        res += (N - count) * count * 2 ** i
        res %= mod
        A >>= 1

    print(res)

main()

Solution (Python):
import numpy as np
import sys
input = sys.stdin.readline

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

A = np.array(A,np.int64)

mod = 10**9 + 7

res = 0

for i in range(60):
    count = np.count_nonzero(A & 1)
    res += (N - count) * count * 2 ** i
    res %= mod
    A >>= 1

print(res)

Solution (Python):
N = int(input())
A_list = list(map(int, input().split()))
bite = []
for _ in range(60):
    bite.append(0)
    
for A in A_list:
    for i in range(60):
        if A & 1 << i:
            bite[i] += 1

ans = 0
on_right = N - 1
for num in range(len(A_list)):
    A = A_list[num]
    for i in range(60):
        if A & 1 << i:
            bite[i] -= 1
            ans += (on_right - bite[i]) * 1 << i
        else:
            ans += bite[i] * 1 << i
    on_right -= 1

ans %= (10 ** 9 + 7)
print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

D = defaultdict(int)
for a in A:
    for i in range(61):
        D[1 << i] += bool(a & (1 << i))

ans = 0
for key, value in D.items():
    ans += key * value * (N - value)
    ans %= MOD

print(ans % MOD)

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

D = defaultdict(int)
for a in A:
    for i in range(61):
        D[1 << i] += bool(a & (1 << i))

ans = 0
for key, value in D.items():
    ans += ((key * value) % MOD) * (N - value) % MOD
    ans %= MOD

print(ans % MOD)

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    one = 0
    for a in A:
        if (a >> i & 1) == 1:
            one += 1
    ans += one * (N - one) * 2 ** i
    ans %= mod
print(ans)

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

ans = 0
for i in range(60):
    x = 0
    for a in A:
        if a >> i & 1:
            x += 1
    ans += x * (N-x) * (2**i)
    ans %= MOD

print(ans)

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

mod = int(1e9 + 7)
ans = 0
for i in range(61):
    t = 0
    for a in A:
        if a >> i & 1:
            t += 1
    ans = (ans + pow(2, i, mod) * t * (n-t)) % mod
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    digit_count_one = [0] * 61
    nums = N * (N-1) // 2
    cnt = 0
    for a in A:
        for i in range(61):
            c = (a >> i) & 1
            if c == 1:
                digit_count_one[i] += 1
    for ix, count in enumerate(digit_count_one):
        freq = count * (N - count)
        cnt += ((1 << ix) * freq) % mod
        cnt %= mod
    print(cnt % mod)
main()

Solution (Python):
import itertools


N = int(input())
nums = [int(i) for i in input().split(" ")]
longest = len(bin(max(nums))) - 2
nums_bin = [format(i, "b").zfill(longest) for i in nums]


result = 0
for index, numbers in enumerate(zip(*nums_bin)):
    i = longest - index - 1
    zero = numbers.count("0")
    one = N - zero
    result += (2 ** i) * (zero * one)
print(result % (10 ** 9 + 7))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
res = 0
for i in range(62):
  cnt = 0
  for x in a:
    if (x & (1<<i)) > 0:
      cnt += 1
  res = (res + (cnt * (n-cnt) * (1 << i))) % mod
print(res)

Solution (Python):
N = int(input())
A=list(map(int,input().split()))
L=[0]*65
MOD=(10**9+7)
for i in range(N):
    t=str(format(A[i],"b"))
    for j in range(len(t)):
        L[j]+=int(t[-j-1])

for i in range(len(L)):
    L[i]=L[i]*(N-L[i])
    L[i]*=2**i
    L[i]%=MOD
print(sum(L)%MOD)

Solution (Python):
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

N = readi()
A = ints()

w = 1000000007

s = 0
for k in range(60):
  n = [0, 0]
  for i in range(N):
    n[A[i]%2] += 1
    A[i] >>= 1

  s += (n[0]*n[1] << k) % w

print(s%w)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007

def wash_b(line, s):
    l = len(line)
    neck = 2**s
    cnt = 0
    for i in range(l):
        if line[i] >= neck:
            line[i] -= neck
            cnt += 1
    return cnt
ans = 0
for i in range(60):
    w = wash_b(a, 59 - i)
    ans += (w*(n-w)*(2**(59-i))) % mod

ans %= mod
print(ans)

Solution (Python):
div = 10**9 + 7
ans = 0

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


A_max = max(A)

A_max_bin = format(A_max, 'b')

max_digits = len(A_max_bin)



input_format = '0' + str(max_digits) + 'b'

A_bin = [ format(item,input_format) for item in A]



ans = 0

for i in range(1,max_digits+1):
    num0 = 0
    num1 = 0
    
    for A_i in A_bin:

        
        

        

        if A_i[-i] == '0':
            num0 += 1
        else:
            num1 += 1

    ans += num0 * num1 * 2**(i-1)
    

    num0 = 0
    num1 = 0


print(ans%div)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7
ans = 0
for k in range(60):
    A_0 = 0
    A_1 = 0
    for i in range(N):
        if A[i]>>k&1:
            A_1 += 1
        else:
            A_0 += 1
    num = A_1 * A_0
    ans += (num * 2 ** k)
ans %=  mod
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007

ans = 0
for i in range(60):
    cont = 0
    for j in range(n):
        if (a[j] >> i & 1):
            cont += 1
    now = cont * (n-cont) % mod
    for j in range(i):
        now  = now * 2 % mod
    ans += now
    ans %= mod
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = [int(i) for i in input().split()]
count0 = [0 for i in range(60)]
count1 = [0 for i in range(60)]
for a in A:
    a_tmp = bin(a).replace("0b","")
    a_tmp = a_tmp.zfill(60)
    for i,b in enumerate(a_tmp):
        if b == "1":
            count1[i] += 1
        else:
            count0[i] += 1
cnt = 0
ans = 0
for c0,c1 in zip(count0[::-1],count1[::-1]):
    ans += c0*c1*(2**cnt)
    cnt += 1
print(ans%(10**9+7))

Solution (Python):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
mod = 10 ** 9 + 7

for i in range(60):
    x, y = 0, 0    
    B = A >> i & 1
    x = np.count_nonzero(B)



    y = N - x
    ans += (x * y) * (2 ** i)
    
print(ans%mod)

Solution (Python):
import numpy as np

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

ans = 0
for i in range(60):
    b = np.count_nonzero(num_list >> i & 1)
    if i==0:
        pow_two = 1
    else:
        pow_two = pow_two * 2 % mod
    ans += pow_two * b * (n-b) % mod
    ans %= mod
    
print(ans)

Solution (Python):

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

bindata = []

for value in data:
  tmp = format(value,'b').zfill(60)  
  bindata.append(tmp)


numlist = []
for i in range(60):
  numlist.append([row[i] for row in bindata])


binnum = [0] * 60
for i in range(60):
  binnum[59-i] = numlist[i].count('1')


"""
for rowdata in bindata:
  for j in range(60):
    if rowdata[j] == '1':
      numlist[59-j] += 1
"""
ans = 0


for i in range(60):
  ans += binnum[i] * (n-binnum[i]) * (2 ** i)
ans = ans % (10**9 + 7)
print(ans)






"""
ans = 0

for i in range(n-1):
  for j in range(i,n):
    ans = ans +  int(bin(data[i] ^ data[j]),0)
ans = ans % (10 ** 9 + 7)

print(int(ans))
"""

Solution (Python):
n = int(input())
nums = list(map(int, input().split()))

res =0 
for i in range(60, -1, -1):
  zeros = 0
  ones = 0
  for x in nums:
    if x >> i & 1:
      ones += 1
    else:
      zeros += 1
  res += zeros*ones << i
print(res%(10**9+7))

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
ans=0
mod=10**9+7
for k in range(60):
    X=0
    Y=0
    for i in range(N):
        if A[i]^(2**k)>A[i]:
            X+=1
        else:
            Y+=1
    
    ans+=(pow(2,k,mod)*((X*Y)%mod))%mod
    ans%=mod
print(ans)

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
ans=0
mod=10**9+7
for k in range(60):
    X=0
    Y=0
    for i in range(N):
        if A[i]^(2**k)>A[i]:
            X+=1
        else:
            Y+=1
    
    ans+=pow(2,k,mod)*(X*Y)
    ans%=mod
print(ans)

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

Solution (Python):
N = int(input())
A = map(int, input().split())
ones = [0] * 60

for a in A:
    i = 0
    while (1 << i) <= a:
        ones[i] += ((a >> i) & 1)
        i += 1

ans = 0
mod = 10 ** 9 + 7

for idx, one in enumerate(ones):
    ans = (ans + one * (N - one) * (1 << idx)) % mod

print(ans)

Solution (Python):
N = int(input())
A = map(int, input().split())
D = [[0, 0] for _ in range(60)]

for a in A:
    for i in range(60):
        if (a >> i) & 1:
            D[i][1] += 1
        else:
            D[i][0] += 1

ans = 0
mod = 10 ** 9 + 7

for idx, d in enumerate(D):
    ans = (ans + (d[0] * d[1] * (1 << idx))) % mod

print(ans)

Solution (Python):
def main():
    """"ここに今までのコード"""

n = int(input())
A = [int(a) for a in input().split()]
mod=10**9+7

ans=0
for i in range(60):
    l=sum([a>>i & 1 for a in A])
    ans+= l*(n-l) <<i
    ans%= mod
    
print(ans) 

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    """"ここに今までのコード"""
 
n = int(input())
A = [int(a) for a in input().split()]
mod=10**9+7
 
ans=0
for i in range(60):
    l=sum([a%2 for a in A])
    ans=(ans+l*(n-l)*(2**i))%mod
    A=[a//2 for a in A]
    
 



print(int(ans)) 
 
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import numpy as np
    n = int(input())
    a = np.array(list(map(int, input().split())), dtype=np.int64)
    l1 = [0]*61
    mod = 10**9+7
    
    
    for cnt in range(61):
        b = a % 2
        l1[cnt] = np.nonzero(b)[0].size
        a = a // 2
    l0 = [n-i for i in l1]
    ans = 0
    for i in range(len(l1)):
        ans = (ans+l0[i]*l1[i]*pow(2, i, mod)) % mod
    print(ans)


main()

Solution (Python):



k=10**9+7

anslist=[]

n=int(input())
a=[format(int(i), '060b') for i in input().split()]
d=[]

for i in range(60):
    b=[j[59-i] for j in a]
    c=b.count("0")*b.count("1")
    d.append(c*2**(i)%k)
ans=0

for i in d:
    ans+=i
print(ans%k)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    l1 = [0]*61
    mod = 10**9+7
    for cnt in range(61):
        l1[cnt] = sum([i % 2 for i in a])
        a = [i//2 for i in a]
    l0 = [n-i for i in l1]
    ans = 0
    for i in range(len(l1)):
        ans = (ans+l0[i]*l1[i]*pow(2, i, mod)) % mod
    print(ans)


main()

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    l1 = [0]*61
    for i in a:
        cnt = 0
        k = 1
        while k <= i:
            if i & k == k:
                l1[cnt] += 1
            cnt += 1
            k *= 2
    l0 = [n-i for i in l1]
    ans = 0
    mod = 10**9+7
    for i in range(len(l1)):
        ans = (ans+l0[i]*l1[i]*pow(2, i, mod)) % mod
    print(ans)
main()

Solution (Python):

import sys
INF = float("inf")

MOD = 1000000007  


def solve(N: int, A: "List[int]"):
    ans = 0
    base = 1
    for i in range(60):
        counter = [0, 0]
        buf = 0
        for j in range(N):
            if A[j] & (1 << i):
                buf += counter[0]
                counter[1] += 1
            else:
                buf += counter[1]
                counter[0] += 1
        ans += buf * base
        ans %= MOD
        base = (base * 2) % MOD
    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)


if __name__ == '__main__':
    main()

Solution (Python):



import numpy as np

n = int(input())
a = np.array([int(i) for i in input().split()])

k = [0] * 60

for j in range(60):
    l = a & 1
    k[j] = np.count_nonzero(l)
    a >>= 1

ans = 0
c = 0
for d in k:
    ans += (d * (n - d) * 2**c)  % (10**9 + 7)
    c += 1
    
print(ans % (10**9 + 7))

Solution (Python):
import numpy as np
mod = 10 ** 9 + 7

n = int(input())
a = np.asarray(list(map(int, input().split())))
ans = 0
bit = 1
for i in range(60):
  n_one = np.count_nonzero(a & 1)
  ans += n_one * (n - n_one) * bit
  a >>= 1
  bit *= 2
  ans %= mod
  bit %= mod
print(ans)

Solution (Python):
import cmath
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7


def main():
    N=int(input())
    a=list(map(int, input().split()))

    ans=0
    for b in range(60):
        c0=0
        c1=0
        for ai in a:
            if ai & (1<<b):
                c1+=1
            else:
                c0+=1

        ans+=(1<<b)*c0*c1
        ans%=MOD

    print(ans)


if __name__=='__main__':
    main()

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

ans = 0
for j in range(60):
    odd = 0
    even = 0
    for i in range(n):
        if a[i] % 2 == 0:
            even += 1
        else:
            odd += 1
    ans += even * odd * 2**j
    a = [i//2 for i in a]
    ans %= 10**9+7

print(ans)

Solution (Python):


import math
n=int(input())
al=list(map(int,input().split()))
a=['{:060b}'.format(x) for x in al]
a=''.join(a)
 
m=math.ceil(math.log(max(1,max(al)),2))
 
ans=0
for i in range(m):
  sum1=a[59-i::60].count('1')
  sum0=n-sum1
  ans+=2**i*sum1*sum0
 
print(ans%(10**9+7))

Solution (Python):
def pos(x, n, m):
    if n == 0:
        return 1
    res = pos(x*x%m, n//2, m)
    if n%2 == 1:
        res = res*x%m
    return res

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

MOD=10**9+7

ans=0
for i in range(60):
    count1=0
    count0=0
    for j in range(N):
        if A[j]>>i & 1:
            count1+=1
        else:
            count0+=1
    ans+=count0*count1%MOD*pos(2,i,MOD)
    ans%=MOD
print(ans)

Solution (Python):
import numpy as np

N = int(raw_input())
A = np.array(map(int, raw_input().split()))
B = map(lambda x: format(x, '060n'), A)

MOD = 10**9 + 7

count = dict()
for i in range(60):
    
    zeros = np.count_nonzero((A>>i)&1)
    ones = N - zeros
    count[i] = zeros*ones

ans = 0
for i in count:
    ans = (ans + count[i] * pow(2,i,MOD)) % MOD

print ans

Solution (Python):
import numpy as np

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

MOD = 10**9 + 7

count = dict()
for i in range(60):
    
    zeros = np.count_nonzero((A>>i)&1)
    ones = N - zeros
    count[i] = zeros*ones

ans = 0
for i in count:
    ans = (ans + count[i] * pow(2,i,MOD)) % MOD

print ans

Solution (Python):
import numpy as np

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

MOD = 10**9 + 7

count = dict()
for i in range(60):
    
    zeros = np.count_nonzero((A>>i)&1)
    ones = N - zeros
    count[i] = zeros*ones

ans = 0
for i in count:
    ans = (ans + count[i]*pow(2,i)) % MOD

print ans

Solution (Python):
import numpy as np

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

MOD = 10**9 + 7

count = dict()
for i in range(60):
    
    zeros = np.count_nonzero((A>>i)&1)
    ones = N - zeros
    count[i] = zeros*ones

mod_val = dict()
curr = 1
for i in range(60):
    mod_val[i] = curr % MOD
    curr = (2*curr) % MOD

ans = 0
for i in count:
    ans = (ans + count[i]*mod_val[i]) % MOD

print ans

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    r = [0] * 60
    t = [0] * 60
    u = [0] * 60
    ii = [2**i for i in range(60)]
    for k in a[::-1]:
        for i in range(60):
            if k & ii[i] > 0:
                r[i] += u[i]
                t[i] += 1
            else:
                r[i] += t[i]
                u[i] += 1

    rr = 0
    for i in range(60):
        rr += r[i] * ii[i]
        rr %= mod

    return rr


print(main())

Solution (Python):


modulus = 10 ** 9 + 7
maxbits = 60

N = int(input())

def add_bits(n, vec):
    """配列vecに整数nの2進各桁を加える"""
    for i in range(len(vec)):
        if n & 1: vec[i] += 1
        n >>= 1


vec = [0] * maxbits
for a in map(int, input().split()):
    add_bits(a, vec)


acc = sum(((n * (N - n)) << i) % modulus for i, n in enumerate(vec))

print(acc % modulus)

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

ans = 0

for bit in range(61):
    now = 0
    for x in a:
        if x&(1<<bit):now += 1

    ans += (2**bit)*(now*(n - now))
    ans %= mod


print(ans)

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7
bit_one_count = [0 for i in range(60)]
bit_zero_count = [0 for i in range(60)]
for i in range(n):
    bits = '{0:060b}'.format(a[i])
    for j in range(60):
        if bits[-1 -j] == '1':
            bit_one_count[j] += 1
        else:
            bit_zero_count[j] += 1

ans = 0
for j in range(60):
    ans += bit_one_count[j] * bit_zero_count[j] * 2 ** j
    ans %= MOD

print(ans)

Solution (Python):
N=int(input())
A=[int(c) for c in input().split()]
D=[0 for i in range(60)];
for a in A:
  for i in range(60):
    D[i]+=a%2
    a//=2
t=1
ans=0
for i in range(60):
  ans+=D[i]*(N-D[i])*t
  t*=2
print(ans%1000000007)

Solution (Python):
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):
    tmp = A & 1
    A >>= 1
    x = np.count_nonzero(tmp)
    x *= n - x
    ans = (ans + pow(2, i, mod) * x) % mod
print(ans)

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

Solution (Python):
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):
    tmp = (A >> i) & 1
    x = np.count_nonzero(tmp)
    x *= n - x
    ans = (ans + pow(2, i, mod) * x) % mod
print(ans)

Solution (Python):
from fractions import gcd

from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7



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

    ans = 0
    for i in range(60):
        one,zero = 0,0
        for j in range(n):
            if ((1 << i) & a[j]) == (1 << i):
                one +=1
            else:
                zero += 1
        ans += (1 << i) * one * zero
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

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



ans =0
mod =pow(10,9)+7


Max = 61

 
for i in range(Max):
    count = 0
    for j in range(N):
        if(A[j]>>i & 1)==1:
            count+=1
    ans+=count*(N-count)*pow(2,i)
    ans = ans%mod
print(ans)

Solution (Python):
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(64):
    tmp = (A >> i) & 1
    x = np.count_nonzero(tmp)
    x *= n - x
    ans += pow(2, i, mod) * x % mod

print(ans % mod)

Solution (Python):
N = int(input())
A = [int(n) for n in input().split(' ')]
 
ans = 0
for i in range(60):
    x = 0
    for A_i in A:
        if A_i>>i&1:
            x += 1
    ans += x*(N-x)*2**i
ans = ans % (10**9+7)
print(ans)

Solution (Python):
import numpy as np
MOD = 10 ** 9 + 7

n = int(input())
a = np.array(list(map(int, input().split())))
l = len(bin(max(a))) - 2

ans = 0
for i in range(l):
    b = (a >> i) & 1
    x = np.count_nonzero(b)
    now = x * (n - x) * pow(2, i, MOD) % MOD
    ans += now

print(ans % MOD)

Solution (Python):
import numpy as np

N = int(input())
a = np.array([int(x) for x in input().split(" ")], np.int64)
sum = 0
pow = 0
while any(a):
    one = np.count_nonzero(a & 1)
    sum += one * (N - one) * 2 ** pow
    sum %= (10 ** 9 + 7)
    pow += 1
    a >>= 1
print(sum)

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

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))

mod = 10 ** 9 + 7

res = 0
for d in range(60):
    one = sum(x & 1 for x in arr)
    res = (res + one * (n - one) * (1 << d)) % mod
    arr = [x >> 1 for x in arr]

print(res)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))

mod = 10 ** 9 + 7

res = 0
for d in range(60):
    one = sum(x & 1 for x in arr)
    res += one * (n - one) * (1 << d)
    res %= mod
    arr = [x >> 1 for x in arr]

print(res)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))

mod = 10 ** 9 + 7

res = 0
for d in range(60):
    one = sum(x % 2 == 1 for x in arr)
    res += one * (n - one) * 2 ** d
    res %= mod
    arr = [x // 2 for x in arr]

print(res)

Solution (Python):
n = int(input())
arr = list(map(lambda n: format(int(n), '060b')[::-1], input().split()))

mod = 10 ** 9 + 7

res = 0
power_of_two = 1
for d in range(60):
    one = sum(x[d] == "1" for x in arr)
    res += one * (n - one) * power_of_two
    res %= mod
    power_of_two *= 2
    power_of_two %= mod

print(res)

Solution (Python):

import sys
from collections import defaultdict

N=input()
A=map(int, sys.stdin.readline().split())

mod=10**9+7
ans=0
for keta in range(60):
    C=defaultdict(lambda: 0)     
    temp_ans=0  
    for i,a in enumerate(A):
        a=a>>keta&1
        if i==0:
            C[a]+=1
        else:
            if a==1:
                temp_ans+=C[0]  
            elif a==0:
                temp_ans+=C[1]  
            C[a]+=1
    ans+=pow(2,keta,mod)*temp_ans
    ans%=mod
print ans

Solution (Python):
import sys
import numpy as np
read = sys.stdin.read

N, *A = map(int, read().split())
a = np.array(A, np.int64)
mod = 10 ** 9 + 7
answer = 0
for i in range(60):
    bit = np.count_nonzero(a & 1)
    answer += 2 ** i * bit * (N - bit)
    answer %= mod
    a >>= 1

print(answer)

Solution (Python):
import numpy as np

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

wa = 0
kazu = 10**9 + 7
for i in range(60):
    b = int((a & 1).sum())
    wa = (wa + b*(n-b)*(1<<i)) % kazu
    a = a >> 1

print(wa)

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

wa = 0
kazu = 10**9 + 7
for i in range(60):
    b = 0
    for j in a:
        b += j & 1
    wa = (wa + b*(n-b)*(1<<i)) % kazu
    for j in range(n):
        a[j] = a[j] >> 1

print(wa)

Solution (Python):
import numpy as np
import math
n = int(input())
A = np.fromstring(input(),dtype=np.int64,sep=" ")

sum = 0
d = 10**9+7
for bit in range(64):
    c = int((A & 1).sum())
    sum += c *(n-c)*(1<<bit)%d
    A = A>>1

print(sum %(d))

Solution (Python):
import numpy as np
 
 
def solve(string):
    n, *a = map(int, string.split())
    
    a = np.asarray(a, dtype=np.int64)
    m = 10**9 + 7
    ans = 0
    for i in range(60):
        s = int((a & 1).sum())
        a >>= 1
        
        ans += s * (n - s) * pow(2, i, m) % m
        ans %= m
    return str(ans)
 
 
if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
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(64):
    tmp = (A >> i) & 1
    
    x = np.count_nonzero(tmp)
    x *= n - x
    ans += pow(2, i, mod) * x % mod

print(ans % mod)

Solution (Python):
import numpy as np 
N = int(input())
A = np.fromstring(input(), dtype = np.int64, sep = ' ')

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

print(res % 1000000007)

Solution (Python):
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(64):
    tmp = (A >> i) & 1
    x = np.count_nonzero(tmp)
    x *= n - x
    ans += pow(2, i, mod) * x % mod

print(ans % mod)

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

bit = [0] * 60
for a in A:
    i = 0
    while a > 0:
        bit[i] += a & 1
        i += 1
        a >>= 1

ans = 0
for i, x in enumerate(bit):
    x = x*(n-x)
    for _ in range(i):
        x *= 2
        x %= mod
    ans += x
    ans %= mod
print(ans)