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

from collections import deque
#from numba import jit

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

#@jit
def gg(nn, x, y, n, is_sit):
	q = deque()
	q.append(1000*x+y)
	cl = set()
	cl.add(x*1000+y)
	while q:
		v = q.popleft()
		x,y = v//1000, v %1000
		nn[x][y] -= 1
		k = nn[x][y]
		for dx,dy in ([-1,0], [0,-1], [1,0], [0,1]):
			if x+dx < 0 or x +dx >= n or y + dy < 0 or y + dy >= n:
				continue
			if nn[x+dx][y + dy] <= k + is_sit[x+dx][y+dy]:
				continue
			if (x+dx)*1000+(y+dy) in cl:
				continue
			q.append((x+dx)*1000+ (y+dy))
			cl.add((x+dx)*1000 + (y+dy))
		#print('yyyyyy')
		#for l in nn:
		#	print(l)

def main():
	n = int(input())
	nn = [[(n+1)//2] * n for _ in range(n)]
	is_sit = [[1] * n for _ in range(n)]
	for i in range(n):
		for j in range(n):
			nn[i][j] = min(i+1,j+1,n-i,n-j)
	#for l in nn:
	#	print(l)
	
	#b , c = tin()
	pl = lin()
	ans = 0
	for p in pl:
		x, y = (p-1) // n, (p-1) % n
		ans += nn[x][y]-1
		is_sit[x][y] = 0
		gg(nn, x, y, n, is_sit)
		
	print(ans)
	#s = input()
	
	
	
if __name__ == "__main__":
	main()

### FIXED CODE ###

import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

#+++++

def main():
	n = int(input())
	nn = [[min(i,j,n-i-1,n-j-1) for j in range(n)] for i in range(n)]
	is_sit = [[True] * n for _ in range(n)]
	cc = [[0]*n for _ in range(n)]
	
	#b , c = tin()
	pl = list(map(int, input().split()))
	ans = 0
	for p in pl:
		x, y = (p-1) // n, (p-1) % n
		ans += nn[x][y]
		is_sit[x][y] = False
		q = [(x, y, nn[x][y])]
		while q:
			(x, y, v) = q.pop()
			if x >= 0 and nn[x-1][y]>v:
				nn[x-1][y] = v
				q.append((x-1, y, v+is_sit[x-1][y]))
			if x < n-1 and nn[x+1][y]>v:
				nn[x+1][y] = v
				q.append((x+1, y, v+is_sit[x+1][y]))		
			if y >= 0 and nn[x][y-1]>v:
				nn[x][y-1] = v
				q.append((x, y-1, v+is_sit[x][y-1]))
			if y < n-1 and nn[x][y+1]>v:
				nn[x][y+1] = v
				q.append((x, y+1, v+is_sit[x][y+1]))	
		
	print(ans)
	#s = input()	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
### BUGGY CODE ###

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

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
T = sum(A)
ans = 0
for i in range(N):
  T -= A[i]
  ans += A[i] * T
  ans %= 10 ** 9 + 7
print(ans)
### BUGGY CODE ###

N,P=map(int,input().split())
S=str(input())
count=0

listS=[int(i) for i in S]
for start in range(N):
    for end in range(start,N):
        num=0
        for i in range(start,end+1):
            num+=listS[i]*(10**(end-i))   
        if num%P==0:
            count+=1
print(count)      

### FIXED CODE ###

n, p = map(int, input().split())
 
s = list(input())
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
else:
    d = [0] * (n + 1)
    ten = 1
    for i in range(n - 1, -1, -1):
        a = int(s[i]) * ten % p
        ten *= 10
        ten %= p
        d[i - 1] = (d[i] + a) % p
    cnt = [0] * p
    for i in range(n, -1, -1):
        cnt[d[i]] += 1
    for  i in cnt:
        ans+=i*(i-1)/2

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

N, A, B = map(int, input().split())
s = str(input())

passed = []

for i in range(N):
  if s[i] == "c":
    print("No")
  elif s[i] == "a" and len(passed) < A + B:
    passed.append(s[i])
    print("Yes")
  elif s[i] == "b" and len(passed) < A + B and passed.count("b") < B:
    passed.append(s[i])
    print("Yes")
  else:
    print("No")
    

### FIXED CODE ###

N, A, B = map(int, input().split())
s = str(input())

passed = []
count = 0
for i in range(N):
  if s[i] == "a" and len(passed) < A + B:
    passed.append(s[i])
    print("Yes")
  elif s[i] == "b" and len(passed) < A + B and count < B:
    passed.append(s[i])
    count += 1
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

s = list(input())

q = int(input())

for i in range(q):
    t = list(input().split())
    
    if t[0] == "1":
        s.reverse()
    else:
        f = t[1]
        c = t[2]
        if f == "1":
            s.insert(0,c)
        else:
            s.append(c)
            
for i in s:
    print(i,end = "")

### FIXED CODE ###

s = list(input())

q = int(input())

before = []

after = []

cnt = 0

for i in range(q):
    t = list(input().split())
    
    if t[0] == "1":
        cnt += 1
    else:
        f = t[1]
        c = t[2]
        if f == "1":
            if cnt%2 == 0:
                before.append(c)                      
            else:
                after.append(c)
        else:
            if cnt%2 == 0:
                after.append(c)
            else:
                before.append(c)
                
if cnt%2 == 1:
    s.reverse()
    after.reverse()
    #before.reverse()
    for i in after:
        print(i,end = "")
    for i in s:
        print(i,end = "")
    for i in before:
        print(i,end = "")
else:
    before.reverse()
    before.extend(s)
    before.extend(after)
            
    for i in before:
        print(i,end = "")
### BUGGY CODE ###

N,A = map(int,input().split())
X = list(map(int,input().split()))
 
dp = [[[0 for k in range(2501)] for j in range(N+1)] for i in range(N+1)]
 
for i in range(1,N+1):
    x = X[i-1]
    dp[i][1][x] += 1
    for j in range(1,i+1):
        for k in range(1,2501):
            if k-x > 0:
                dp[i][j][k] += dp[i-1][j-1][k-x] + dp[i-1][j][k]
            else:
                dp[i][j][k] += dp[i-1][j][k]
 
ans = 0
 
for j in range(1,N+1):
    ans += dp[N][j][j*A]
print(ans)

### FIXED CODE ###

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

dp = [[[0 for k in range(2501)] for j in range(N+1)] for i in range(N+1)]

for i in range(1,N+1):
    x = X[i-1]
    dp[i][1][x] += 1
    for j in range(1,i+1):
        for k in range(1,2501):
            if k-x > 0:
                dp[i][j][k] += dp[i-1][j-1][k-x] + dp[i-1][j][k]
            else:
                dp[i][j][k] += dp[i-1][j][k]

ans = 0

for j in range(1,N+1):
    ans += dp[N][j][j*A]
print(ans)
### BUGGY CODE ###

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

d = [a[i][:] for i in range(n)]
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][j],d[i][k] + d[k][j])

ans = 0
for i in range(n):
    for j in range(n):
        if a[i][j] > d[i][j]:
            ans = -2
            break
        for k in range(n):
            if i == k or j == k: continue
            if d[i][j] == d[i][k] + d[k][j]: break
        else:
            ans += d[i][j]
    else:
        continue
    break

ans //= 2
print(ans)

### FIXED CODE ###

n = int(input())
a = [[int(i) for i in input().split()] for _ in range(n)]
ans = 0
b = [i[:] for i in a[:]]

for k in range(n):
    for i in range(n):
        for j in range(n):
            b[i][j] = min(b[i][j],b[i][k]+b[k][j])

flag = False
for i in range(n):
    for j in range(n):
        if b[i][j] < a[i][j]:
            ans = -1
            flag = True
            break
        if b[i][j] == a[i][j]:
            for k in range(n):
                if k == i or k == j: continue
                if b[i][j] == b[i][k] + b[k][j]: break
            else:
                ans += b[i][j]
    if flag: break

ans //= 2
print(ans)
### BUGGY CODE ###

import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

N, K = LI()
S = SI().strip()

searching = 1
count = [0]
head = 0
for i in range(N):
    if int(S[i]) == searching:
        count[head] += 1
    else:
        searching = (searching+1)%2
        head += 1
        count.append(1)
if len(count)//2 <= K:
    print(N)
    sys.exit()

count.append(0)

max_length = 0
for k in range(N):
    if 2*k+2*K+1 > N: break
    max_length = max(sum(count[2*k:2*k+2*K+1]), max_length)
print(max_length)


### FIXED CODE ###

import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

def main():
    N, K = LI()
    S = SI().strip()

    searching = 1
    count = [0]
    head = 0
    for i in range(N):
        if int(S[i]) == searching:
            count[head] += 1
        else:
            searching = (searching+1)%2
            head += 1
            count.append(1)
    if len(count)//2 <= K:
        print(N)
        sys.exit()

    count.append(0)

    current_sum = sum(count[0:2*K+1])
    max_length = current_sum
    try:
        for k in range(1, N):
            if 2*k+2*K > len(count): break
            current_sum = current_sum - count[2*k-2] - count[2*k-1] + count[2*k+2*K-1] + count[2*k+2*K]
            max_length = max(current_sum, max_length)
    except:
        pass
    print(max_length)

main()
### BUGGY CODE ###

K = int(input())
p = [1,2,3,4,5,6,7,8,9]
q = 1
t = 10
r = 0
while t <= 3234566667 and len(p) < K+1:
        q = 1
        r = 0
        a = list(str(t))
        for i in range(len(a)):
            a[i] = int(a[i])
        while r < len(a)-1:
            if abs(a[r] - a[r+1]) <= 1:
                q = q*1
                r = r + 1
            else:
                q = q*0
                if a[r] < a[r+1]:
                    a[r] = a[r] + 1
                    for i in range(r+1,len(a)):
                        a[i] = 0
                    Tlist = ''.join(map(str, a))
                    t = int(Tlist)
                    break 
                else:
                    t = t + 1
                    r = r + 1
        if q == 1:
            p.append(t)
            t = t + 1
print(p[K-1])

### FIXED CODE ###

K = int(input())
from collections import deque
p = deque()
for i in range(1,10):
    p.append(i)
for i in range(K):
    if p[0] % 10 != 0:
        p.append(10*p[0]+p[0]%10-1)
    p.append(10*p[0]+p[0]%10)
    if p[0] % 10 != 9:
        p.append(10*p[0]+p[0]%10+1)
    q = p[0]
    p.popleft()
print(q)
### BUGGY CODE ###

import collections

N = int(input())
S = list(input() for i in range(N))
dict = {}

for l in S:
        if l in dict:
            dict[l] += 1;
        else:
            dict[l] = 1;

max_k_list = [kv[0] for kv in dict.items() if kv[1] == max(dict.values())]

max_k_list.sort()

for i in max_k_list:
    print(i)


### FIXED CODE ###

import collections

N = int(input())
S = list(input() for i in range(N))
dict = {}

for l in S:
        if l in dict:
            dict[l] += 1;
        else:
            dict[l] = 1;
            
max = max(dict.values())

max_k_list = [kv[0] for kv in dict.items() if kv[1] == max]

max_k_list.sort()

for i in max_k_list:
    print(i)
### BUGGY CODE ###


from math import floor

def parse():
  return map(int, input().split(" "))

def main():
  A, B, N = parse()

  limit_N = 10000000
  N = limit_N if N > limit_N else N

  x = 0
  max_val = floor((A * x) / B) - A * floor(x / B)

  for x in range(1, N + 1):
    val = floor((A * x) / B) - A * floor(x / B)
    if max_val < val:
      max_val = val

  print(max_val)

if __name__ == "__main__":
  main()

### FIXED CODE ###


from math import floor

def parse():
  return map(int, input().split(" "))

def main():
  A, B, N = parse()
  
  x = B - 1 if B - 1 <= N else N
  print(floor((A * x) / B) - A * floor(x / B))
  exit(0)

  limit_N = 5000000
  N = limit_N if N > limit_N else N

  x = 0
  max_val = floor((A * x) / B) - A * floor(x / B)

  for x in range(1, N + 1):
    val = floor((A * x) / B) - A * floor(x / B)
    if max_val < val:
      max_val = val

  print(max_val)


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

A, B, C = map(int, input().split())

def intSqrt(n):
    M = int(n**0.5)

    while (M + 1)**2 <= n:
        M += 1

    for _ in range(10000):
        n *= 100
        M *= 10
        for add in range(0, 10)[:: -1]:
            if (M + add) * (M + add) <= n:
                M += add
                break

    return M

if intSqrt(A) + intSqrt(B) < intSqrt(C):
    print('Yes')
else:
    print('No')


### FIXED CODE ###

A, B, C = map(int, input().split())

def intSqrt(n):
    M = int(n**0.5)

    while (M + 1)**2 <= n:
        M += 1

    for _ in range(300):
        n *= 100
        M *= 10
        for add in range(0, 10)[:: -1]:
            if (M + add)**2 <= n:
                M += add
                break

    return M

A, B, C = intSqrt(A), intSqrt(B), intSqrt(C)

if abs(A + B - C) < 10 or A + B >= C:
    print('No')
else:
    print('Yes')
### BUGGY CODE ###

X, Y, A, B, C=map(int,input().split())
rp=list(map(int,input().split()))
bp=list(map(int,input().split()))
np=list(map(int,input().split()))
rp.sort()
bp.sort()
np.sort()
count=X+Y
red=X
blue=Y
N=0
ans =0

for k in range(count):
    if red == 0:
        if np[-1] >= bp[-1]:
            ans += np[-1]
            np = np[:-1]
        else:
            ans+=bp[-1]
            bp=bp[:-1]
    elif blue == 0:
        if np[-1] >= rp[-1]:
            ans += np[-1]
            np = np[:-1]
        else:
            ans+=rp[-1]
            rp=rp[:-1]        
    elif len(np) >0:
        s = np[-1]
        if s >= rp[-1] and s >= bp[-1]:
            ans+=s
            np = np[:-1]
        else:
            if red >0:
                if blue>0:
                    if rp[-1] >= bp[-1]:
                        ans += rp[-1]
                        rp = rp[:-1]
                        red-=1
                    else:
                        ans+=bp[-1]
                        bp=bp[:-1]
                        blue-=1
                else:
                    ans += rp[-1]
                    rp = rp[:-1]
                    red-=1

            else:
                ans += bp[-1]
                bp=bp[:-1]
                blue-=-1
    elif rp[-1] >= bp[-1]:
        ans += rp[-1]
        rp = rp[:-1]
        red-=1
    else:
        ans+=bp[-1]
        bp=bp[:-1]
        blue-=1
            
print(ans)

### FIXED CODE ###

X, Y, A, B, C=map(int,input().split())
rp=list(map(int,input().split()))
bp=list(map(int,input().split()))
np=list(map(int,input().split()))
rp.sort()
bp.sort()
np.sort()
count=X+Y
red=len(rp)-1
blue=len(bp)-1
non=len(np)-1
lb = blue-Y
lr = red -X
N=0
ans =0

for k in range(count):
    if non > -1:
        nn= np[non]
    else:
        nn =0
    if blue > lb:
        bb= bp[blue]
    else:
        bb =0
    if red > lr:
        rr= rp[red]
    else:
        rr =0
    
    if red == lr:
        if bb >= nn or non ==-1:
            ans+=bb
            blue-=1        
        else:
            ans += nn
            non-=1

    elif blue == lb:
        if rr >= nn or non ==-1:
            ans+=rr
            red-=1        
        else:
            ans += nn
            non-=1
       
    elif non > -1:
        if nn >= rr and nn >= bb:
            ans+=nn
            non-=1
        else:
            if red > lr:
                if blue> lb:
                    if rr >= bb:
                        ans += rr
                        red-=1
                    else:
                        ans+=bb
                        blue-=1
                else:
                    ans += rr
                    red-=1

            else:
                ans += bb
                blue-=1
    elif rr >= bb:
        ans += rr
        red-=1
    else:
        ans+=bb
        blue-=1
            
print(ans)
### BUGGY CODE ###

import sys
from itertools import product

def main():
    input = sys.stdin.readline
    X, Y, Z, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    A = sorted(A, key=lambda x: -x) + [-10**9]
    B = sorted(B, key=lambda x: -x) + [-10**9]
    C = sorted(C, key=lambda x: -x) + [-10**9]

    AB = []
    for x in product(A, B):
        AB.append(sum(x))

    AB = sorted(AB, key=lambda x: -x)
    AB = AB[:K]

    ABC = []
    for x in product(AB, C):
        ABC.append(sum(x))

    ABC = sorted(ABC, key=lambda x: -x)
    for i in range(K):
        print(ABC[i])


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from heapq import heappush, heappop

def main():
    input = sys.stdin.readline
    X, Y, Z, K = map(int, input().split())
    A = sorted(list(map(int, input().split())), key=lambda x: -x)
    B = sorted(list(map(int, input().split())), key=lambda x: -x)
    C = sorted(list(map(int, input().split())), key=lambda x: -x)

    deli = []
    heappush(deli, (-A[0]-B[0]-C[0], 0, 0, 0))
    pushed = set((0,0,0))
    for _ in range(K):
        d = heappop(deli)
        i, j, k = d[1], d[2], d[3]

        if i+1 < X and (i+1, j, k) not in pushed:
            heappush(deli, (-A[i+1]-B[j]-C[k], i+1, j, k))
            pushed.add((i+1, j, k))

        if j+1 < Y and (i, j+1, k) not in pushed:
            heappush(deli, (-A[i]-B[j+1]-C[k], i, j+1, k))
            pushed.add((i, j+1, k))

        if k+1 < Z and (i, j, k+1) not in pushed:
            heappush(deli, (-A[i]-B[j]-C[k+1], i, j, k+1))
            pushed.add((i, j, k+1))

        print(-d[0])


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

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

out = [0] * N

for i in range(N) :
    ans = A[i]
    sig = i % 2

    # 前半
    for j in range(0,i) :
        ans += (-1)**(j+sig) * A[j]

    # 後半
    for j in range(i+1,N) :
        ans += (-1)**(j+sig+1) * A[j]
    out[i] = ans

print('{} '.format(out[-1]), end='')
out.pop()

for o in out :
    print('{} '.format(o), end='')

print('')

### FIXED CODE ###

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

ss = 0
for i in range(N) :
    ss += (-1)**i * A[i]

ans = []

for i in range(N) :
    ss = -ss + 2*A[i]
    ans.append(ss)

print('{} '.format(ans[-1]), end='')
ans.pop()

for a in ans :
    print('{} '.format(a), end='')
print('')
### BUGGY CODE ###

import numpy as np
N = int(input())
X = list(map(int, input().split()))
for i in range(N):
    tmp = np.array(X[:i]+X[i+1:])
    med = np.median(tmp)
    print(int(med))

### FIXED CODE ###

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

for i in range(N):
    ans = 0
    if X[i] <= Y[N//2-1]:
        ans = Y[N//2]
    else:
        ans = Y[N//2-1]
    print(ans)
### BUGGY CODE ###

import numpy as np
s=list(input())
n=len(s)
dp=np.zeros((n+1,13),np.int64)
mod=pow(10,9)+7
if s[-1]=='?':
  dp[1][:10]=1
else:
  dp[1][int(s[-1])]=1
for i in range(2,n+1):
  if s[-i]=='?':
    for j in range(10):
      a=(j*pow(10,i-1,13))%13
      if a==0:
        dp[i]+=dp[i-1]
      else:
        dp[i][a:]+=dp[i-1][:-a]
        dp[i][:a]+=dp[i-1][-a:]
  else:
    j=int(s[-i])
    a=(j*pow(10,i-1,13))%13
    if a==0:
      dp[i]+=dp[i-1]
    else:
      dp[i][a:]+=dp[i-1][:-a]
      dp[i][:a]+=dp[i-1][-a:]
  dp[i]%=mod
print(dp[n][5])
#print(dp)

### FIXED CODE ###

def main():
  s=list(input())
  n=len(s)
  dp=[0]*13
  mod=pow(10,9)+7
  if s[-1]=='?':
    dp=[1]*10+[0]*3
  else:
    dp[int(s[-1])]=1
  p_dp=[0]*13
  for i in range(2,n+1):
    if s[-i]=='?':
      for j in range(10):
        a=(j*pow(10,i-1,13))%13
        for k in range(13):
          p_dp[(a+k)%13]+=dp[k]
    else:
      j=int(s[-i])
      a=(j*pow(10,i-1,13))%13
      for k in range(13):
        p_dp[(a+k)%13]+=dp[k]
    
    for k in range(13):
      p_dp[k]%=mod
    dp=[k for k in p_dp]
    p_dp=[0]*13
  print(dp[5])

if __name__=='__main__':
  #import datetime
  #print(datetime.datetime.now())
  main()
  #print(datetime.datetime.now())
### BUGGY CODE ###

n = int(input())
ans = 0
for i in range(1, n):
	ans += i

print(ans)


### FIXED CODE ###

n = int(input())
print((n-1)*n//2)
### BUGGY CODE ###

a=int(input())
b=list(map(int,input().split()))
c=b.copy()
d=0
e=[]
for m in range(a):
    tmp=0
    d+=1
    for n,i in enumerate(b):
        if d==i:
            try:
                c.remove(i)
                tmp+=1
            except ValueError:
                break
    e.append(str(tmp))

f='\n'.join(e)
print(f)


### FIXED CODE ###

a=int(input())
b=list(map(int,input().split()))
d=0
e=[0 for i in range(a)]


for i in range(len(b)):
    e[b[i]-1]+=1

for j in e:
    print(str(j))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
N,M = map(int,input().split())
G = [[] for _ in range(N)]

for _ in range(M):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    G[x].append(y)
    G[y].append(x)

seen = [False]*(N)
ans = 0
def dfs(v):
    if seen[v]:
        return
    seen[v] = True
    for nv in G[v]:
        dfs(nv)

for v in range(N):
    if not seen[v]:
        dfs(v)
        ans += 1
print(ans)

### FIXED CODE ###

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

par = [-1]*(N+1)


def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True


def same(x,y):
    return find(x) == find(y)


def size(x):
    return -par[find(x)]

for i in range(M):
    x,y,z = map(int,input().split())
    unite(x,y)

ans = 0
counted = [False] * (N+1)
for i in range(1,N+1):
    root = find(i)
    if not counted[root]:
        ans += 1
        counted[root] = True
print(ans)
### BUGGY CODE ###

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

dp = [[0]*(M+1) for i in range(N+1)]
for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            dp[n+1][m+1] = dp[n+1][m]+dp[n][m+1]+1
        else:
            dp[n+1][m+1] = dp[n+1][m]+dp[n][m+1]-dp[n][m]
        dp[n+1][m+1] %= mod

print(dp[-1][-1]+1)


### FIXED CODE ###

n,m = map(int,input().split())
s = list(map(int,input().split()))
t = list(map(int,input().split()))
dp0 = [[0 for i in range(m+2)] for j in range(n+2)]
dp1 = [[0 for i in range(m+2)] for j in range(n+2)]
dp0[0][0] = 1
mod = 10**9+7
for i in range(n+1):
    for j in range(m+1):
        dp0[i+1][j] = (dp0[i+1][j]+dp0[i][j])%mod
        dp1[i][j] = (dp1[i][j]+dp0[i][j])%mod
        dp1[i][j+1] = (dp1[i][j+1]+dp1[i][j])%mod
        if i != n and j != m and s[i] == t[j]:
            dp0[i+1][j+1] = (dp1[i+1][j+1]+dp1[i][j])%mod
print(dp1[n][m])
### BUGGY CODE ###

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

b = [0] * 65

for i in range(N):
    bb = format(A[i], "060b")
    for j in range(60):
        if bb[j] == "1":
            b[j] += 1

ans = 0

for j in range(60):
    ans = (ans + b[j] * (N - b[j]) * pow(2, 59 - j, mod)) % mod

print(ans)

### FIXED CODE ###

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

b = [0] * 65

for i in range(N):
    bb = format(A[i], "060b")
    for j in range(60):
        if bb[j] == "1":
            b[j] += 1

ans = 0

for j in range(60):
    ans = (ans + b[j] * (N - b[j]) * pow(2, 59 - j, mod)) % mod

print(ans)