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:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
alis = li()
import numpy as np
alis = np.array(alis,dtype=np.int64)
b = [0] * 61
count = 0
while True:
    if np.all(alis== 0):
        break
    c = (alis % 2 == 0)
    b[count] = sum(c)
    count += 1
    alis //= 2
mod = 10 ** 9 + 7
ans = 0
for i in range(61):
    tmp = (1<<i) % mod
    k = (b[i] * (n-b[i]))  % mod
    k = k*tmp % mod
    ans += k
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline
P = 10 ** 9 + 7


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

    ans = 0
    one_cnt = [0] * B
    for b in range(B):
        for i in range(N):
            one_cnt[b] += (A[i] >> b) & 1
        ans += 2 ** b * one_cnt[b] * (N - one_cnt[b])
        ans %= P
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline
P = 10 ** 9 + 7


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

    one_cnt = [0] * B
    for b in range(B):
        for i in range(N):
            one_cnt[b] += (A[i] >> b) & 1

    ans = 0
    for b in range(B):
        ans += 2 ** b * one_cnt[b] * (N - one_cnt[b])
        ans %= P
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline
P = 10 ** 9 + 7


def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    B = 61

    one_cnt = [0] * B
    for i in range(N):
        for b in range(B):
            one_cnt[b] += (A[i] >> b) & 1

    ans = 0
    for b in range(B):
        ans += 2 ** b * one_cnt[b] * (N - one_cnt[b])
        ans %= P
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline
P = 10 ** 9 + 7


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

    one_cnt = [0] * B
    for i in range(N):
        for b in range(B):
            one_cnt[b] += (A[i] >> b) & 1

    ans = 0
    for b in range(B):
        ans += 2 ** b * one_cnt[b] * (N - one_cnt[b])
        ans %= P
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        if isinstance(x, str):
            x = int(x)
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )

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

def xor(a, b):
    return a ^ b

ret = ModInt(0)
for i in range(N - 1):
    for j in range(i + 1, N):
        ret += xor(A[i], A[j])

print(ret)

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
N = int(input())
A = list(map(int, input().split()))


x = [ A[i]^A[j] for i in range(N-1) for j in range(i+1,N) ]
kotae =sum(x) % (10**9 +7)
print(kotae)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    b = sum(map(lambda x: (x >> i)&1, a))
    c = n - b
    ans += b * c * (1<<i) % mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
i = 1
for _ in range(60):
    b = sum(map(lambda x: x & i != 0, a))
    c = n - b
    ans += b * c * i % mod
    i <<= 1
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
i = 1
for _ in range(60):
    b = 0
    c = 0
    for j in a:
        if j & i != 0:
            b += 1
        else:
            c += 1
    ans += b * c * i % mod
    i *= 2
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(a[i].bit_length()):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=(b[i]*(n-b[i])*2**i) % 1000000007
print(c%1000000007)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    c=bin(a[i])
    for j in range(len(bin(a[i]))-2):
        if c[-j-1]=='1':
            b[j]+=1
c=0
for i in range(64):
    c+=(b[i]*(n-b[i])*2**i)%(10**9+7)
    c %= (10**9+7)
print(c%(10**9+7))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(len(bin(a[i]))-2):
        c=bin(a[i])
        if c[-j-1]=='1':
            b[j]+=1
c=0
for i in range(64):
    c+=b[i]*(n-b[i])*2**i
print(c%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  k=[0]*60
  n=I()
  l=LI()

  for x in l:
    _a=bin(x)[2:]
    a=_a.zfill(60)

    for i,y in enumerate(a):
      if y=='1':
        k[59-i]+=1

  ans=0
  for i,x in enumerate(k):
    ans+=(n-x)*x*(2**i)
    ans%=mod

  return ans%mod

# main()
print(main())

Submission status: Time Limit Exceeded

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

import sys
import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from fractions import gcd                    # for Python3.4.3


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = lmi()
    m = max(a)
    # corner case: all numbers are equal to zero
    if m == 0:
        print(0)
        exit(0)

    ans = 0
    for shift in range(int(math.log2(m)+1)):
        mask = 0b1 << shift
        # print(tuple(map(lambda x: (x&mask)>>shift, a)))
        count_one = tuple(map(lambda x: (x&mask)>>shift, a)).count(1)
        ans = (ans + int(pow(2, shift, mod)) * count_one * (n - count_one)) % mod
        # print(ans)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

ind = int(input())
nums = [int(x) for x in input().split()]
MOD = 1000000007
ans = 0
for v in itertools.combinations(nums, 2):
    # XOR は四則演算よりも優先度が低い…….
    ans = (ans + (v[0] ^ v[1])) % MOD

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
    a_bi_e = format(a[i], 'b')
    a_bi.append(a_bi_e)

MOD = 10 ** 9 + 7
S = 0

for i in range(n-1):
    k = i + 1
    while k < n:
        string = ''
        dlen = len(a_bi[i]) - len(a_bi[k]) 
        if dlen == 0:
            for j in range(len(a_bi[i])):
                string_e = int(a_bi[i][j]) ^ int(a_bi[k][j])
                string += str(string_e)
        if dlen > 0:
            for j in range(dlen):
                string += a_bi[i][j]
            for j in range(len(a_bi[k])):
                string_e = int(a_bi[i][j+dlen]) ^ int(a_bi[k][j])
                string += str(string_e)
        if dlen < 0:
            dlen *= -1
            for j in range(dlen):
                string += a_bi[k][j]
            for j in range(len(a_bi[i])):
                string_e = int(a_bi[i][j]) ^ int(a_bi[k][j+dlen])
                string += str(string_e)
        k += 1
        S += (int(string, 2) % MOD)
S %= MOD
print(S)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int,input().split()))
ans = 0
f = list(itertools.combinations(a,2))
for i in range(len(f)):
    add = f[i][0]^f[i][1]
    ans = (ans + add)%1000000007
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

bits = [0] * 60
for d in a:
    for i in range(60):
        if d % 2 == 1:
            bits[i] += 1
        d >>= 1
        if d == 0:
            break

total = 0
mod = 10 ** 9 + 7
for i in range(60):
    total += (2 ** i) * (bits[i] * (n - bits[i]))
    total %= mod
print(total)

Submission status: Time Limit Exceeded

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

for i in A:
    b = i
    tmp = 0
    while(b):
        digit[tmp] += b & 1
        tmp += 1
        b >>= 1

ans = 0
for i in range(60):
    ans = (ans + (digit[i]*(N-digit[i]) % mod) * pow(2, i, mod) % mod) % mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
numbers=input().split()
nums=list(map(int,numbers))
#print(nums)
mx=0
for num in nums:
    if num>mx:
        mx=num
#print(mx)
j=0
ans=0
while 2**j<=mx:
    sm=0
    for num in nums:
        sm+= num>>j &1
    ans+=(sm)*(n-sm)*2**j
    j=j+1
#print(ans)
print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
numbers=input().split()
nm=list(map(int,numbers))
#print(nm)
sums=0
for i in range(0,n-1):
    for j in range(i+1,n):
        #print(nm[i],end=" ")
        #print(nm[j])
        sums+=nm[i]^nm[j]
#print(sums)
print(sums%1000000007)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = [0 for i in range(62)]
for i in range(n):
    b = bin(a[i])
    for i in range(len(b)-2):
        x[-i-1] += int(b[-i-1])
mod = 10**9+7
ans = 0
two = 1
for i in range(1,62):
    ans = (ans + x[-i]*(n-x[-i])*two)%mod
    two = two*2%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = [0 for i in range(65)]
for i in range(n):
    b = bin(a[i])
    for i in range(len(b)-2):
        x[-i-1] += int(b[-i-1])
mod = 10**9+7
ans = 0
for i in range(1,65):
    ans = (ans + x[-i]*(n-x[-i])*pow(2,i-1,mod))%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for digit in range(60):
    one = sum((A >> digit) & 1)
    ans += (one * (N - one) * pow(2, digit, MOD)) % 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
one = [0] * 60

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

for digit in range(60):
    ans += (one[digit] * (N - one[digit]) * pow(2, digit, MOD)) % 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
A_bin = list(map(lambda x: bin(x)[2:].zfill(60), A))
one = [0] * 60

for num in A_bin:
    for digit in range(60):
        one[digit] += int(num[-(digit + 1)])

for digit in range(60):
    ans += (one[digit] * (N - one[digit]) * pow(2, digit, MOD)) % 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
A_bin = list(map(lambda x: bin(x)[2:].zfill(60), A))
zero = [0] * 60
one = [0] * 60

for num in A_bin:
    for digit in range(60):
        if num[-(digit + 1)] == '0':
            zero[digit] += 1
        else:
            one[digit] += 1

for digit in range(60):
    ans += ((zero[digit] * one[digit])  * pow(2, digit, MOD)) % MOD
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
prime = 10 ** 9 + 7
max_digit = len(bin(max(A))[2:])
A_bin = list(map(lambda x: bin(x)[2:].zfill(max_digit), A))
zero = [0] * max_digit
one = [0] * max_digit

for num in A_bin:
    for digit in range(max_digit):
        if num[-(digit + 1)] == '0':
            zero[digit] += 1
        else:
            one[digit] += 1

for digit in range(max_digit):
    ans += (((zero[digit] * one[digit]) % prime) * pow(2, digit, prime)) % prime
    ans %= prime

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
prime = 10 ** 9 + 7
max_digit = len(bin(max(A))[2:])
A_bin = list(map(lambda x: bin(x)[2:].zfill(max_digit), A))
zero = [0] * max_digit
one = [0] * max_digit

for num in A_bin:
    for digit in range(max_digit):
        if num[-(digit + 1)] == '0':
            zero[digit] += 1
        else:
            one[digit] += 1

for digit in range(max_digit):
    ans += ((zero[digit] * one[digit]) % prime) * pow(2, digit, prime)
    ans %= prime

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def xor(x,y):
  return x^y

mod = pow(10,9)+7
n = int(input())
A = list(map(int, input().split()))
ans = 0

for i in range(n):
  for j in range(i+1, n):
    a = xor(A[i],A[j])
    ans += a%mod
print(ans%mod)

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]
        ans %= (10**9 + 7)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  n = int(input())
  a = list(map(int,input().split()))
  os = [0]*60
  for ai in a:
    bi = bin(ai)[2:]
    for j in range(len(bi)):
      if bi[-j-1] == "1":
        os[j] += 1
  mod = 10**9+7
  s = 0
  k = 1
  for i in range(60):
    x = (n-os[i])*os[i]
    s = (s+x*k)%mod
    k = (2*k)%mod
  print(s)
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
os = [0]*60
for ai in a:
  bi = bin(ai)[2:]
  for j in range(len(bi)):
    if bi[-j-1] == "1":
      os[j] += 1
mod = 10**9+7
s = 0
k = 1
for i in range(60):
  x = (n-os[i])*os[i]
  s = (s+x*k)%mod
  k = (2*k)%mod
print(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
os = [0 for _ in range(60)]
for i in range(n):
  bi = bin(a[i])[2:]
  for j in range(len(bi)):
    if bi[-j-1] == "1":
      os[j] += 1
mod = 10**9+7
s = 0
k = 1
for i in range(60):
  x = (n-os[i])*os[i]
  s = (s+x*k)%mod
  k = (2*k)%mod
print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
ans=0
cnt0=[0]*60
cnt1=[0]*60
mod=10**9+7
tp=[0]*60
for i in range(60):
  tp[i]=(1<<i)%mod
for i in a:
  for j in range(60):
    if (i>>j)&1:
      ans+=(cnt0[j]*tp[j])
    else:
      ans+=(cnt1[j]*tp[j])
  for j in range(60):
    if (i>>j)&1:
      cnt1[j]+=1
    else:
      cnt0[j]+=1
print(ans%mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N = ir()
A = lr()
bit = [0 for _ in range(60)]
for a in A:
    for i in range(a.bit_length()):
        if (a >> i) & 1:
            bit[i] += 1

answer = 0
for i, x in enumerate(bit):
    answer += x * (N-x) * 2 ** i % MOD

print(answer%MOD)
# 22

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def myinput():
    return map(int,readline().split())

n = int(readline())
a = list(myinput())
mod = 10**9 + 7
ans = 0

for j in range(60):
    k = 2**j
    one = 0
    zero = 0
    for i in range(n):
        if (a[i]&k):
            one += 1
        else:
            zero += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**j) 
    ans %= mod   

print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def myinput():
    return map(int,readline().split())

n = int(readline())
a = list(myinput())
mod = 10**9 + 7
ans = 0

if max(a)==0:
  print(0)
  exit()

m = math.floor(math.log(max(a),2))+1

for j in range(m):
    one = 0
    zero = 0
    for i in range(n):
        b = str(bin(a[i]))[2:]
        c = b.zfill(m)
        s = int(c[m-j-1])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**j) 
    ans %= mod

print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def myinput():
    return map(int,readline().split())

n = int(readline())
a = list(myinput())
mod = 10**9 + 7
ans = 0

if max(a)==0:
  print(0)
  exit()

for j in reversed(range(60)):
    one = 0
    zero = 0
    for i in range(n):
        b = str(bin(a[i]))[2:]
        c = b.zfill(60)
        s = int(c[j])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**(59-j)) 
    ans %= mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def myinput():
    return map(int,readline().split())

n = int(readline())
a = list(myinput())
mod = 10**9 + 7
ans = 0

for j in reversed(range(60)):
    one = 0
    zero = 0
    for i in range(n):
        b = str(bin(a[i]))[2:]
        c = b.zfill(60)
        s = int(c[j])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**(59-j)) 
    ans %= mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
ans = 0

for j in reversed(range(61)):
    one = 0
    zero = 0
    for i in range(n):
        b = str(bin(a[i]))[2:]
        c = b.zfill(61)
        s = int(c[j])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**(60-j)) % mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
ans = 0

ls_bin = []
for i in range(n):
    b = str(bin(a[i]))[2:]
    c = b.zfill(61)
    ls_bin.append(c)
# print(ls_bin)

ans = 0
for j in reversed(range(61)):
    one = 0
    zero = 0
    for i in range(n):
        s = int(ls_bin[i][j])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**(60-j)) % mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
ans = 0

ls_bin = []
for i in range(n):
    b = str(bin(a[i]))[2:]
    c = b.zfill(61)
    ls_bin.append(c)
# print(ls_bin)

ans = 0
for j in reversed(range(61)):
    one = 0
    zero = 0
    for i in range(n):
        s = int(ls_bin[i][j])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**(60-j))
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
a=a[::-1]
c=format(a[0],'b')
c=len(c)
m=10**9+7
zeros=[0]*c
power2=[1]*c
for i in range(n):
  a[i]=format(a[i],'b')
  a[i]=a[i][::-1]
  for j in range(len(a[i])):
    if a[i][j]=='1':
      zeros[j]+=1
for i in range(1,c):
  power2[i]=(power2[i-1]*2)%m
ans=0
for i in range(c):
  ans=(ans+zeros[i]*(n-zeros[i])*power2[i])%m
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=10**9+7
zeros=[0]*60
power2=[1]*60
for i in range(n):
  a[i]=format(a[i],'b')
  a[i]=a[i][::-1]
  for j in range(len(a[i])):
    if a[i][j]=='1':
      zeros[j]+=1
for i in range(1,60):
  power2[i]=(power2[i-1]*2)%m
ans=0
for i in range(60):
  ans=(ans+zeros[i]*(n-zeros[i])*power2[i])%m
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
mod=10**9+7
l=list(map(int,input().split()))
d=len(str(bin(max(l))))-2
ll=[[0,0] for i in range(d)]
ans=0
for i in l:
  for j,v in enumerate(bin(i)[2:].zfill(d)):
    ll[d-j-1][int(v)]+=1
for i,(a,s) in enumerate(ll):
  ans+=(2**i%mod)*a*s%mod
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a = list(map(lambda x:format(x,'060b'),map(int,input().split())))

p = 10**9+7
ans = 0

for i in range(60):
    one = 0
    for j in range(n):
        if a[j][59-i]=='1':
            one += 1
    ans += pow(2,i,p)*one*(n-one)

print(ans%p)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a = list(map(lambda x:format(x,'b'),map(int,input().split())))
b = list(map(len,a))

p = 10**9+7
s = 0
for i in range(max(b)):
    zero = 0
    one = 0
    for j in range(n):
        if len(a[j]) < i+1:
            zero += 1
            continue
        if a[j][-(1+i)]=='1':
            one += 1
        else:
            zero += 1
    cnt = one*zero%p
    s += (cnt*pow(2,i,p))%p

print(s%p)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a = list(map(lambda x:format(x,'b'),map(int,input().split())))
b = list(map(len,a))

p = 10**9+7
s = 0
for i in range(max(b)):
    zero = 0
    one = 0
    for j in range(n):
        if len(a[j]) < i+1:
            zero += 1
            continue
        if a[j][-(1+i)]=='1':
            one += 1
        else:
            zero += 1
    s += (one*zero)*2**i%p

print(s%p)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a = list(map(lambda x: x[2:],map(bin,map(int,input().split()))))

p = 10**9+7
def xor(a,b):
    a,b = int(a),int(b)
    c = str(a+b)
    c = list(map(lambda x: '1' if x=="1" else '0',c))
    s = 0
    for i in range(len(c)):
        s += int(c[len(c)-1-i])*2**i % p
    return s%p
s = 0
for i in range(n-1):
    for j in range(i+1,n):
        s += xor(a[i],a[j])
        s = s%p
print(s)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
B=[format(a,'b').zfill(100) for a in A]
mod=pow(10,9)+7
answer=0
for i in range(100):
    zero=0
    one=0
    kotae=1
    for j in B:
        if j[i]=='0':
            zero+=1
        elif j[i]=='1':
            one+=1
    kotae=zero*one
    for _ in range(100-i-1):
        kotae*=2
    answer+=kotae
print(answer%mod)

Submission status: Time Limit Exceeded

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

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

for i in range(0, len(A)):
    _a = A[i]
    for j in range(len(li))[::-1]:
        quo = _a // pow(2, j)
        li[j] += quo
        _a -= quo*pow(2, j)


res = 0
for i in range(len(li)):
    res += (pow(2, i) * (li[i]*(N-li[i])))%MOD
    res %= MOD
print(res)

Submission status: Time Limit Exceeded

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

lists = [[] for i in range(len(A))]

_a = A[0]
li = [0 for i in range(61)]
for i in range(len(li))[::-1]:
    quo = _a // pow(2, i)
    li[i] = quo
    _a -= quo*pow(2, i)
lists[0] = li

for i in range(1, len(A)):
    _a = A[i]
    li = [0 for j in range(61)]
    for j in range(len(li))[::-1]:
        quo = _a // pow(2, j)
        li[j] = lists[i-1][j] + quo
        _a -= quo*pow(2, j)
    lists[i] = li

res = []
for j in range(len(A)-1):
    a = A[j]
    lia = [lists[len(lists)-1][i] - lists[j][i] for i in range(61)]
    if j == 0:
        lib = lists[0]
    else:
        lib = [lists[j][i] - lists[j-1][i] for i in range(61)]
    _res = 0
    for i in range(len(li)):
        if lib[i] % 2 == 0:
        # 0のとき
            _res += pow(2, i) * lia[i]
        else:
        # 1のとき
            _res += pow(2, i) * ((N-j-1) - (lia[i]))
        _res %= MOD
    res.append(_res)
print(sum(res) % MOD)

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 i in range(60):
    x = 0
    for j in range(n):
        if a[j] >> i & 1: x += 1 # i桁目が1である数の個数
    now = x*(n-x)%mod # 0と1の組み合わせの数(0 xor 1 = 1)
    for _ in range(i): now = now*2%mod # i桁目が1なら*2^i
    ans += now
    ans %= mod
print(ans)

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

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

Submission status: Time Limit Exceeded

Solution code:
#abc15047d
n=int(raw_input())
a=map(int,raw_input().split())
mod=10**9+7
res=0
for i in range(60):
 cnt=sum([1 for x in a if (x>>i & 1)])
 res+=cnt*(n-cnt)*(1<<i)
 res=res%mod
print res

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

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

#k=len(str(bin(max(nums))))-2
if max(nums)==0:
    print(0)
    sys.exit()
else:
    k=int(math.log2(max(nums)))+1

mat=[]
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    mat.append(list(num))
 
mat=list(zip(*mat))
ans=0
 
for i in range(k):
    b=mat[i].count("1")
    ans+=b*(N-b)*pow(2,(k-i-1),l)
print(ans%l)