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 d(A, d):
    return (A >> d) & 1

def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    _s = 0
    S = [[0]*60 for _ in range(N)]
    S[0] = [d(A[0],j) for j in range(60)]
    for i in range(1,N):
        for j in range(60):
            S[i][j] += S[i-1][j] + d(A[i], j)
    res = 0
    for i in range(1,N):
        for j in range(60):
            if d(A[i],j) == 0:
                res += (S[i-1][j])*(2**j)
                res %= (10**9+7)
            else:
                res += (i - S[i-1][j])*(2**j)
                res %= (10**9+7)
    print(res % (10**9+7))
    # print(S)
    # dp = [[0]*N for _ in range(60)]
    # dp[0] = [d(S[i], 0) for i in range(N)]
    # for i in range(1,60):
    #     for j in range(N):
    #         dp[i][j] = dp[i][j-1] ^ d(S[j-1] ^ (A[j] if (N-1)%2==0 else 0), i) ^ (1 if dp[i-1][j-1] > dp[i-1][j] else 0)
    # res = 0
    # for a in reversed(dp[N-1]):
    #     res <<= 1
    #     res += a
    # print(res)
main()

Submission status: Time Limit Exceeded

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    t = 0
    ls = [0] * 70
    for v in a:
        tt = bin(v)
        for i in range(len(tt)-2):
            ls[i] += int(tt[-i-1])
    for v in a:
        tt = bin(v)
        for i in range(len(tt)-2):
            if tt[-i-1] == "1":
                t += 2 ** i * (n - ls[i])
                t %= mod
    print(t)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
L=len(format(max(a),"b"))
s=[0]*L
for i in range(n):
  c=format(a[i], 'b').zfill(L)
  for j in range(L)[::-1]:
    s[j]+=int(c[j])
ans=0
for i in range(len(s))[::-1]:
  ans+=2**(i)*(s[L-i-1])*(n-s[L-i-1])
  ans%=mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
mod = 10 ** 9 + 7
pows = [1] * 66
for i in range(65):
    pows[i + 1] = (pows[i] * (i + 1)) % mod


def read_valus():
    return map(int, input().split())


def read_list():
    return list(read_valus())


def read_lists(N):
    return [read_list() for n in range(N)]


def c(a, b):
    return pows[a] * pow(pows[a - b], mod - 2, mod) * pow(pows[b], mod - 2, mod) % mod


def p(N, a):
    return a * (N - a) % mod


def main():
    N = int(input())
    A = read_list()

    num = [0] * 65
    for a in A:
        b = format(a, "065b")[::-1]
        for i in range(65):
            num[i] += int(b[i])

    res = 0
    for i in range(65):
        res = (res + pow(2, i, mod) * p(N, num[i])) % mod

    print(res % mod)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

tmp = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = [''.join(str(bin(x)).replace('0b', '')).zfill(60) for x in a]

ans = 0
for i in range(60):
    n0 = 0
    n1 = 0
    for j in a:
        if j[i] == '0':
            n0+=1
        else:
            n1+=1
    ans+=((2**(60-i-1)) * n0 * n1)
    
print(ans%(10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

B = [0] * 62
for a in A:
    for i in range(62):
        if a >> i & 1:
            B[i] += 1

ans = 0
for i, b in enumerate(B):
    ans += ((N - b) * b % mod) * pow(2, i, mod)
    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
    for i in a:
        j=list(reversed(bin(i)[2:]))
        for k in range(len(j)):
            if j[k]=="1":
                l1[k]+=1
    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():
    N = int(input())
    A = list(map(int, input().split()))
    sum = 0
    for i in range(N):
        for j in range(i,N):
            sum += A[i]^A[j]
            sum%=1000000007
    print(sum)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from pprint import pprint

def pow_r(x, n):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2) % (10**9 + 7)
    else:
        return (x * pow_r(x ** 2, (n - 1) // 2)) % (10**9 + 7)


def solve(n, a):

    zero_count = [0] * 60
    for a_i in a:
        binary = format(a_i, '060b')

        for j, b_j in enumerate(binary):
            zero_count[j] += int(b_j)

    ans = 0
    for i, count in enumerate(zero_count[::-1]):
        # ans += (2**i) * (count * (n - count)) 
        ans += pow_r(2, i) * (count % (10**9 + 7)) * ((n - count) % (10**9 + 7)) 
        ans %= 10**9 + 7
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

Submission status: Time Limit Exceeded

Solution code:
bites = [0 for _ in range(60)]
n = int(input())
a_array = map(int, input().split())
for a in a_array:
    a = a << 1
    for i in range(60):
        a = a >> 1
        if not a:
            break
        if a & 1:
            bites[i] += 1
ans = 0
base = 1
for i in range(60):
    if i:
        base *= 2
    base %= 10 ** 9 + 7
    ans += base * bites[i] * (n - bites[i])
    ans %= 10 ** 9 + 7
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
MOD = 10**9 + 7

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

count_list = [0] * 60
        
for i in inputs:
    tmp = bin(i)
    for i in range(len(tmp) - 2):
       # print(60-(len(tmp)-2)+i)
       # print("tmp="+str(int(tmp[2:][i])))
        count_list[60-(len(tmp)-2)+i] += int(tmp[2:][i])
    #print("count_list="+str(count_list))

result = 0
for i in range(60):
    keta_result = count_list[i] * (n - count_list[i])
    #print("keta_result="+str(keta_result)+" i="+str(i))
    result += keta_result * (2 ** (60 - 1 - i))
#print(count_list)
print(result % MOD)

Submission status: Time Limit Exceeded

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

cnt=[0]*60
p=10**9+7
for m in a:
    #b=bin(m)
    #l=len(b)-2
    #print(b)
    for i in range(60):
        if((m>>i) & 1):
            cnt[i]+=1
    #for i in range(l):
    #    cnt[i]+=int(b[-i-1])
    #kei=m
    #for i in range(100):
    #    cnt[i]+=kei%2
    #    kei//=2
    #    if(kei==0):
    #        break

#print(cnt)

lis=[]
jou=1
for i in range(60):
    lis.append(jou)
    jou*=2
    jou%=p

ans=0

for i in range(60):
    ans+=(lis[i]%p)*(cnt[i]%p)*((n-cnt[i])%p)
    ans%=p

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
mod = 10**9+7
N = int(sys.stdin.readline())
A = tuple(map(int, sys.stdin.readline().split()))
B = []
ans = 0
for i in A:
    B.append(list(bin(i)[2:]))
C = [0 for i in range(60)]
for i in B:
    for l in range(len(i)):
        if i[-(l+1)] == '1':
            C[l] += 1
for i in range(60):
    ans = (ans + C[i]*(N-C[i])*(2**i)) % mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
n = int(input())
a = list(map(int,input().split()))
ans = 0
mod = (10**9 +7)
for j in range(61):
    num_zero = 0
    for i in range(len(a)):
        if a[i] % 2 == 0: 
            num_zero += 1
        a[i] = a[i] //2
    #print(a)
    ans += num_zero * (n-num_zero) * (2**j) 
    #print(ans)
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

max_A = max(A)
j = 0
while max_A >> j > 0:
    j += 1
max_j = j

c = defaultdict(int)
ans = 0
MOD = 10 ** 9 + 7
for i in range(N - 2, -1, -1):
    Ai = A[i + 1]
    for j in range(max_j):
        c[(j, Ai >> j & 1)] += 1
    Ai = A[i]
    for j in range(max_j):
        ans += (1 << j) * c[(j, (Ai >> j & 1 ^ 1))]
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

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

mod = 10 ** 9 + 7


def read_valus():
    return map(int, input().split())


def read_list():
    return list(read_valus())


def read_lists(N):
    return [read_list() for n in range(N)]


def p(N, a):
    return (a * (N - a)) % mod


def main():
    pows = [1] * 66
    for i in range(65):
        pows[i + 1] = (pows[i] * 2) % mod

    N = int(input())
    A = read_list()

    num = [0] * 65
    for a in A:
        tmp = a
        for i in range(65):
            if tmp == 0:
                break
            num[i] += tmp % 2
            tmp //= 2

    res = 0
    for i in range(65):
        if num[i] == 0:
            continue

        res = (res + (pows[i] * p(N, num[i])) % mod) % mod

    print(res % mod)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
ans = 0
#print("---")
for i in range(n-1):
    for j in range(n-1-i):
        a = s[i] ^ s[j+i+1]
        ans += a
        #print(s[i], s[j+i+1], "の和＝", a, ans)
#print("---")
print(ans%(10**9 +7))

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

N = int(input())
values = [int(num) for num in input().split(' ')]

ans = 0
for i in range(len(values)):
    for j in range(i, len(values)):
        ans += values[i] ^ values[j]

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

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
ls = list(map(int,input().split()))
mod = 10**9 + 7
check = [[0]*61 for i in range(n+1)]
bit = [[False]*61 for i in range(n+1)]
index = n-1
for i in range(n,0,-1):
    c = ls[i - 1]
    co = 60
    wari = 2 ** 60
    check[i - 1] = [o for o in check[i]]
    while c > 0:
        check[i - 1][co] = check[i][co]
        if c < wari:
            co -= 1
            wari //= 2
            continue
        check[i - 1][co] += (c >= wari) + 0
        bit[i-1][co] = (c >= wari)
        co -= 1
        c %= wari
        wari //= 2

ans = 0
c = 0
for j in range(n - 1):
    c = 0
    for i in range(60):

        ans += (2 ** c) * check[j + 1][c] * ((not bit[j][c]) + 0) + (2 ** c) * (n - j - 1 - check[j + 1][c]) * ((bit[j][c]) + 0)
        c += 1
        ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#O(nm) = O(60n)で解けるはず・・・！
n = int(input())
*l, = map(int,input().split())
#2進数の桁の出現数をカウントする。
lone = [0]*60
for i in range(n):
  s = bin(l[i])[2:]
  for j in range(len(s)):
    lone[j] += int(s[-j-1])
ans = 0
for i in range(60):
  ans += (2**i*lone[i]*(n-lone[i]))%(10**9+7)
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    a_s = LI()
    kaizyo = [1]
    kaizyo_append = kaizyo.append
    keta = [0 for i in range(60)]
    ans = 0
    for i in range(60):
        kaizyo_append(kaizyo[i] * 2 % MOD)
    for i in a_s:
        for i, v in enumerate(format(i, 'b')[::-1]):
            keta[i] += int(v)
    for i, v in enumerate(keta):
        c = v * (n-v) % MOD
        ans += c * kaizyo[i]
        ans = ans % MOD
        # print(ans, c, kaizyo[i])

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007
S = 0
for i in range(N-1):
    for j in range(i+1,N):
        S += A[i]^A[j]
        S = S%MOD
        
print(S)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
s = input().split(" ")
num_list = [int(x) for x in s]
taken_list, count = num_list.copy(), 0
for x in num_list:
    taken_list.remove(taken_list[0])
    for y in taken_list:
        count += x ^ y
print(count % (pow(10, 9)+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.reverse()
mod = 7 + 10**9
leng = 61
data = [[0 for i in range(leng+1)]for j in range(n)]
#pre
for i in range(n):
    k = list(bin(a[i]))
    k.reverse()
    ll = len(k)
    for j in range(1, leng+1):
        if j - 1 >= ll:
            data[i][j] = data[i - 1][j]
            continue
        if k[j - 1] == "1":
            data[i][j] = data[i - 1][j] + 1
        else:
            data[i][j] = data[i-1][j]
ans = 0
a.reverse()
data.reverse()
for i in range(n-1):
    k = bin(a[i])
    k = list(map(int, k[:1:-1]))
    k = k + [0 for i in range(leng - len(k))]
    for j in range(leng):
        if k[j] == 1:
            ans += ((n - i - 1) - data[i+1][j+1]) * (2**j)
            ans %= mod
        else:
            ans += data[i+1][j+1] * (2**j)
            ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
P = 10 ** 9 + 7
 
n = int(input())
a = list(map(int, input().split()))
a.sort()
 
b = [[0 for j in range(60)] for i in range(n)]
 
str_a = format(a[0], "0b")
for i in range(len(str_a)):
  a_bit = int(str_a[-(i + 1)])
  b[0][i] = a_bit
 
for i in range(1, n):
  str_a = format(a[i], "0b")
  for j in range(len(str_a)):
    a_bit = int(str_a[-(j + 1)])
    b[i][j] = b[i - 1][j] + a_bit
    
ans = 0
for i in range(1, n):
  str_a = format(a[i], "0b")
  for j in range(len(str_a)):
    if str_a[-(j + 1)] == "0":
      ans += b[i - 1][j] * (2 ** j)
    else:
      ans += (i - b[i - 1][j]) * (2 ** j)
 
print(ans % P)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

n = int(input())
A = list(map(int, input().split()))
s = 0

def xor(a, b):
    return a ^ b
for i in range(n-1):
    for j in range(i+1, n):
        s += xor(A[i],A[j])%(10**9+7)
s = s % (10**9+7)
print(s)

Submission status: Time Limit Exceeded

Solution code:
# D - Xor Sum 4
N = int(input())
A = list(map(int, input().split()))
DP =[]
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        DP.append(int(A[i]^A[j]))

print(sum(DP) % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
# An efficient Python3 program to compute
# sum of bitwise OR of all pair

# Returns sum of bitwise OR
# of all pairs
def sumXOR( arr,  n):
    s = 0
    for i in range(0, 60):
        #  Count of zeros and ones
        zc = 0
        oc = 0
        # Individual sum at each bit position
        idsum = 0
        for j in range(0, n):
            if (arr[j] % 2 == 0):
                zc = zc + 1
            else:
                oc = oc + 1
            arr[j] = arr[j]  >> 1;
        # calculating individual bit sum
        idsum = oc * zc * (1 << i)
        # final sum
        s = (s + idsum)%(1000000007);
    return s



# driver function
s = 0
n = int(input())
arr = [int(i) for i in input().split()]
s = sumXOR(arr, n);
print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum_a = 0
for i in range(n-1):
    for j in range(i+1, n):
        sum_a += (a[i] ^ a[j]) % 1000000007

print(sum_a % 1000000007)

Submission status: Time Limit Exceeded

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


n = 60
N = read_a_int()
A = read_ints()


def ret_binary(a: int):  # 逆順で返すことに注意
    tmp = bin(a)[2:]
    ret_r = [0] * n
    for i, t in enumerate(tmp[::-1]):
        ret_r[i] = int(t)
    return ret_r


def calc_sum(a, n_1_ls, n_1_max):
    '''
    aはxorしてから和を取りたい数
    n_1_lsは各桁の1の数
    n_1_maxは最大1は何個あり得るか
    '''
    a_binary = ret_binary(a)
    ret = 0
    for i, (aa, n_1) in enumerate(zip(a_binary, n_1_ls)):
        if aa == 0:
            ret += (((2**i) % MOD) * (n_1 % MOD)) % MOD
        else:
            ret += (((2**i) % MOD) * ((n_1_max - n_1) % MOD)) % MOD
    return ret


def add_koko(lsa, lsb):
    return [a + b for a, b in zip(lsa, lsb)]


MOD = 10**9 + 7

n_1_max = 0
n_1_ls = [0] * n
ans = 0
a_pre = A[N - 1]
for i in range(N - 2, -1, -1):
    a = A[i]
    n_1_ls = add_koko(n_1_ls, ret_binary(a_pre))
    n_1_max += 1
    tmp = calc_sum(a, n_1_ls, n_1_max)
    ans += tmp
    ans %= MOD
    a_pre = a

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline())
A = tuple(map(int, sys.stdin.readline().split()))
B = []
ans = 0
for i in A:
    B.append(list(bin(i)[2:]))
C = [0 for i in range(60)]
for i in B:
    for l in range(len(i)):
        if i[-(l+1)] == '1':
            C[l] += 1
for i in range(60):
    ans = (ans + C[i]*(N-C[i])*(2**i))%(10**9+7)
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(N):
    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())
A = list(map(int, input().split()))

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

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

Submission status: Time Limit Exceeded

Solution code:
denominator = 1000000000 + 7

def prepare(a):
  a = int(a)
  a = a % denominator
  return a

N = int(input().rstrip())
l = list(map(int, input().rstrip().split(' ')))
#l = list(map(prepare, input().rstrip().split(' ')))

sum = 0
hash = {}

for i in range(N-1):
  for j in range(i+1, N):
    if l[i] < l[j]:
      x, y = l[i], l[j]
    else:
      x, y = l[j], l[i]
    
    if not str(x) + ':' + str(y) in hash:
      hash[str(x) + ':' + str(y)] = int(l[i] ^ l[j]) % denominator
      sum += (int(l[i] ^ l[j]) % denominator)
    else:
      sum += hash[str(x) + ':' + str(y)]
    #print('l[i]:' + str(l[i]) + ', l[j]: ' + str(l[j]) + ', l[i] ^ l[j]: ' + str(l[i] ^ l[j]))

print(sum % denominator)

Submission status: Time Limit Exceeded

Solution code:

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

###
ans2 = [(A[y] ^ A[x]) % 1000000007 for y in range(N) for x in range(y+1,N)]
print(sum(ans2)%1000000007)
###

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(0, 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:
import itertools


def xor_pair_sum(ar, n): 
    total = 0
    nums = list(itertools.combinations(ar,2))
    return sum([i[0] ^ i[1] for i in nums])
  
  
# Driver program to test the above function 
n = int(input()) 
nums = list(map(int, input().split()))
mod = 1000000007
print(xor_pair_sum(nums, n) % mod)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = list(input().split())
d_to_num1 = {}
max_len = 0
for i in range(N):
    a = list(bin(int(A[i]))[2:])
    if max_len <= len(a):
        max_len = len(a)
    for j,b in enumerate(reversed(a)):
        if b=='1':
            if not(j in d_to_num1.keys()):
                d_to_num1[j]=1
            else:
                d_to_num1[j]+=1 
        
if __name__ == "__main__":

    res = 0
    mod = 10**9+7

    for i in range(max_len):
        if not(i in d_to_num1.keys()):
            num_1 = 0
        else:
            num_1 = d_to_num1[i]
        num_0 = (N-num_1)%mod
        tmp = 1
        tmp *= num_1
        tmp %= mod
        tmp *= num_0
        tmp %= mod
        for _ in range(i):
            tmp = (tmp*2)%mod
        res += tmp%mod
        res %= mod
    print(res)

Submission status: Time Limit Exceeded

Solution code:
#bit表記を足せればいいんだけど...。
import numpy as np#単純に足し合わせるのは繰り上がりに対応できない
n = int(input())
lst = list(map(int,input().split()))
MOD = 10**9+7
max_x = max(lst) 
max_length = len(bin(max_x))-2
lst = [bin(x)[2:] for x in lst]
cnt_1 = [0]*max_length#ここに記録していく.
cnt_0 = [0]*max_length

for x in lst:
    for i in range(1,max_length+1):
        if len(x) < i:
            cnt_0[i-1] += 1
        else:
            if x[-i] == '1':
                cnt_1[i-1] += 1
            else:
                cnt_0[i-1] += 1
ans=0
for i in range(0,max_length):
    cnt_0_i = cnt_0[i]
    cnt_1_i = cnt_1[i]
    ans += cnt_0_i * cnt_1_i * (1 << i)
    ans = ans % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**7)
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())

def main():
    n = II()
    a_s = LI()
    kaizyo = [1]
    kaizyo_append = kaizyo.append
    keta = [0 for i in range(60)]
    ans = 0
    for i in range(60):
        kaizyo_append(kaizyo[i] * 2 % MOD)
    for i in a_s:
        for j, v in enumerate(format(i, 'b')[::-1]):
            keta[j] += int(v)
    for i, v in enumerate(keta):
        c = v * (n-v) % MOD
        ans += c * kaizyo[i] % MOD
        ans = ans % MOD

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

Submission status: Time Limit Exceeded

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

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    mLEN = len(format(max(A),'b'))
    bA = [[0]*N for _ in range(mLEN)]

    for i in range(N):
        a = format(A[i],'b').zfill(mLEN)
        for k in range(mLEN):
            bA[k][i] = a[k]

    answer = 0
    for keta in range(mLEN):
        zero = bA[keta].count('0')
        one = N-zero
        a = 0
        for i in range(N):
            if bA[keta][i] == '1':
                one -= 1
                a += zero
            else:
                zero -= 1
                a += one

        answer += a*pow(2,mLEN-1-keta,MOD)
    print(answer%MOD)
    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:
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
bi=[0]*60
for i in range(N):
  a=list(bin(A[i]))
  for j in range(len(a)-2):
    bi[60-len(a)+2+j]+=int(a[j+2])
  
bi.reverse()
ans=0
for i in range(60):
  ans=(ans+((2**i)*bi[i]*(N-bi[i]))%mod)%mod
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

c = [0] * 60

const = 10 ** 9 + 7

ans = 0

"""
for i in range(n):
    b = str(bin(a[i]))
    for j in range(len(b) - 2):
        c[j] += int(b[- j - 1])
"""

"""
for i in range(n):
    b = a[i]
    t = 0
    while t <= 60:
        if b == 0:
            break
        elif b == 1:
            c[t] += 1
            break
        else:
            c[t] += b % 2
            b = b // 2
            t += 1
"""

for i in range(n):
    b = a[i]
    while b > 0:
        c[int(math.log2(b & -b))] += 1
        b &= b - 1

for i in range(60):
    ans += (((2 ** i) % const) * (c[i] * (n - c[i]))) % const

print(ans % const)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

s = [0]*10**4
p = itertools.combinations(a,2)
s = [v[0]^v[1] for v in p]
  
t = sum(s)
print(t%mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
inf = 10**9+7
a = list(int(x) for x in input().split())
b = []
for key in a:
    p = 0
    while key:
        q = key%2
        if q:
            if p >= len(b):
                b.append(1)
            else:
                b[p] = b[p]+1
        else:
            if p >= len(b):
                b.append(0)
        key = key//2
        p += 1
ans = 0
k = 1
q = 0
for key in b:
    if b[q]:
        ans = (ans+k*(n-b[q])*b[q])%inf
    q += 1
    k *= 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from pprint import pprint

def pow_r(x, n):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2) % (10**9 + 7)
    else:
        return (x * pow_r(x ** 2, (n - 1) // 2)) % (10**9 + 7)


def solve(n, a):

    zero_count = [0] * 60
    for a_i in a:
        binary = format(a_i, '060b')

        for j, b_j in enumerate(binary):
            zero_count[j] += int(b_j)

    ans = 0
    for i, count in enumerate(zero_count[::-1]):
        # ans += (2**i) * (count * (n - count)) 
        ans += pow_r(2, i) * (count * (n - count)) 
        ans %= 10**9 + 7
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

Submission status: Time Limit Exceeded

Solution code:
words = lambda t : list(map(t, input().split()))
n = int(input())
xs = words(int)

ys = []
n = 0
for x in xs:
    y = list(reversed(bin(x)))[:-2]
    ys.append(y)
    n = max(n, len(y))
#print(ys, n)
ans = 0
for i in range(n):
    x0 = 0
    x1 = 0
    for y in ys:
        #print(y,i,len(y))
        if i < len(y):
            if y[i] == "1":
                x1 += 1
            else:
                x0 +=1
        else:
            x0 += 1
    #print(x1,x0)
    ans += x1 * x0 * (2**(i))
    ans %= 10**9 + 7
print(ans)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
s = input().split(" ")
num_list = [int(x) for x in s]
taken_list, count = [x for x in num_list], 0
for x in num_list:
    taken_list.remove(taken_list[0])
    for y in taken_list:
        count += x ^ y
print(count % (pow(10, 9)+7))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A_list = [[int(i) for i in bin(int(A))[2:].zfill(61)] for A in input().split()]
ans = 0
 
for i in range(61):
  one = sum([A_list[j][i] for j in range(n)])
  ans += 2**(60-i) * one * (n-one)
  ans %= 10**9+7
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
a_ls = [bin(int(i))[2:].zfill(60) for i in sys.stdin.readline().split()]
MOD = 10**9 + 7
#memo_ls[i][j] : 後ろからi番目まででj桁に1がある個数
memo_ls = [[0 for j in range(60)] for i in range(n+1)]
for i, a in enumerate(a_ls[::-1], 1):
    for j, k in enumerate(a[::-1]):
        memo_ls[i][j] = memo_ls[i-1][j] + int(k)

res = 0
for i, a in enumerate(a_ls):
    for j, x in enumerate(a[::-1]):
        if x == "0":
            res += 2 ** j * memo_ls[n-1-i][j]
        else:
            res += 2 ** j * (n - 1 - i - memo_ls[n-1-i][j])
        res %= MOD
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.reverse()
mod = 7 + 10**9
leng = 61
data = [[0 for i in range(leng+1)]for j in range(n)]
#pre
for i in range(n):
    k = bin(a[i])
    k = k[::-1]
    ll = len(k)
    for j in range(1, leng+1):
        if j - 1 >= ll:
            data[i][j] = data[i - 1][j]
            continue
        if k[j - 1] == "1":
            data[i][j] = data[i - 1][j] + 1
        else:
            data[i][j] = data[i-1][j]
ans = 0
a.reverse()
data.reverse()
for i in range(n-1):
    k = bin(a[i])
    k = list(map(int, k[:1:-1]))
    k = k + [0 for i in range(leng - len(k))]
    for j in range(leng):
        if k[j] == 1:
            ans += ((n - i - 1) - data[i+1][j+1]) * (2**j)
            ans %= mod
        else:
            ans += data[i+1][j+1] * (2**j)
            ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
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:
import operator
n=int(input())
l=map(int,input().split())
dic=dict(zip(range(n),l))
ans=0
for i in range(n):
    for j in range(i,n):
        if i == j:
            continue
        ans+=operator.xor(dic[i],dic[j])
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

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

def func(x, nn):
    value = 0
    for i, j in itertools.combinations(range(nn), 2):
        value += x[i] ^ x[j]
    ans = value % (10 ** 9 + 7)
    return ans

def main():
    n = int(input())
    li = tuple(map(int, input().split()))
    print(func(li, n))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = sorted(map(int, input().split()))

sums = 0
for x in itertools.combinations(a, 2):
        r =int(bin(x[0] ^ x[1]), 2)
        sums += r

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A_list = [[int(i) for i in bin(int(A))[2:].zfill(60)] for A in input().split()]
print(sum([2**(59-i) * sum([A_list[j][i] for j in range(n)]) * (n-sum([A_list[j][i] for j in range(n)])) for i in range(60)])
%(10**9+7))