Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
c = list(input())

ans = 0
l = 0
r = N-1
while l <= r:
    flag = False
    for i in range(l,N):
        if c[i] == 'W':
            l = i
            flag = True
            break
    if not flag:
        l = N

    flag = False
    for i in range(r+1)[::-1]:
        if c[i] == 'R':
            r = i
            flag = True
            break
    if not flag:
        r = 0

    if r < l:
        break
    
    c[l] = 'R'
    c[r] = 'W'
    ans += 1

print(ans)

### FIXED CODE ###

import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
c = list(input())

ans = 0
l = 0
r = N-1
while l <= r:
    flag = False
    for i in range(l,N):
        if c[i] == 'W':
            l = i
            flag = True
            break
    if not flag:
        l = N

    flag = False
    for i in range(r+1)[::-1]:
        if c[i] == 'R':
            r = i
            flag = True
            break
    if not flag:
        r = -1

    if r < l:
        break
    
    c[l] = 'R'
    c[r] = 'W'
    ans += 1

print(ans)
### BUGGY CODE ###

N=int(input())
list = list(map(int, input().split()))
res = []
i=1

while(i<N+1):
  res.append(list.count(i))
  i+=1

k=0
while(k<len(res)):
  print(str(res[k]))
  k+=1

### FIXED CODE ###

from collections import Counter

N=int(input())
list = list(map(int, input().split()))
i=1
counter = Counter(list)

for i in range(1,N+1):
  print(counter[i])
### BUGGY CODE ###

def compute(n, k, h):
    inf = 1e9
    if n == 1:
        return 0
    dp = [inf] * n
    dp[0] = 0
    for i in range(1, n):
        cnt = 1
        while cnt <= k and i - cnt > -1:
            dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
            cnt += 1
    return dp[-1]


if __name__ == '__main__':
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    print(compute(N, K, h))

### FIXED CODE ###

n, k = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
inf = 1e9
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
    cnt = 1
    while cnt <= k and i - cnt > -1:
        dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
        cnt += 1
print(dp[-1])
### BUGGY CODE ###


S = list(map(int, list(input())))

mod = 2019
ctr = [0] * mod
p = 1
t = 0
for i, v in enumerate(reversed(S)):
    t = (t + int(v) * 10 ** i) % mod
    ctr[t] += 1

ans = ctr[0]
for v in ctr[1:]:
    ans += v * (v - 1) // 2
print(ans)


### FIXED CODE ###


S = list(map(int, list(input())))

mod = 2019
ctr = [0] * mod
t = 0
for i, v in enumerate(reversed(S)):
    t = (t + int(v) * pow(10, i, mod)) % mod
    ctr[t] += 1

ans = ctr[0]
for v in ctr:
    ans += v * (v - 1) // 2
print(ans)
### BUGGY CODE ###

x,y,a,b,c= list(map(int, input().split()))
p= list(map(int, input().split()))
q= list(map(int, input().split()))
r= list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
np=p[0:x]
nq=q[0:y]
np.extend(nq)
np.sort()
for i in range(min(len(np),len(r))):
    if np[i]<r[0]:
        np[i]=r.pop(0)
print(sum(np))

### FIXED CODE ###

x,y,a,b,c= list(map(int, input().split()))
p= list(map(int, input().split()))
q= list(map(int, input().split()))
r= list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
np=p[0:x]
nq=q[0:y]
np.extend(nq)
m=min(np)
nr=[i for i in r if i>=m]
np.extend(nr)
np.sort(reverse=True)
print(sum(np[0:x+y]))
### BUGGY CODE ###

import sys
import math
import bisect
from collections import defaultdict

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)

### FIXED CODE ###

from collections import*
from bisect import*
s=input()
n=len(s)
t=input()
d=defaultdict(list)
for i,c in enumerate(s):
    d[c].append(i)
m=-1
o=0
for c in t:
    if not d[c]:
        print(-1)
        exit()
    i=bisect(d[c],m)
    if len(d[c])==i:
        o+=1
        m=d[c][0]
    else:
        m=d[c][i]
print(o*n+m+1)
### BUGGY CODE ###

N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
for i in range(1, N+1):
    if (K - (Q - A.count(i))) <= 0:
        print("No")
    else:
        print("Yes")


### FIXED CODE ###

import collections
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
c = collections.Counter(A)
for i in range(1, N+1):
    if (K - (Q - c[i])) <= 0:
        print("No")
    else:
        print("Yes")
### BUGGY CODE ###

from sys import stdin
a, b = map(int,stdin.readline().split())
greater = max(a,b)
while(True):
    if (greater % a == 0) and (greater % b == 0):
        lcm = greater
        break
    greater += 1
print(lcm)

### FIXED CODE ###

a, b = map(int,input().split())
for i in range(1,b+1):
  if (a*i) % b == 0:
    print(a*i)
    break
### BUGGY CODE ###

from sys import stdin
from collections import deque
input = stdin.readline


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

    nexts = [[] for i in range(n)]
    
    for _ in range(m):
        ai, bi = map(int, input().split())
        ai -= 1
        bi -= 1
        nexts[ai].append(bi)
        nexts[bi].append(ai)

    blues = [-1] * n # 1 is in blues
    blues[0] = 0 # 0 is not in blues

    red_deque = deque([0])

    while -1 in blues:
        rd = red_deque[0]
        red_deque.popleft()

        for nxt in nexts[rd]:
            if blues[nxt] == -1:
                blues[nxt] = rd
                if nxt not in red_deque:
                    red_deque.append(nxt)

    print("Yes")
    for blue in blues[1:]:
        print(blue + 1)
    

if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin
from collections import deque
input = stdin.readline


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

    nexts = [[] for i in range(n)]
    
    for _ in range(m):
        ai, bi = map(int, input().split())
        ai -= 1
        bi -= 1
        nexts[ai].append(bi)
        nexts[bi].append(ai)

    blues = [-1] * n # 1 is in blues
    blues[0] = 0 # 0 is not in blues
    checked = [0] * n

    red_deque = deque([0])

    while len(red_deque) > 0:
        rd = red_deque[0]
        red_deque.popleft()
        if checked[rd] == 0:
            checked[rd] = 1
            for nxt in nexts[rd]:
                if blues[nxt] == -1:
                    blues[nxt] = rd
                    red_deque.append(nxt)

    print("Yes")
    for blue in blues[1:]:
        print(blue + 1)
    

if __name__ == "__main__":
    main()
### BUGGY CODE ###

n = int(input())
first = n
k = [int(x) for x in input().split()]
i=0
while(i<n):
    #print("i="+str(i)+"k[]="+str(k[i]))
    if(k[i]!=i+1): 
        k.pop(i)
        n-=1
    else: i+=1
if(n==0): print("-1")
else: print(first-n)

### FIXED CODE ###

n = int(input())
first = n
k = [int(x) for x in input().split()]
j = 1
for i in (k):
    if(i==j): j+=1
if(j==1): print("-1")
else: print(str(n-j+1))
### BUGGY CODE ###

H, W, M = map(int, input().split())
hallline = [0 for i in range(H)]
wallline = [0 for i in range(W)]
b = []

for i in range(M):
    tmp = list(map(lambda x: int(x) - 1, input().split()))
    hallline[tmp[0]] += 1
    wallline[tmp[1]] += 1
    b.append((tmp[0], tmp[1]))

t = max(hallline)
s = max(wallline)

for i in (i for i in range(H) if hallline[i] == t):
    for j in (i for i in range(W) if wallline[i] == s):
        if (i, j) not in b:
            print(t + s)
            exit()
print(t + s - 1)


### FIXED CODE ###

H, W, M = map(int, input().split())
hallline = [0 for i in range(H)]
wallline = [0 for i in range(W)]
b = {}

for i in range(M):
    tmp = list(map(lambda x: int(x) - 1, input().split()))
    hallline[tmp[0]] += 1
    wallline[tmp[1]] += 1
    b[(tmp[0], tmp[1])] = True

t = max(hallline)
s = max(wallline)

a = [i for i in range(H) if hallline[i] == t]
c = [i for i in range(W) if wallline[i] == s]

tmp = False

for i in a:
    for j in c:
        if (i, j) not in b.keys():
            print(t + s)
            tmp = True
            break
    if tmp:
        break
if not tmp:
    print(t + s - 1)
### BUGGY CODE ###

#Python

N = input()

#print N

a = map(int, raw_input().split())
#print a
#print sum(a)

b=[]

for i in range(N-1):
	i=i+1
	#print "g1::"+str(sum(a[:i]))
	#print "g2::"+str(sum(a[i:]))
	#print "sa::"+str( abs(sum(a[:i]) - sum(a[i:])) )
	b.append( abs(sum(a[:i]) - sum(a[i:])) )

#print b
print min(b)

### FIXED CODE ###

#Python

N = input()
a = map(int, raw_input().split())

b=[]
ans=0
sum=sum(a)

x=0
for i in range(N-1):
	x+=a[i]
	#print "x::"+str(x)
	if i==0:
		ans= abs( sum - x*2 )
	if ans>abs( sum - x*2 ):
		ans= abs( sum - x*2 )
	#print "ans::"+str(ans)

print ans
### BUGGY CODE ###

S = input()

count = 0
while 'BW' in S:
    count += S.count('BW')
    S = S.replace('BW', 'WB')

print(count)


### FIXED CODE ###

S = input()

count = 0
pre_index = 0
pre_count = 0
for index, value in enumerate(S):
    if value == 'W':
        n = S[pre_index:index].count('B')
        count += n + pre_count
        pre_count = n + pre_count
        pre_index = index

print(count)
### BUGGY CODE ###

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

# coding: utf-8
# Your code here!
#N, K = map(int, input().split())
X = int(input())

div = make_divisors(X)

for diff in div:
    for a in range(X):
        if (a**5 - (a-diff)**5) == X:
            print(a, a-diff)
            break

### FIXED CODE ###

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

    # divisors.sort()
    return divisors

# coding: utf-8
# Your code here!
#N, K = map(int, input().split())
X = int(input())

div = make_divisors(X)

for diff in div:
    for a in range(int(X**0.5)):
        if (a**5 - (a-diff)**5) == X:
            print(a, a-diff)
            break
### BUGGY CODE ###

N, X = map(int, input().split())
S = list(map(int, input().split()))



MOD = 1000000007
numbers = S[:]
numbers.sort()
dp = [[0 for _ in range(X+1)] for _ in range(N+1)]

for x in range(X+1):
    dp[0][x] = x

for i, n  in enumerate(numbers):
    for x in range(X+1):
        dp[i+1][x] += dp[i][x % n]
        #dp[i+1][x] = dp[i+1][x] % MOD
        
        dp[i+1][x] += dp[i][x] * i #% MOD
        #dp[i+1][x] = dp[i+1][x] % MOD

print(dp[N][X] % MOD)

### FIXED CODE ###

N, X = map(int, input().split())
S = list(map(int, input().split()))

MOD = 1000000007
numbers = S[:]
numbers.sort(reverse=True)


dp = {X: 1}

for i, n in enumerate(numbers):
    tmp_dp = {}
    for k, v in dp.items():
        if k < n:
            tmp_dp[k] = (tmp_dp.get(k,0)+v*(N-i))
        else:
            tmp_dp[k]=(tmp_dp.get(k,0)+v*(N-i-1)) 
            tmp_dp[k%n]=(tmp_dp.get(k%n,0)+v) 
    dp = tmp_dp.copy()
        
ans = 0
for k, v in dp.items():
    ans += k *  v

print(ans % MOD)
### BUGGY CODE ###

# https://atcoder.jp/contests/abc168/tasks/abc168_d
# BFS

N, M = map(int, input().split(' '))

A = []
B = []
for i in range(M):
    _a, _b = map(int, input().split(' '))
    A.append(_a)
    B.append(_b)

# 接続している部屋のマップ
room_next = [[] for n in range(N)]

for a, b in zip(A, B):
    room_next[a - 1].append(b - 1)
    room_next[b - 1].append(a - 1)

room_depth = [None] * N
room_depth[0] = 0
room_sign = [None] * N

stack = [0]
visited = []

while stack:
    now = stack.pop()
    visited.append(now)
    for r in room_next[now]:
        if r not in visited:
            stack.append(r)

        if room_depth[r] is None:
            room_depth[r] = room_depth[now] + 1
            room_sign[r] = now + 1

print('Yes')
for s in room_sign[1:]:
    print(s)


### FIXED CODE ###

# https://atcoder.jp/contests/abc168/tasks/abc168_d
from collections import deque

N, M = map(int, input().split(' '))

A = []
B = []

# 隣接リスト
route2 = [[] for n in range(N)]

for i in range(M):
    a, b = map(int, input().split(' '))
    A.append(a)
    B.append(b)

for a, b in zip(A, B):
    route2[a - 1].append(b - 1)
    route2[b - 1].append(a - 1)

room_sign = [None] * N

queue = deque([])
visited = set()

queue.append(0)
visited.add(0)

while len(queue) > 0:
    now = queue.popleft()
    for i in route2[now]:
        if i not in visited:
            queue.append(i)
            visited.add(i)

            room_sign[i] = now + 1

print('Yes')
for s in room_sign[1:]:
    print(s)
### BUGGY CODE ###

n, m = map(int, input().split())
As = list(map(lambda x: int(x), input().split()))


for _ in range(m):
  maxa=-1
  for i,a in enumerate(As):
    if maxa<a:
      maxa=a
      maxi=i
  As.pop(maxi)
  As.append(int(maxa/2))
  #print(As)
print(sum(As))

### FIXED CODE ###

import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)  # aを優先度付きキューに

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
score=0
mod=10**9+7
for i in range(0,n-1):
  b=a[0]
  del a[0]
  score+=b*sum(a)
print(score%mod)
    

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b=sum(a)
score=0
for i in range(len(a)):
  b -= a[i]
  score+=a[i]*b
  
print(score%(10**9+7))
### BUGGY CODE ###

def bubble_sort_revision(target_list):

    list_length = len(target_list)
    
    flag = True
    change_count = 0
    
    for top_index in range(1,list_length):
        for i in range(top_index, list_length)[::-1]:
            if target_list[i] < target_list[i - 1] and target_list[top_index] >= target_list[i]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                
    return change_count
def solve(n, target_list):
    a = [0 for i in range(max(target_list) + 1)]
    ans = 0
    for i in range(n):
        ans += i - sum(a[:target_list[i]])
        a[target_list[i]] += 1
    return ans

if __name__ == "__main__":
    l = int(input())
    target_list = [int(i) for i in input().split()]
    print(solve(l, target_list))

### FIXED CODE ###

def bubble_sort_revision(target_list):#?????????????????????

    list_length = len(target_list)
    
    flag = True
    change_count = 0
    
    for top_index in range(1,list_length):
        for i in range(top_index, list_length)[::-1]:
            if target_list[i] < target_list[i - 1] and target_list[top_index] >= target_list[i]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                
    return change_count

def my_add(bit, i, x):
    while i <= len(bit) - 1:
        bit[i] += x
        i += int(bin(i & -i), 2)
        
def my_sum(bit, i):
    s = 0
    while i > 0:
        s += bit[i]
        i -= int(bin(i & -i), 2)
    return s

def merge(l,r):
    global count
    l_index = 0
    r_index = 0
    merge_list = []
    l.append(pow(10,9) + 1)
    r.append(pow(10,9) + 1)

    len_l = len(l) - 1
    for k in range(len(l) + len(r) - 2):
        if l[l_index] < r[r_index]:
            merge_list.append(l[l_index])
            l_index += 1
            len_l -= 1
        else:
            count += len_l
            merge_list.append(r[r_index])
            r_index += 1

    return merge_list
    
def merge_sort(target_list):
    if len(target_list) == 1:
        return target_list
    
    mid = int(len(target_list) / 2)
    
    r = merge_sort(target_list[mid:])
    l = merge_sort(target_list[:mid])
    
    return merge(l, r)

def bit_solve(n, target_list):#???????????§????????????bit?????§?????????????????????
    bit = [0 for i in range(max(target_list) + 2)]
    ans = 0
    for i in range(n):
        ans += i - my_sum(bit, target_list[i] + 1)
        my_add(bit, target_list[i] + 1, 1)
        print(ans, target_list[i], bit)
    return ans

if __name__ == "__main__":
    global count
    count = 0
    l = int(input())
    target_list = [int(i) for i in input().split()]
    merge_sort(target_list)
    print(count)
### BUGGY CODE ###

import math
K=int(input())
ans=0
if K%2==0:
    print(-1)
else:
    if K%7==0:
        K//=7
    k=1
    kk=1
    while True:
        kk*=10
        kk%=9*K
        if kk==1:
            ans=k
            break
        else:
            k+=1


    print(ans)




### FIXED CODE ###

import math
import time
start=time.time()
K=int(input())
ans=0
if K%2==0:
    print(-1)
else:
    if K%7==0:
        K//=7
    k=1
    kk=1
    while True:
        now=time.time()
        if (now-start)>1.8:
            ans=-1
            break
        kk*=10
        kk%=9*K
        if kk==1:
            ans=k
            break
        else:
            k+=1


    print(ans)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
for _ in range(Q):
    ans = 0
    l, r = map(int, input().split())
    sub = S[l - 1: r]
    print(sub.count('AC'))

### FIXED CODE ###

N, Q = map(int, input().split())
S = list(input())
cnt = [0] * (N)

for i in range(1, N):
    if S[i - 1] + S[i] == 'AC':
        cnt[i] = cnt[i - 1] + 1
    else:
        cnt[i] = cnt[i - 1]

for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)
### BUGGY CODE ###

n,m  = map(int, input().split())
broken_stairs = []
INF = 1000000007
broken_stairs = [int(input()) for i in range(m)]

dp = [0] * (n + 1)
dp[0] = 1
if 1 not in broken_stairs:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, n + 1):
	if i in broken_stairs:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF
print(dp[-1])


### FIXED CODE ###

n,m  = map(int, input().split())
INF = 1000000007
broken_stairs = set([int(input()) for i in range(m)])

dp = [0] * (n + 1)
dp[0] = 1
if 1 not in broken_stairs:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, n + 1):
	if i in broken_stairs:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF
print(dp[n])
### BUGGY CODE ###

import numpy as np

n = int(input())
s = np.array([list(input()) for _ in range(n)])

ans = 0
for i in range(n):
    t = np.append(s[i:], s[:i], axis=0)
    for j in range(n):
        u = np.append(t[:, j:], t[:, :j], axis=1)
        if np.array_equal(u, u.T):
            ans += 1
print(ans)

### FIXED CODE ###

import numpy as np
n = int(input())
S = [list(input()) for _ in range(n)]

ss = np.array(S + S)

ans = 0
for i in range(n):
    a = ss[i:i+n]
    if np.array_equal(a, a.T):
      ans += 1
print(ans * n)
### BUGGY CODE ###

N, M = map(int, input().split())
li = [[] for i in range(N+1)]
for i in range(M):
  a, b = map(int, input().split())
  li[a].append(b)
  li[b].append(a)
  
ans = 0
for i in range(1, N+1):
  l = li[i]
  for x in li[i]:
    for y in li[x]:
      if y == i:
        pass
      elif y in li[i]:
        pass
      else:
        l.append(y)
  ans = max(ans, len(set(l))+1)
print(ans)

### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]  # 親
        self.rank = [1] * n  # 木の高さ
        self.size = [1] * n  # size[i] は i を根とするグループのサイズ

    def find(self, x):  # x の根を返す
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])  # 経路圧縮
            return self.parent[x]

    def unite(self, x, y):  # x, y の属する集合を併合する
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def is_same(self, x, y):  # x, y が同じ集合に属するか判定する
        return self.find(x) == self.find(y)

    def group_size(self, x):  # x が属する集合の大きさを返す
        return self.size[self.find(x)]


N, M = map(int, input().split())
A, B = [0] * M, [0] * M  # 入力時に 0-index に合わせる

direct =[[] for _ in range(N)]  # 同じ集合の友達もしくはブロック関係の人
uf = UnionFind(N)  # 友達関係をまとめた UnionFind 木

for i in range(M):
    A[i], B[i] = map(int, input().split())
    A[i] -= 1
    B[i] -= 1
    direct[A[i]].append(B[i])
    direct[B[i]].append(A[i])
    uf.unite(A[i], B[i])

ans = [0] * N
for i in range(N):
    ans[i] = uf.group_size(i)
print(max(ans))
### BUGGY CODE ###

# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    A = LI()
    # print([bin(a) for a in A])
    mod = pow(10, 9) + 7
    ans = 0
    for i in range(0, 61):
        # i桁目が1の個数を数える
        x = 0
        for a in A:
            if (a >> i) & 1:
                x += 1
        y = n - x       # i桁目が0の個数
        # print(i, x, y)
        # XORなので x*y 通りの組み合わせ
        ans = ans + pow(2, i) * x * y % mod
    print(ans % mod)



if __name__ == '__main__':
    solve()


### FIXED CODE ###

# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    A = LI()
    # print([bin(a) for a in A])
    mod = 1000000007
    ans = 0
    for i in range(0, 61):
        # i桁目が1の個数を数える
        x = 0
        for a in A:
            if (a >> i) & 1:
                x += 1
        y = n - x       # i桁目が0の個数
        # print(i, x, y)
        # XORなので x*y 通りの組み合わせ
        ans = ans + pow(2, i) * x * y % mod
    print(ans % mod)



if __name__ == '__main__':
    solve()