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 bin_digit(n: int):
    return len(bin(n)[2:]) + 1


def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = K * x
            x = x ** 2
            n = (n - 1) // 2
        else:
            x = x ** 2
            n = n // 2

    return K * x


MOD = 10**9 + 7

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

digit = bin_digit(max(An))

res = 0
for d in range(digit):
    n0, n1 = 0, 0
    for i in range(N):
        if An[i] & pow_k(2, d):
            n1 += 1
        else:
            n0 += 1

    temp = pow_k(2, d) % MOD
    n = n0 * n1 % MOD
    temp *= n % MOD
    res = (res + temp) % MOD

print(res)

Submission status: Time Limit Exceeded

Solution code:
def bin_digit(n: int):
    return len(bin(n)[2:]) + 1


MOD = 10**9 + 7

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

digit = bin_digit(max(An))

res = 0
for d in range(digit):
    n0, n1 = 0, 0
    for i in range(N):
        if An[i] & 1 << d:
            n1 += 1
        else:
            n0 += 1

    temp = (1 << d) % MOD
    n = n0 * n1 % MOD
    temp *= n % MOD
    res = (res + temp) % MOD

print(res)

Submission status: Time Limit Exceeded

Solution code:
def bin_digit(n: int):
    return len(bin(n)[2:]) + 1


MOD = 10**9 + 7

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

digit = bin_digit(max(An))

res = 0
for d in range(digit):
    n0, n1 = 0, 0
    for i in range(N):
        if An[i] & 1 << d:
            n1 += 1
        else:
            n0 += 1

    temp = 2**d % MOD
    n = n0 * n1 % MOD
    temp *= n % MOD
    res = (res + temp) % MOD

print(res)

Submission status: Time Limit Exceeded

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


def solve(N, A, L=60, MOD=10**9+7):
    modsum = 0
    for j in range(L):
        count_ones = sum([(A[i] >> j) & 1 for i in range(N)])
        count_zeros = N - count_ones
        # MODは一度にとる
        modsum +=  (1<<j) * count_zeros * count_ones
        modsum %= MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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


def solve(N, A, L=60, MOD=10**9+7):
    modsum = 0
    for j in range(L):
        count_ones = 0
        count_zeros = 0
        for i in range(N):
            count_ones = count_ones + ((A[i] >> j) & 1)
            count_zeros = N - count_ones
        # MODは一度にとる
        modsum +=  (1<<j) * count_zeros * count_ones
        modsum %= MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を記憶
    count_zeros = [0 for j in range(L+1)]
    count_ones = [0 for j in range(L+1)]
    for i in range(N):
        for j in range(L):
            count_ones[j] = count_ones[j] + ((A[i] >> j) & 1)
            count_zeros[j] = N - count_ones[j]
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for j in range(L):
        # MODは一度にとる
        modsum +=  (1<<j) * count_zeros[j] * count_ones[j]
        modsum %= MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を記憶
    count_zeros = [0 for j in range(L+1)]
    count_ones = [0 for j in range(L+1)]
    for i in range(N):
        for j in range(L):
            count_ones[j] = count_ones[j] + ((A[i] >> j) & 1)
            count_zeros[j] = N - count_ones[j]
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for j in range(L):
        # MODは一度にとる
        modsum += count_zeros[j] * count_ones[j] * (1<<j)
        modsum %= MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を記憶
    count_zeros = [0 for j in range(L+1)]
    count_ones = [0 for j in range(L+1)]
    for i in range(N):
        for j in range(L):
            count_ones[j] = count_ones[j] + ((A[i] >> j) & 1)
            count_zeros[j] = N - count_ones[j]
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for j in range(L):
        # MODは一度にとる
        modsum = (modsum + count_zeros[j] * count_ones[j] * pow(2, j, MOD)) % MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を記憶
    count_zeros = [0 for j in range(L+1)]
    count_ones = [0 for j in range(L+1)]
    for i in range(N):
        for j in range(L):
            count_ones[j] = count_ones[j] + ((A[i] >> j) & 1)
            count_zeros[j] = N - count_ones[j]
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for j in range(L):
        # MODは一度にとる
        modsum = (count_zeros[j] * count_ones[j] * pow(2, j, MOD) + modsum) % MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を記憶
    count_zeros = [0 for j in range(L+1)]
    count_ones = [0 for j in range(L+1)]
    for i in range(N):
        for j in range(L):
            count_ones[j] = count_ones[j] + ((A[i] >> j) & 1)
            count_zeros[j] = N - count_ones[j]
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for j in range(L):
        base = (count_zeros[j] * count_ones[j]) % MOD
        # 64bit以下に収まるように計算
        base = (base * pow(2, j, MOD)) % MOD
        modsum = (base + modsum) % MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を記憶
    count_zeros = [0 for j in range(L+1)]
    count_ones = [0 for j in range(L+1)]
    for i in range(N):
        for j in range(L):
            count_ones[j] = count_ones[j] + ((A[i] >> j) & 1)
            count_zeros[j] = N - count_ones[j]
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for j in range(L):
        base = count_zeros[j] * count_ones[j]
        # 64bit以下に収まるように計算
        base = (base * pow(2, j, MOD)) % MOD
        modsum = (base + modsum) % MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を記憶
    count_zeros = [0 for j in range(L+1)]
    count_ones = [0 for j in range(L+1)]
    for i in range(N):
        for j in range(L):
            count_ones[j] = count_ones[j] + ((A[i] >> j) & 1)
            count_zeros[j] = N - count_ones[j]
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for j in range(L):
        base = count_zeros[j] * count_ones[j]
        # 64bit以下に収まるように分割。base<<jとしない。
        for k in range(j):
            base = (base<<1) % MOD
        modsum = (base + modsum) % MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を記憶
    count_zeros = [0 for j in range(L+1)]
    count_ones = [0 for j in range(L+1)]
    for i in range(N):
        for j in range(L):
            count_ones[j] = count_ones[j] + ((A[i] >> j) & 1)
            count_zeros[j] = N - count_ones[j]
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for j in range(L):
        base = count_zeros[j] * count_ones[j]
        base = (base<<j) % MOD
        modsum = (base + modsum) % MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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

def digits2int(c, L, MOD):
    
    return base


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を、累積和として記憶
    count_ones = [[0 for j in range(L+1)] for i in range(N+1)]
    for i in range(N):
        for j in range(L):
            count_ones[i+1][j] = count_ones[i][j] + ((A[i] >> j) & 1)
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for i in range(N-1):
        c = [0 for j in range(L)]
        for j in range(L):
            if ((A[i] >> j) & 1) == 0:
                c[j] = count_ones[N][j] - count_ones[i+1][j]
            else:
                c[j] = (N-i-1) - (count_ones[N][j] - count_ones[i+1][j])
        # digit2int
        for i in range(L):
            if c[i] > 0:
                f = (c[i] << i) % MOD
                modsum = (modsum + f) % MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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

def digits2int(c, L, MOD):
    base = 0
    for i in range(L):
        f = (c[i] << i) % MOD
        base = (base + f) % MOD
    return base


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を、累積和として記憶
    count_ones = [[0 for j in range(L+1)] for i in range(N+1)]
    for i in range(N):
        for j in range(L):
            count_ones[i+1][j] = count_ones[i][j] + ((A[i] >> j) & 1)
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for i in range(N-1):
        c = [0 for j in range(L)]
        for j in range(L):
            if ((A[i] >> j) & 1) == 0:
                c[j] = count_ones[N][j] - count_ones[i+1][j]
            else:
                c[j] = (N-i-1) - (count_ones[N][j] - count_ones[i+1][j])
        modsum = (modsum + digits2int(c, L, MOD)) % MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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

def digits2int(c, L, MOD):
    base = 0
    for i in range(L):
        factor = (1 << i) % MOD
        f = (factor * c[i]) % MOD
        base = (base + f) % MOD
    return base


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を、累積和として記憶
    count_ones = [[0 for j in range(L+1)] for i in range(N+1)]
    for i in range(N):
        for j in range(L):
            count_ones[i+1][j] = count_ones[i][j] + ((A[i] >> j) & 1)
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for i in range(N-1):
        c = [0 for j in range(L)]
        for j in range(L):
            if ((A[i] >> j) & 1) == 0:
                c[j] = count_ones[N][j] - count_ones[i+1][j]
            else:
                c[j] = (N-i-1) - (count_ones[N][j] - count_ones[i+1][j])
        modsum = (modsum + digits2int(c, L, MOD)) % MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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

def digits2int(c, L, MOD):
    base = 0
    for i in range(L):
        factor = (1 << i) % MOD
        for j in range(c[i]):
            base = (base + factor) % MOD
    return base


def solve(N, A, L=60, MOD=10**9+7):
    # j桁目のビットが1であるものの数を、累積和として記憶
    count_ones = [[0 for j in range(L+1)] for i in range(N+1)]
    for i in range(N):
        for j in range(L):
            count_ones[i+1][j] = count_ones[i][j] + ((A[i] >> j) & 1)
    # A[i] と A[j] (i<j) のxorをとる
    modsum = 0
    for i in range(N-1):
        c = [0 for j in range(L)]
        for j in range(L):
            if ((A[i] >> j) & 1) == 0:
                c[j] = count_ones[N][j] - count_ones[i+1][j]
            else:
                c[j] = (N-i-1) - (count_ones[N][j] - count_ones[i+1][j])
        modsum = (modsum + digits2int(c, L, MOD)) % MOD
    return modsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Time Limit Exceeded

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

MOD = 1000000007  # type: int


def solve(N: int, A: "List[str]"):
    ans = 0
    for i in range(60):
        z = 0
        o = 0
        for a in A:
            if i + 1 > len(a):
                z += 1
            else:
                if a[len(a) - i - 1] == '0':
                    z += 1
                else:
                    o += 1
        ans += (z * o) * (2 ** i)
        ans %= MOD
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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 = [bin(int(next(tokens)))[2:] for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Cn, ans = N * (N-1) // 2, 0

for i in range(60):
    count = 0
    for j in range(N):
        count += A[j] % 2
        A[j] //= 2
    if count == 0:
        continue
    ans += (Cn - (count*(count-1)//2 + (N-count)*(N-count-1)//2)) * (2**i)
print(ans % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import math
from bisect import bisect_left

def C(a,b):
    if a - b < 0:
        return 0
    else:
        return math.factorial(a) // (math.factorial(b)*math.factorial(a-b))

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

Cn, ans = N * (N-1) // 2, 0

for i in range(60):
    count = 0
    for j in range(N):
        count += A[j] % 2
        A[j] //= 2
    if count == 0:
        continue
    ans += (Cn - (C(count, 2) + C(N-count, 2))) * (2**i)
print(ans % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
def main():
  n=int(input())
  num=[int(i) for i in input().split()]
  mod=10**9+7

  import math
  if max(num)==0:
    print(0)
    exit()
  l=math.ceil(math.log(max(num),2))

  ans=[0]*l
  tmp1,tmp2,tmp3=0,0,0
  for i in range(l):
    ans[i]=tmp3
    cnt=0
    for j in range(n):
      if (num[j]>>i)&1:
        cnt+=1
    tmp1=cnt*(n-cnt)
    tmp2=(ans[i]+tmp1)%2
    tmp3=(ans[i]+tmp1)//2
    ans[i]=tmp2

  a_append=ans.append
  while tmp3>0:
    a_append(tmp3%2)
    #print(tmp3)
    tmp3//=2
  #print(ans)
  ans=int(''.join([str(i) for i in ans[::-1]]),2)%mod
  print(ans)
  
if __name__=='__main__':
  main()

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(61):

  one = 0
  for a in A:
    if (a >> i) & 1:
      one += 1
  
  zero = N - one
  ans += one * zero * (2 ** i)
  ans %= mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
mod = 10**9+7
SUM = 0

maxA = max(A)
d = 0
while 1:
    if maxA < 2**d:
        break
    d += 1

BitSumB = 0
for i in range(d):
    tmp = 0
    for n in range(N):
        tmp += (A[n] >> i) & 1
    BitSumB += (2**i) * tmp * (N - tmp)



"""
BitA = [[0]*d for _ in range(N)]
for i in range(N):
    BitA[i] = list(map(int, format(bin(A[i])[2:], '0>{}'.format(d))))

BitSumB = 0
for i in range(d):
    tmp = sum([BitA[j][i] for j in range(N)])
    BitSumB += 2 ** (d-i-1) * (tmp * (N - tmp))
    #BitSumB = BitSumB % mod
"""

print(BitSumB % mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
mod = 10**9+7
SUM = 0

maxA = max(A)
d = 0
while 1:
    if maxA < 2**d:
        break
    d += 1

BitA = [[0]*d for _ in range(N)]
for i in range(N):
    BitA[i] = list(map(int, format(bin(A[i])[2:], '0>{}'.format(d))))

BitSumB = 0
for i in range(d):
    tmp = sum([BitA[j][i] for j in range(N)])
    BitSumB += 2 ** (d-i-1) * (tmp * (N - tmp))
    #BitSumB = BitSumB % mod

print(BitSumB%mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
mod = 10**9+7
SUM = 0

maxA = max(A)
d = 0
while 1:
    if maxA < 2**d:
        break
    d += 1

BitA = [[0]*d for _ in range(N)]
for i in range(N):
    BitA[i] = list(map(int, format(bin(A[i])[2:], '0>{}'.format(d))))

BitSumB = 0
for i in range(d):
    tmp = sum([BitA[j][i] for j in range(N)])
    BitSumB += 2 ** (d-i-1) * (tmp * (N - tmp))
    BitSumB = BitSumB % mod

print(BitSumB)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
mod = 10**9+7
SUM = 0

maxA = max(A)
d = 0
while 1:
    if maxA < 2**d:
        break
    d += 1

BitA = [[0]*d for _ in range(N)]
for i in range(N):
    BitA[i] = list(map(int, bin(A[i]|2**d)[3:]))

BitSumB = 0
for i in range(d):
    tmp = sum([BitA[j][i] for j in range(N)])
    BitSumB += 2 ** (d-i-1) * (tmp * (N - tmp))
    BitSumB = BitSumB % mod

print(BitSumB)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
mod = 10**9+7
SUM = 0

maxA = max(A)
d = 0
while 1:
    if maxA < 2**d:
        break
    d += 1

BitA = [[0]*d for _ in range(N)]
for i in range(N):
    for j in range(d):
        BitA[i][j] = int(bin(A[i]|2**d)[3+j])

BitSumB = 0
for i in range(d):
    tmp = sum([BitA[j][i] for j in range(N)])
    BitSumB += 2 ** (d-i-1) * (tmp * (N - tmp))
    BitSumB = BitSumB % mod

print(BitSumB)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
mod = 10**9+7
SUM = 0

maxA = max(A)
d = 0
while 1:
    if maxA < 2**d:
        break
    d += 1

BitA = [[0]*d for _ in range(N)]
for i in range(N):
    for j in range(d):
        BitA[i][j] = int(bin(A[i]|2**d)[3+j])

BitSumB = 0
for i in range(d):
    tmp = sum([BitA[j][i] for j in range(N)])
    BitSumB += 2 ** (d-i-1) * (tmp * (N - tmp))

print(BitSumB % mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
mod = 10**9+7
SUM = 0

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

print(SUM)

Submission status: Time Limit Exceeded

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

def main():
    N = map(int,input().split())
    a = list(map(int,input().split()))
    MOD = 10**9+7
    M = max(a)
    l = M.bit_length()
    bit = [[0,0] for _ in range(l)]

    for num in a:
        for i in range(l):
            re = num%2
            bit[i][re] += 1
            num //= 2

    ans = 0
    for i in range(l):
        x = (bit[i][0]*bit[i][1])*(1<<i)
        ans += (x%MOD)
    
    print(ans%MOD)    
    
if __name__ == "__main__":
    main()

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):
    x = [(bool)(ai & 1 << i) for ai in a]
    sx = sum(x)
    count = sx * (n - sx)
    ans += count << i
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
scale = 62
#scale = 5
z0 = [0 for _ in range(scale)]
for x in a:
  for d in range(scale):
    if x % 2 == 1:
      z0[d] += 1
    x //= 2
ans = 0
for d in range(scale):
  ans += z0[d] * (n-z0[d]) * 2**d
mod = 10**9+7
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#11:44
n = int(input())
a = list(map(int,input().split()))
scale = 62
#scale = 5
z0 = [0 for _ in range(scale)]
for x in a:
  for d in range(scale):
    if x % 2 == 1:
      z0[d] += 1
    x //= 2
ans = 0
for d in range(scale):
  ans += z0[d] * (n-z0[d]) * 2**d
mod = 10**9+7
ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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


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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
	N = int(input())
	A = map(int, input().split())
	sum = 0
	for i, j in  itertools.combinations(A, 2):
		sum = sum + (i ^ j)
	print( sum % (10**9+7))


if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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

MOD = 10**9+7

ans=0
for i in range(60):
    one_cnt = 0
    for a in a_list:
        one_cnt += (a & 2**i)
    one_cnt //= 2**i
    zero_cnt = n - one_cnt
    ans = (ans + (2**i * one_cnt * zero_cnt) % MOD) % MOD
print(ans)

Submission status: Time Limit Exceeded

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

MOD = 10**9+7

ans=0
for i in range(60):
    one_cnt = 0
    for a in a_list:
        one_cnt += (a & 2**i) // 2**i
    zero_cnt = n - one_cnt
    ans = (ans + (2**i * one_cnt * zero_cnt) % MOD) % MOD
print(ans)

Submission status: Time Limit Exceeded

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

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):
  count_one = sum(a>>i & 1 for a in A)
  ans += count_one * (N - count_one) * (2 ** i)
  
    
print(ans%MOD)

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):
  count_one = sum(a>>i & 1 for a in A)
  ans += (count_one * (N - count_one) * (2 ** i) ) % MOD
  
    
print(ans%MOD)

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(61):
  count_one = sum(a>>i & 1 for a in A)
  ans += (count_one * (N - count_one) * (2 ** i) ) % MOD
  
    
print(ans%MOD)

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(61):
  count_one = sum(a>>i & 1 for a in A)
  ans += count_one * (N - count_one) * (2 ** i)
  
    
print(ans%MOD)

Submission status: Time Limit Exceeded

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

ans = tuple(
  A[i]^A[j] for i in range(N) for j in range(i+1, N)
)
'''for i in range(N):
  for j in range(i+1, N):
    ans += A[i]^A[j]'''
    
print(sum(ans)%MOD)

Submission status: Time Limit Exceeded

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

ans = [
  A[i]^A[j] for i in range(N) for j in range(i+1, N)
]
'''for i in range(N):
  for j in range(i+1, N):
    ans += A[i]^A[j]'''
    
print(sum(ans)%MOD)

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(N):
  for j in range(i+1, N):
    ans += A[i]^A[j]
    
print(ans%MOD)

Submission status: Time Limit Exceeded

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

MOD = 10 ** 9 + 7
ans = 0
m = 1
ans = 0
for _ in range(60):
    one_count = 0
    for a in aaa:
        one_count += a & m
    one_count //= m
    zero_count = n - one_count
    ans = (ans + one_count * zero_count * m) % MOD
    m *= 2
        
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 j in range(61):
  c = 0
  for i in A:
    if i>>j & 1:
      c += 1
  ans += 2**j*((n-c)*c)
  ans %= 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(61):
  c = 0
  for i in A:
    if i>>j & 1:
      c += 1
  ans += 2**j*((n-c)*c)
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
# import math
# import fractions
# import numpy as np

MOD = 10 ** 9 + 7

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

    return ans % MOD

# S = input()
N = int(input())
# H, N = map(int, input().split())
A = list(map(int, input().split()))
# B = [int(input()) for _ in range(n)]
# A = []
# B = []
# for _ in range(N):
#     a, b = list(map(int, input().split()))
#     A.append(a)
#     B.append(b)

print(solve(N, A))

Submission status: Time Limit Exceeded

Solution code:
# import math
# import fractions
import numpy as np

MOD = 10 ** 9 + 7

def solve(N, A):
    # for i, a in enumerate(A):
    #     A[i] = bin(a)
    # print(A)
    
    B = []
    for i in range(N - 1):
        for j in range(i+1, N):
          B.append(np.bitwise_xor(A[i], A[j]) % MOD)  

    return sum(B) % MOD

# S = input()
N = int(input())
# H, N = map(int, input().split())
A = list(map(int, input().split()))
# B = [int(input()) for _ in range(n)]
# A = []
# B = []
# for _ in range(N):
#     a, b = list(map(int, input().split()))
#     A.append(a)
#     B.append(b)

print(solve(N, A))

Submission status: Time Limit Exceeded

Solution code:
# import math
# import fractions
# import numpy as np

MOD = 10 ** 9 + 7

def solve(N, A):
    # for i, a in enumerate(A):
    #     A[i] = bin(a)
    # print(A)
    
    B = []
    for i in range(N - 1):
        for j in range(i+1, N):
          B.append((A[i] ^ A[j]) % MOD)  

    return sum(B) % MOD

# S = input()
N = int(input())
# H, N = map(int, input().split())
A = list(map(int, input().split()))
# B = [int(input()) for _ in range(n)]
# A = []
# B = []
# for _ in range(N):
#     a, b = list(map(int, input().split()))
#     A.append(a)
#     B.append(b)

print(solve(N, A))

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):
  o=0
  x=1<<i
  for j in a:
    if j&x:o+=1
  ans+=x*o*(n-o)
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

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

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):
  x=1<<i
  z=o=0
  for j in range(n):
    if a[j]&x:o+=1
    else:z+=1
  ans=(ans+((x%mod)*o*z)%mod)%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
b = [[0]*60 for i in range(2)]
#max_a = math.ceil(math.log(max(A),2))
max_a = 60
for i in range(N):
    x = A[i]
    j = 0
    for j in range(max_a):
        b[x % 2][j] += 1
        x //= 2

x = 0
for i in range(max_a):
    x += b[0][i] * b[1][i] * 2**i
    x %= 10 ** 9 + 7

print (x)

Submission status: Time Limit Exceeded

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

print (x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
ma = max(a)
maketa = len(bin(ma))-2
mat = np.zeros((N,maketa))
for i,elem in enumerate(a):
    mat[i] = np.array(list(bin(elem)[2:].zfill(maketa)))
res = 0
mat = mat.T
dic = {}
for i in range(maketa):
    dic[i] = int(np.sum(mat[maketa-i-1]))
for i in range(maketa):
    num = dic[i]
    res += num*(N-num)*(2**(i))
print(res%(10**9+7))

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,N,1):
        sum += (A[i]^A[j])
print(sum%(10**9+7))