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: Time Limit Exceeded

Solution code:
def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

# numpy and scipy are available for use
import numpy
import scipy
#https://atcoder.jp/contests/abc147/tasks/abc147_d
#Xor Sum 4
"""
iterate over bits
1. calculate how many bits we have on that position
2. for each 1, we need to add num 0s * num 1s * 2s
3. sum them up

"""

# reads a single line
N = gi()
a = [0] * N

for i in range(N):
    a[i] = gi()

ans = 0
for shift in range(60):
    base = 1 << shift
    n1 = 0
    for ai in a:
        if (ai & base):
            n1 += 1

    part = n1 * (N - n1)
    part %= MOD
    part *= base
    part %= MOD
    ans += part
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

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


total = 0

for i in range(0, N):
    for j in range(i + 1, N):
        total += (A_i[i] ^ A_i[j]) % 1000000007


total %= 1000000007

print(total)

Submission status: Time Limit Exceeded

Solution code:
#入力値処理
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)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
bins = [format(i, "b").zfill(60) for i in A]

keta = []
for i in range(60):
    tmp = list(map(int, [r[i] for r in bins]))
    keta.append(tmp[:])
keta.reverse()

ans = 0
for i in range(60):
    s = sum(keta[i])
    ans += s * (N - s) * 2 ** i
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
import itertools


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 i in range(1, longest+1):
    one = 0
    zero = 0
    for num_bin in nums_bin:
        if num_bin[-1*i] == "1":
            one += 1
        elif num_bin[-1*i] == "0":
            zero += 1
        else:
            raise Exception()
    result += (2 ** (i-1)) * (one * zero)
print(result % (10 ** 9 + 7))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
numlist = input().split(' ') 
sum = 0

for i in range(N-1):
  for j in range(N-i-1):
    sum += int(numlist[i])^int(numlist[j+i+1])
    
print(int(sum % (10**9 + 7)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
numlist = input().split(' ') 
sum = 0

for i in range(N-1):
  for j in range(N-1):
    if i-j<=0:
      sum += int(numlist[i])^int(numlist[j+1])
    
print(int(sum % (10**9 + 7)))

Submission status: Time Limit Exceeded

Solution code:
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
print(sum(L)%MOD)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A=list(map(int,input().split()))
L=[0]*65

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]%=(10**9+7)
    L[i]*=2**i
    L[i]%=(10**9+7)
print(sum(L)%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
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] //= 2

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

print(s%w)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
def make_bin(i):
    return list(map(int, list(format(i, "060b"))))


a_bin = []
for i in range(n):
    a_bin.append(make_bin(a[i]))

ans = 0
for i in range(60):
    index_i = []
    for j in range(n):
        index_i.append(a_bin[j][i])
    ones = index_i.count(1)
    ans += (ones*(n-ones)*(2**(59-i))) % mod

ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
def make_bin(i):
    return list(map(int, list(format(i, "060b"))))
def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, y // 2) ** 2 % mod
    else:
        return power(x, y // 2) ** 2 * x % mod

a_bin = []
for i in range(n):
    a_bin.append(make_bin(a[i]))

ans = 0
for i in range(60):
    index_i = []
    for j in range(n):
        index_i.append(a_bin[j][i])
    ones = index_i.count(1)
    ans += (ones*(n-ones)*(power(2, 59-i))) % mod

ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

for k in range(60):
  x, y = 0, 0
  for i in range(N):
    if A[i] >> k & 1:
      x += 1
  y = N - x
  ans += (x * y) * (2 ** k)
    
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
p = 10**9 + 7
n = int(input())
a = list(map(int,input().split()))
c = [0]*60
for x in a:
  y = x
  for i in range(60):
    c[i] += y%2
    y //= 2
q = 0
for i in range(60):
  q = (q + c[i]*(n-c[i])*2**i)%p
print(q)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    ans += A[i] ^ A[j]
    
print(ans % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
print(sum((l[i]^l[j])%1000000007 for i in range(n-1) for j in range(i,n))%1000000007)

Submission status: Time Limit Exceeded

Solution code:
p = 10**9 + 7
n = int(input())
a = list(map(int,input().split()))
s = 0
for k in range(64):
  r = sum([(x//(2**k))%2 for x in a])
  s = (s + 2**k*r*(n-r))%p
print(s)

Submission status: Time Limit Exceeded

Solution code:
p = 10**9 + 7
n = int(input())
a = list(map(int,input().split()))
def f(a):
  if sum(a) == 0:
    return(0)
  else:
    r = sum([x%2 for x in a])
    b = [x//2 for x in a]
  return((r*(n-r) + 2*f(b))%p)
print(f(a))

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

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

N = readi()
A = ints()

s = 0
w = 1000000007
for i in range(N-1):
  for j in range(i+1, N):
    s += (A[i] ^ A[j])
    s %= w
print(s%w)

Submission status: Time Limit Exceeded

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

N = readi()
A = ints()

s = 0
for i in range(N-1):
  for j in range(i+1, N):
    s += (A[i] ^ A[j])%(10**9+7)
print(s%(10**9+7))

Submission status: Time Limit Exceeded

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

N = readi()
A = ints()

s = 0
for i in range(N-1):
  for j in range(i+1, N):
    s += A[i] ^ A[j]
print(s%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
# #bin()やformat(数字 ,"b")を使うとstr型になる
# #bin()とformat(数字 ,"#b")は同意

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

for i in range(N): A[i] = format(A[i], "#b") #ここで全て60ビットの二進数に変換

sum = 0
c0 = [0]*60
c1 = [0]*60
for i in range(N):
    for j in range(60):
        if A[i][-(j+1)] == "0": #str型であることに注意！
            c0[j] += 1
        elif A[i][-(j+1)] == "1":
            c1[j] += 1
        else:
            break

for i in range(60):
    if c1[i] > 0:
        c0[i] = N - c1[i] 
    sum += (c0[i] * c1[i]) << i

print(sum%mod)


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

# for i in range(N): A[i] = format(A[i], "060b") #ここで全て60ビットの二進数に変換

# mod = 10**9+7

# sum = 0
# for i in range(1,61):
#     count0 = 0
#     count1 = 0
#     for j in range(N):
#         if A[j][-i] == "0": #str型であることに注意！
#             count0 += 1
#         else:
#             count1 += 1 
#     sum += (count0 * count1) << (i-1) #左シフトだが，2**(i-1)でもOK (処理速度変わらない)
# print(sum%mod)

Submission status: Time Limit Exceeded

Solution code:
#bin()やformat(数字 ,"b")を使うとstr型になる
#bin()とformat(数字 ,"#b")は同意

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

for i in range(N): A[i] = format(A[i], "060b") #ここで全て60ビットの二進数に変換

mod = 10**9+7

sum = 0
for i in range(1,61):
    count0 = 0
    count1 = 0
    for j in range(N):
        print
        if A[j][-i] == "0": #str型であることに注意！
            count0 += 1
        else:
            count1 += 1 
    sum += (count0 * count1) * 2**(i-1) #左シフトだが，2**(i-1)でもOK
print(sum%mod)

Submission status: Time Limit Exceeded

Solution code:
#bin()やformat(数字 ,"b")を使うとstr型になる
#bin()とformat(数字 ,"#b")は同意

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

for i in range(N): A[i] = format(A[i], "060b") #ここで全て60ビットの二進数に変換

mod = 10**9+7

sum = 0
for i in range(1,61):
    count0 = 0
    count1 = 0
    for j in range(N):
        print
        if A[j][-i] == "0": #str型であることに注意！
            count0 += 1
        else:
            count1 += 1 
    sum += (count0 * count1) << (i-1) #左シフトだが，2**(i-1)でもOK
print(sum%mod)

Submission status: Time Limit Exceeded

Solution code:
#bin()やformat(数字 ,"b")を使うとstr型になる
#bin()とformat(数字 ,"#b")は同意

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

for i in range(N): A[i] = format(A[i], "060b") #ここで全て60ビットの二進数に変換

mod = 10**9+7

sum = 0
for i in range(1,61):
    count0 = 0
    count1 = 0
    for j in range(N):
        if A[j][-i] == "0": #str型であることに注意！
            count0 += 1
        else:
            count1 += 1 
    sum += (count0 * count1) << (i-1) #左シフトだが，2**(i-1)でもOK
print(sum%mod)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

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

for i in range(n-1):
  for j in range(i+1, n):
    sum += a[i]^a[j]

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

Submission status: Time Limit Exceeded

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

for i in range(60):
    x, y = 0, 0    
    for Ai in A:
        if Ai >> i & 1:
            x += 1
    y = N - x
    ans += (x * y) * (2 ** i)
    
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]

sum = 0
for i in range(len(A)-1):
  for j in range(i+1, len(A)):
    sum += A[i] ^ A[j]
    #print(i, j, sum)

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

Submission status: Time Limit Exceeded

Solution code:
def getdata_input():
    while True:
        yield input()

def callFunc2(it):
    N=int(next(it))
    data=[0]*N
    (data[0],*data[1:])=map(int,next(it).split())
    d=data[::-1]
    val=0
    
    for _ in range(N):
        i=d.pop()
        for x in d:
            val += i^x
    
    return val%(10**9+7)

it=getdata_input()
print(callFunc2(it))

Submission status: Time Limit Exceeded

Solution code:
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))

Submission status: Time Limit Exceeded

Solution code:
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))

Submission status: Time Limit Exceeded

Solution code:
#入力値処理
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)

#各桁の1の個数を格納
numlist = [0] * 60

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

#各桁の1の個数と0の個数の積の和を求める
for i in range(60):
  ans += numlist[i] * (n-numlist[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))
"""

Submission status: Time Limit Exceeded

Solution code:
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
    #print(X,Y)
    ans+=pow(2,k,mod)*(X*Y)
    ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#入力値処理
n = int(input())
data = [int(s) for s in input().split()]

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
l = list(map(int,input().split()))
ans = 0

comb = list(itertools.combinations(l,2))

for i in range(len(comb)):
    k = int(bin(comb[i][0] ^ comb[i][1]),0)
    ans += k
    ans %= 10**9+7

print(ans)

Submission status: Time Limit Exceeded

Solution code:
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()

Submission status: Time Limit Exceeded

Solution code:
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 = ans%mod
    

#ans=xor[0]
#for j in range(60-1):
#    ans=((2*ans)+xor[j+1])%mod
print(int(ans)) 

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
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]
    

#ans=xor[0]
#for j in range(60-1):
#    ans=((2*ans)+xor[j+1])%mod
print(int(ans)) 

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
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=0
    for j in range(n):
        l+=A[j]%2
        A[j]=A[j]//2
    ans=(ans+l*(n-l)*(2**i))%mod
    

#ans=xor[0]
#for j in range(60-1):
#    ans=((2*ans)+xor[j+1])%mod
print(int(ans)) 

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

n = int(input())
A = [int(a) for a in input().split()]

xor=[0]*60
for i in range(60):
    l=0
    for j in range(n):
        l+=A[j]%2
        A[j]=A[j]//2
    xor[59-i]=l*(n-l)
    
mod=10**9+7
ans=xor[0]
for j in range(60-1):
    ans=((2*ans)+xor[j+1])%mod
print(int(ans)) 

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    """"ここに今までのコード"""
import numpy as np
n = int(input())
A=list(map(int, input().split()))

l=np.zeros(60)
for i in range(60):
    for j in range(n):
        l[60-i-1]+=A[j]%2
        A[j]=A[j]//2
         
xor=([n]*60-l)*l                
mod=10**9+7
ans=xor[0]
for j in range(60-1):
    ans=((2*ans)+xor[j+1])%mod
print(int(ans)) 

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
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
    #n = 300000
    #a = np.array([2**60-i for i in range(n)])
    for cnt in range(61):
        b = a % 2
        l1[cnt] = sum(b)
        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()

Submission status: Time Limit Exceeded

Solution code:
# D - Xor Sum 4
mod = 1000000007
N = int(input())
Alist = list(map(int, input().split()))
ans = 0
for i in range(60):
    x = 0;
    for j in range(N):
        if Alist[j]>>i&1:
            x += 1
    now = x * (N - x) % mod
    for j in range(i):
        now = now * 2 % mod  # オーバーフロー対策
    ans += now
    ans %= mod
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
AList = list(map(int, input().split()))
divider = 10**9 + 7
count = 0

for i in range(N-1) :
    for j in range(i+1,N) :
        count += AList[i]^AList[j]
print(count%divider)

Submission status: Time Limit Exceeded

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

ans = 0
div = 10 ** 9 + 7

for i in range(N - 1):
    for j in range((i + 1), N):
        ans += A[i] ^ A[j]

print(ans % div)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import numpy as np
    n = int(input())
    a = list(map(int, input().split()))
    l1 = np.zeros(61, dtype=np.int64)
    mod = 10**9+7
    for i in a:
        j = list(map(int, reversed(bin(i)[2:])))
        l1[:len(j)] += j
    l0 = n-l1
    ans = 0
    for i in range(len(l1)):
        ans = (ans+l0[i]*l1[i]*pow(2, i, mod)) % mod
    print(ans)


main()

Submission status: Time Limit Exceeded

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


main()

Submission status: Time Limit Exceeded

Solution code:
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()

Submission status: Time Limit Exceeded

Solution code:
def main():
    """"ここに今までのコード"""
import numpy as np
n = int(input())
A=list(map(int, input().split()))


bit= np.array([[0]*60 for i in range(n)])
for i in range(n):
    a=A[i]
    j=1
    if a!=0:    
        while a//2>0:
            if a%2==1:
                bit[i][60-j]=1
                j+=1
                a=a//2
            else:
                j+=1
                a=a//2
        bit[i][60-j]=1
           
l=np.sum(bit,axis=0)           
xor=([n]*60-l)*l
    
#for j in range(60):
    #for i in range(n):
        #l+=bit[i][j]
    #xor[j]=l*(n-l)
    
L=10**9+7
ans=xor[0]
for j in range(60-1):
    ans=((2*ans)+xor[j+1])%L
print(ans) 

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


bit= np.array([[0]*60 for i in range(n)])
for i in range(n):
    a=A[i]
    j=1
    if a!=0:    
        while a//2>0:
            if a%2==1:
                bit[i][60-j]=1
                j+=1
                a=a//2
            else:
                j+=1
                a=a//2
        bit[i][60-j]=1
           
l=np.sum(bit,axis=0)           
xor=([n]*60-l)*l
    
#for j in range(60):
    #for i in range(n):
        #l+=bit[i][j]
    #xor[j]=l*(n-l)
    
L=10**9+7
ans=xor[0]
for j in range(60-1):
    ans=((2*ans)+xor[j+1])%L
print(ans)

Submission status: Time Limit Exceeded

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


bit= [[0]*60 for i in range(n)]
for i in range(n):
    a=A[i]
    j=1
    if a!=0:    
        while a//2>0:
            if a%2==1:
                bit[i][60-j]=1
                j+=1
                a=a//2
            else:
                j+=1
                a=a//2
        bit[i][60-j]=1
      
xor=[0]*60
    
for j in range(60):
    l=0
    for i in range(n):
        l+=bit[i][j]
    xor[j]=l*(n-l)
    
L=10**9+7
ans=xor[0]
for j in range(60-1):
    ans=((2*ans)+xor[j+1])%L
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


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))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

k = [0] * 60

for j in range(60):
    l = [i >> j & 1 for i in a]
    for m in l:
        k[j] += m

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

k = [0] * 60

for i in a:
    for j in range(60):
        if (i >> j) & 1:
            k[j] += 1

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

k = [0] * 60

for i in a:
    for j in range(60):
        if (i >> j) & 1:
            k[j] += 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))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
MOD=10**9+7
a=list(map(int,input().split()))
x=[0 for i in range(60)]
for i in range(n):
    s=(bin(a[i])[2:])[::-1]
    for j in range(len(s)):
        if s[j]=='1': x[j]+=1

ans=0
q=1
for i in range(60):
    ans+=((((n-x[i] )*x[i])%MOD)*q)%MOD
    ans=ans%MOD
    q=(q*2)%MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
MOD=10**9+7
a=list(map(int,input().split()))
x=[0 for i in range(60)]
for i in range(n):
    s=(bin(a[i])[2:])[::-1]
    for j in range(len(s)):
        if s[j]=='1': x[j]+=1

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

Submission status: Time Limit Exceeded

Solution code:
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 = sum(a & 1)
  ans += n_one * (n - n_one) * bit
  a >>= 1
  bit *= 2
  ans %= mod
  bit %= mod
print(ans)

Submission status: Time Limit Exceeded

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

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if A[i]!=A[j]:
            ans+=A[i]^A[j]
            ans=ans%mod
        else:
            continue

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
def xor(a,b):
    #a_ = bin(a)[2:]                                                                              
    #b_ = bin(b)[2:]                                                                              
    a_ = format(a,"b")
    b_ = format(b,"b")
    s = len(a_) - len(b_)
    if s < 0:
        a_ = "0"*abs(s) + a_
    else:
        b_ = "0"*abs(s) + b_
    x = ""
    for i in range(len(a_)):
        if a_[i] == b_[i]:
            x += "0"
        else:
            x += "1"
    return x

s = 0
for i in range(n-1):
    for j in range(i,n):
        s += int(xor(l[i],l[j]),2)
print(s%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
mod = 10 ** 9 + 7
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
for i in range(N-1):
    for j in range(i+1,N,1):
        ans += (A[i] ^ A[j]) % mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
count=0
mod=10**9+7
for i in range(n-1):
  for j in range(i+1,n):
    count+=a[i]^a[j]
print(count%mod)

Submission status: Time Limit Exceeded

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

bits = [0 for _ in range(60)]
for i in range(n):
    for b in range(60):
        if a[i] & 2 ** b > 0:
            bits[b] += 1

ans = 0
for i, b in enumerate(bits):
    if b > 0:
        ans += (2 ** i) * (b * (n-b))
        ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
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*2**i%MOD
    ans%=MOD
print(ans)

Submission status: Time Limit Exceeded

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

MOD=10**9+7

ans=0
for i in range(N-1):
    for j in range(i,N):
        ans+=A[i] ^ A[j] #XOR
        ans%=MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
A = map(lambda x: format(x, '060b'), A)
MOD = 10**9 + 7

count = dict()
for i in range(60):
    zeros = len([a[i] for a in A if a[i] == '0'])
    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[59-i]) % MOD

print ans

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
A = map(lambda x: format(x, '060b'), A)
MOD = 10**9 + 7

count = dict()
for i in range(60):
    zeros = len([a[i] for a in A if a[i] == '0'])
    ones = N - zeros
    count[i] = zeros*ones

ans = 0
for i, v in count.items():
    ans = (ans + count[i]*((1<<(59-i)) % MOD)) % MOD

print ans

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
A = map(lambda x: format(x, '060b'), A)
MOD = 10**9 + 7

count = dict()
for i in range(60):
    zeros = len([a[i] for a in A if a[i] == '0'])
    ones = N - zeros
    count[i] = zeros*ones

ans = 0
for i, v in count.items():
    ans = (ans + count[i]*(1<<(59-i))) % MOD

print ans

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
A = map(lambda x: format(x, '060b'), A)
MOD = 10**9 + 7

count = dict()
for i in range(60):
    zeros = len([a[i] for a in A if a[i] == '0'])
    ones = len([a[i] for a in A if a[i] == '1'])
    count[i] = zeros*ones

ans = 0
for i, v in count.items():
    ans = (ans + count[i]*(2**(59-i))) % MOD

print ans