Harryxun/stf_run huggingface dataset:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    memo={}
    def win(a,b):
        if a>b:a,b=b,a
        if (a,b)==(0,0) or (a,b)==(0,1) or (a,b)==(1,1):return False
        if (a,b) in memo:return memo[a,b]
        for i in range(1,a):
            r=a-i*2
            if r<0:break
            if not win(r,b+i):
                memo[a,b]=True
                return True
        for i in range(1,b):
            r=b-i*2
            if r<0:break
            if not win(r,a+i):
                memo[a,b]=True
                return True
        memo[a, b] = False
        return False

    x,y=MI()
    if win(x,y):print("Alice")
    else:print("Brown")

main()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
def MI(): return map(int, sys.stdin.readline().split())

def main():
    x,y=MI()
    if x>y:x,y=y,x
    if y>x+1:print("Alice")
    else:print("Brown")

main()
N=int(input())
A=[int(X) for X in input().split()]
B=[]
for i in range(N):
  B +=[A[i]-1-i]
B = sorted(B)
p=N//2
answer=float('inf')
for i in range(B[p-1],B[p+2]):
  a=0
  for j in range(N):
    a+=abs(B[j]-i)
  answer=min(answer,a)
print(answer if answer!=float('inf') else 0)

### FIXED CODE ###

import numpy as np
N=int(input())
A=[int(X) for X in input().split()]
B=[]
for i in range(N):
  B +=[A[i]-1-i]
B = np.array(sorted(B))
x = B[N//2]
answer = np.abs(B-x).sum()
print(answer)
N = int(input())
H = list(map(int, input().split()))
ans = "Yes"
for i in range(N - 1):
  if H[i] > H[i + 1]:
    H[i] = H[i] - 1
    if H[i] - 1 > H[i + 1]:
      ans = "No"
    else:
      H[i] = H[i] - 1

if sorted(H) != H:
  ans = "No"
print(ans)

### FIXED CODE ###

A, B, C = map(int, input().split())
emp = A - B
ans = C - emp
if ans < 0:
  ans = 0
print(ans)
row = int(input())
item_list = [input() for i in range(row)]
result_list = []
for j in item_list:
  exist_in_item_list = False
  for k in result_list.len():
    if result_list[k] == item_list[j]:
      exist_in_item_list = True
      break
  result_list.append(item_list[j])

print(result_list.len())


### FIXED CODE ###

row = int(input())
item_list = [input() for i in range(row)]
print(len(set(item_list)))
N = input()
print(f'ABC{N}')

### FIXED CODE ###

N = input()
print('ABC'+ N)
from collections import deque
H, W = map(int, input().split())
G = [list(input()) for i in range(H)]  # 迷路
D = [[-1] * W for i in range(W)]  # 最短距離
D[0][0] = 0

Black = 0  # 最初の盤面の黒の数
for g in G:
    Black += g.count('#')

# BFS
que = deque([[0, 0]])
direction = [(1, 0), (-1, 0), (0, 1), (0, -1)]
while que:
    nh, nw = que.pop()
    for dh, dw in direction:
        if not ((0 <= nh + dh < H) and (0 <= nw + dw < W)):
            continue

        if D[nh + dh][nw + dw] > 0:
            continue

        if G[nh + dh][nw + dw] == '#':
            continue

        D[nh + dh][nw + dw] = D[nh][nw] + 1
        que.appendleft([nh + dh, nw + dw])

if D[H - 1][W - 1]:
    print(H * W - D[H - 1][W - 1] - Black - 1)
else:
    print(-1)


### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
Field = [list(input()) for i in range(H)]

que = deque()
que.append([0, 0])
Field[0][0] = 0

while que:
    now = que.popleft()
    if now == [H-1, W-1]:
        break

    if now[0]+1 <= H -1:
        if Field[now[0]+1][now[1]] == ".":
            Field[now[0]+1][now[1]] = str(int(Field[now[0]][now[1]])+1)
            que.append([now[0]+1, now[1]])

    if now[0]-1 >= 0:
        if Field[now[0]-1][now[1]] == ".":
            Field[now[0]-1][now[1]] = str(int(Field[now[0]][now[1]])+1)
            que.append([now[0]-1, now[1]])

    if now[1] + 1 <= W -1:
        if Field[now[0]][now[1]+1] == ".":
            Field[now[0]][now[1]+1] = str(int(Field[now[0]][now[1]])+1)
            que.append([now[0], now[1]+1])

    if now[1] -1 >= 0:
        if Field[now[0]][now[1]-1] == ".":
            Field[now[0]][now[1]-1] = str(int(Field[now[0]][now[1]])+1)
            que.append([now[0], now[1]-1])
else:
    print(-1)
    exit()
Z = int(Field[H-1][W-1])

sharp_cnt = 0
for f in Field:
    sharp_cnt += f.count("#")

print(H*W - sharp_cnt - Z - 1)
n = int(n)
seq = [int(x) for x in input().split()]
d = round(sum(seq) / len(seq))
print(sum([(x-d)**2 for x in seq]))


### FIXED CODE ###

n = int(input())
seq = [int(x) for x in input().split()]
d = round(sum(seq) / len(seq))
print(sum([(x-d)**2 for x in seq]))
N, K = map(int, input().split())
P = list(map(lambda s: int(s) - 1, input().split()))
C = list(map(int, input().split()))

visited = [False] * N
ans = []
for i in range(N):
    if visited[i]:
        continue
    visited[i] = True
    S = [C[i]]
    p = P[i]
    while p != i:
        visited[p] = True
        S.append(C[p])
        p = P[p]
    s = sum(S)
    n = len(S)
    SS = S + S
    if s <= 0 or K < n:
        a = max(sum(SS[j:j + c + 1])
                for j in range(n) for c in range(min(K, n)))
    else:
        M = max(sum(SS[j:j + c + 1]) for j in range(n) for c in range(K % n))
        a = s * (K // n) + M
    ans.append(a)

print(max(ans))


### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(lambda s: int(s) - 1, input().split()))
C = list(map(int, input().split()))

ans = -1_000_000_000
for i in range(N):
    S = [C[i]]
    p = P[i]
    while p != i:
        S.append(C[p])
        p = P[p]
    s = sum(S)
    n = len(S)
    acc = 0
    for i in range(min(n, K + 2)):
        acc += S[i]
        a = acc
        if s > 0:
            a += s * ((K - (i + 1)) // n)
        ans = max(a, ans)

print(ans)
# -*- coding:utf-8 -*-

n = int(input())
ans = []

for i in range(n):
    command = input().split()
    if command[0] == "insert":
        ans.insert(0, command[1])
    elif command[0] == "delete":
        ans.remove(command[1])
    elif command[0] == "deleteFirst":
        ans.pop(0)
    else:
        ans.pop()

print (' '.join(ans))

### FIXED CODE ###

# -*- coding:utf-8 -*-
import collections
n = int(input())
ans = collections.deque()

for i in range(n):
    command = input().split()
    if command[0] == "insert":
        ans.appendleft(command[1])
    elif ans == []:
        continue
    elif command[0] == "delete":
        try:
            ans.remove(command[1])
        except:
            pass
    elif command[0] == "deleteFirst":
        ans.popleft()
    else:
        ans.pop()

print (' '.join(ans))
a,b=map(int,input().split())
print((a+b+1)/2))


### FIXED CODE ###

a,b=map(int,input().split())
print((a+b+1)//2)
n,k = map(int,input().split())
s = input()

print(s[:k-1]+s.upper[k-1]+s[k:])

### FIXED CODE ###

_, K = map(int, input().split())
S = input()
 
print(S[: K - 1] + S[K - 1].lower() + S[K:])
while True:
   x,y = map(int, input().split())
   if x == 0 and y == 0:
      break
   if x >= y:
      print '%s %s' % (y, x)
   else:
      print '%s %s' % (x, y)

### FIXED CODE ###

while True:
   x,y = map(int, raw_input().split())
   if x == 0 and y == 0:
      break
   if x >= y:
      print '%s %s' % (y, x)
   else:
      print '%s %s' % (x, y)
s,t = input().sprit()
i=int(input())
a=0
if s[i]=t[i]:
    a=a+1
else:
    a=a+0
print(a)

### FIXED CODE ###

s,t = input(), input()
a = 0
for i in range(len(s)):
    if s[i]!=t[i]:
        a = a + 1
print(a)
import numpy as np
import math

N = int(input())
A = input().split(' ')

an = np.array(A, dtype=np.int64)

M = 0
b = []

for i in range(1,N):
   chk_num = int(N/(i))

   if(chk_num<2):
      continue

   ball = 0
   for j in range(1,chk_num):
      c = i * j
      ball += an[j]
   M += 1
   b.append((ball+1)%2)


print(M)
print(*b)


### FIXED CODE ###

r = int(input())

s = 3*r*r

print(s)
import sys

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

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        if a[i]%mm==0:
            icnt+=a[i]//mm
        else:
            icnt+=a[i]//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:
    if um-lm<5:
        break

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)



### FIXED CODE ###

import sys

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

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)
n,m = map(int,input().split( ))
ls_a = []
ls_b = [[] for i in range(n)]
for i in range(m):
    p,y = map(int,input().split( ))
    ls_a.append([p,y])
    ls_b[p-1].append(y)
for i in range(n):
    if len(a[i]) !=0:
        ls_b[i].sort()
for i in range(m):
    print(str(ls_a[i][0]).zfill(6) + str(ls_b[ls_a[i][0]-1].index(ls_a[i][1])+1).zfill(6))

### FIXED CODE ###

N,M=map(int,input().split())
PY=[list(map(int,input().split()))+[i] for i in range(M)] #定義終了
 
PY.sort(key= lambda x:x[1])
num=[0]*N
w=[""]*M
 
for p,y,i in PY:
	num[p-1]+=1
	w[i]=str(p).zfill(6)+str(num[p-1]).zfill(6)

for i in range(M):
  	print(w[i])
#-*- coding:utf-8 -*-

n, k, q = map(int, input().split())
a_li = [int(input()) for i in range(q)]

pt_li = [] 
for i in range(n):
    pt_li.append(k)

for t in range(q):
    for u in range(n):
        pt_li[u] -= 1
    pt_li[a_li[t]-1] += 1

for s in range(n):
     if pt_li[s] <= 0:
         print("No")
     else:
         print("Yes")

### FIXED CODE ###

# -*- coding:utf-8 -*-

S = input()

if S == "Sunny":
    print("Cloudy")
elif S == "Cloudy":
    print("Rainy")
else:
    print("Sunny")
import math

numofpoints= int(raw_input())
coords=[]
for index in range(numofpoints):
	x,y= map(int, raw_input.split())
    coords.append((x,y))
    
def factorial(n):
  	if n==0:
      return 1
    else:
		return n*factorial(n-1)

ave=0
c=0
for i in range(numofpoints):
  xi=coords[i][0]
  yi=coords[i][0]
	for j in range(i,numofpoints):
    	xj=coords[j][0]
  		yj=coords[j][0]
        	rij = ((xi-xj)**2 + (yi-yj)**2)**0.5
        ave = ave + rij
print sumofnum/math.factorial(numofpoints)



### FIXED CODE ###

print(input()**2)
[H, N] = [int(x) for x in input().split()]
A = list(map(int, input().split()))
count = 0

arr = sorted(A, reverse=True)
while N > 0:
    arr.pop(0)
    N -= 1
    if N == 0:
        break
for x in arr:
    count += x

print(count)

### FIXED CODE ###

N, K = map(int, input().split())
H = map(int,input().split())
print(sum(sorted(H, reverse=True)[K::]))
def dfs(tree, count, p):
    for i in tree[p]:
        count[i] += count[p]
        dfs(tree, count, i)


def find_root(inv):
    return [k for k in inv if len(inv[k]) == 0][0]


def main():
    N, Q = map(int, input().split())
    tree = {i+1: [] for i in range(N)}
    inv = {i+1: [] for i in range(N)}
    count = {i+1: 0 for i in range(N)}

    for _ in range(N-1):
        a, b = map(int, input().split())
        tree[a].append(b)
        inv[b].append(a)

    for _ in range(Q):
        p, x = map(int, input().split())
        count[p] += x

    dfs(tree, count, find_root(inv))

    print(" ".join(map(str, sorted(count.values()))))


if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import defaultdict, deque


def main():
    N, Q = map(int, input().split())

    tree = defaultdict(list)
    counter = defaultdict(int)
    for _ in range(N-1):
        a, b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)
    for _ in range(Q):
        p, x = map(int, input().split())
        counter[p] += x

    # bfs
    q = deque([1])
    visited = {1}

    while q:
        i = q.popleft()

        for j in tree[i]:
            if j not in visited:
                q.append(j)
                counter[j] += counter[i]
                visited.add(j)

    counts = [counter[i] for i in range(1, N+1)]
    ans = " ".join(map(str, counts))
    print(ans)



if __name__ == '__main__':
    main()
x = nums =0
 dic = {'I': 1, 'D': -1}
 for i in s:
     x += dic[i]
     nums = max(x, nums)
print(nums)

### FIXED CODE ###

x = 0
max_value = [0]

n = int(input())
s = input()

list = [i for i in s]

for j in list:
    if j == 'I':
        x += 1
        max_value.append(x)
    else:
        x -= 1
        max_value.append(x)
print(max(max_value))
import math
ans=0
A=[int(input()) for i in range(5)]
a=0
for i in range(5):
  if (A[i]%10)>a:
    p=i
    a=A[i]
for i in range(5):
  if i==p:
    ans+=A[i]
  else:
    ans+=10*(math.ceil(A[i]/10))
print(ans)

### FIXED CODE ###

import math
ans=0
A=[int(input()) for i in range(5)]
a=10
p=0
for i in range(5):
  if a>(A[i]%10) and A[i]%10!=0:
    p=i
    a=A[i]%10
for i in range(5):
  if i==p:
    ans+=A[i]
  else:
    ans+=10*(math.ceil(A[i]/10))
print(ans)
n = int(input())
a = list(map(int, input().split()))

odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        even.append(a[i])
    else:
        odd.append(a[i])

if n % 2 == 1:
    print(*even[::-1], *odd)
else:
    print(*odd[::-1], *even)

### FIXED CODE ###

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

odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        even.append(a[i])
    else:
        odd.append(a[i])

if n % 2 == 1:
    ans = even[::-1]+odd
else:
    ans = odd[::-1]+even
print(*ans)
x,a = map(int(input()).split())
if x<a:
  print(0)
else:
  print(10)

### FIXED CODE ###

x,a = map(int,input().split())
if x<a:
  print(0)
else:
  print(10)
r = int(input())
l = pi * 2 * r
print(l)

### FIXED CODE ###

import math
r = int(input())
l = math.pi * 2 * r
print(l)
A,B,C,D=map(int,input().split())
lcm=int(C*D/math.gcd(C,D))

if B//lcm==0:
    num_CD=0
else:
    num_CD=B//lcm-math.ceil(A/lcm)+1


if B//C==0:
    num_C=0
else:
    num_C=B//C-math.ceil(A/C)+1



if B//D==0:
    num_D=0
else:
    num_D=B//D-math.ceil(A/D)+1


ans=B-A+1-num_C-num_D+num_CD


print(int(ans))

### FIXED CODE ###

import fractions

A,B,C,D=map(int,input().split())
lcm=int(C*D/(fractions.gcd(C,D)))

if B//lcm==0:
    num_CD=0
else:
    num_CD=B//lcm-(A-1)//lcm


if B//C==0:
    num_C=0
else:
    num_C=B//C-(A-1)//C



if B//D==0:
    num_D=0
else:
    num_D=B//D-(A-1)//D


ans=B-A+1-num_C-num_D+num_CD


print(int(ans))
l = ['%d%d'%(i, i) for i in range(10)]
S = input()
if S.count(l) > 0:
    print('Bad')
else:
    print('Good')

### FIXED CODE ###

l = ['%d%d'%(i, i) for i in range(10)]
S = input()
if sum([S.count(i) for i in l]) > 0:
    print('Bad')
else:
    print('Good')
N=int(input())
sen = N / 1000:
 
for N in 10000:
  if N % 1000 == 0：
  print(0)
else:
  atai = N - sen
  print(sen + atai )

### FIXED CODE ###

#! /usr/bin/python3

N = int(input())
1 <= N <= 10000

if N % 1000 == 0:
 print(0)
else:
  sen = N//1000
  sen2 = sen*1000
  atai = N-sen2
  atai2 = 1000-atai
  print(atai2)
A,B = (int(i) for i in input().split)
a = max(A,B)
b = min(A,B)
t = a - b
if t <= 1:
  print(a + a - 1)
else:
  print(a + b)



### FIXED CODE ###

A,B = map(int,input().split())
a = max(A,B)
b = min(A,B)
t = a - b
if t <= 1:
  print(a + b)
else:
  print(a + a - 1)
N = input()
h = map(int,input().split())
h = list(h)

dp = [99999999 for i in range(100)]
dp[0]=0

for i in range(int(N)):
    for j in [i+1,i+2]:
        if j<int(N) :
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[int(N)-1])

### FIXED CODE ###

import sys
n =int(input())
h = map(int,input().split())
h = list(h)

dp = [sys.maxsize]*n
dp[0]=0

for i in range(n):
    for j in range(i+1,i+2+1):
        if j<n :
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[n-1])
N,u,v = map(int,input().split())
u -= 1
v -= 1

du = [0]*N
dv = [0]*N
du[u] = 0
dv[v] = 0
G = [[]]*N

def dfs(v, d, p, dis):
    dis[v] = d
    if G[v] != 0:
        for u in G[v]:
            if( u == p):
                continue
            else:
                dfs( u, d+1, v, dis )

def calcDist(s, dist):
    dfs(s, 0, -1, dist)

for i in range(N-1):
    e1,e2 = map(int, input().split())
    e1 -= 1
    e2 -= 1
    if G[e1] == []:
        G[e1] = [e2]
    else:
        G[e1].append(e2)
    if G[e2] == []:
        G[e2] = [e1]
    else:
        G[e2].append(e1)

if G[u]==[v]:
    ans = 0
else:    

    calcDist(v,dv)
    calcDist(u,du)
    maxD = 0
    for idu,idv in zip(du,dv):
        if idu < idv:
            maxD = max(maxD, idv)       
    ans = maxD-1
    
print(ans)

### FIXED CODE ###

import heapq

N,u,v = map(int,input().split())
u -= 1
v -= 1

#du = [0]*N
#dv = [0]*N
du = [float('inf')]*N
dv = [float('inf')]*N
#du[u] = 0
#dv[v] = 0
q = []

G = [[]]*N

'''
def dfs(v, d, p, dis):
    dis[v] = d
    if G[v] != []:
        for u in G[v]:
            if( u == p):
                continue
            else:
                dfs( u, d+1, v, dis )

def calcDist(s, dist):
    dfs(s, 0, -1, dist)
'''
def calcDist(s, dist):
    heapq.heappush(q,[0, s])
    dist[s] = int(0)
    
    while q!=[]:
        p = heapq.heappop(q)
        pv = p[1]
        if dist[pv] < p[0] :
            continue
        for i in range(len(G[pv])):
            eto = G[pv][i]
            if dist[eto] > dist[pv] + 1:
                 dist[eto] = int(dist[pv] + 1)
                 heapq.heappush(q, [dist[eto], eto])


for i in range(N-1):
    e1,e2 = map(int, input().split())
    e1 -= 1
    e2 -= 1
    if G[e1] == []:
        G[e1] = [e2]
    else:
        G[e1].append(e2)
    if G[e2] == []:
        G[e2] = [e1]
    else:
        G[e2].append(e1)

if v in G[u]:
    ans = 0
else:    

    calcDist(v,dv)
    calcDist(u,du)
    maxD = 0
    for idu,idv in zip(du,dv):
        if idu < idv:
            maxD = max(maxD, idv)       
    ans = maxD-1
    
print(ans)
n = int(input())
c=list(map(int, input().split())) 

n_pos = 0
max_c = 0
for i in c:
  if i>=max_c:
  	n_pos += 1
    max_c = i
  else:
    pass
print(n_pos)

### FIXED CODE ###

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

n_pos = 0
max_c = 0
for i in c:
    if i>=max_c:
        n_pos += 1
        max_c = i
    else:
        pass
print(n_pos)
N=input()
lista=list(map(int,input().split()))
  for _ in range(1,N+1):
print(lista.count(_))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for aa in a:
  ans[aa-1]+=1
for an in ans:
  print(an)
if __name__ == '__main__':
    
    A, B = [int(x) for x in input().split(' ')]
    S = input()

    S = S.split('-')
    if S.length < 2:
        print('No')

    a = S[0]
    b = S[1]

    if a.length == A:
        if b.length == B:
            print('YES')
            exit()

    print('No')


### FIXED CODE ###

if __name__ == '__main__':
    
    A, B = [int(x) for x in input().split(' ')]
    S = input()

    S = S.split('-')
    if len(S) != 2:
        print('No')
        exit()

    a = S[0]
    b = S[1]

    if len(a) == A:
        if len(b) == B:
            print('Yes')
            exit()

    print('No')
#ABC105B
N = int(input())
OK = False
for i in range(N/4):
    for j in range(N/7):
        if i*4 + j*7 == N:
            flag = True
if OK:
    print("Yes")
else:
    print("No") 

### FIXED CODE ###

#ABC105B
N = int(input())
flag = False
for i in range(30):
    for j in range(30):
        if i*4 + j*7 == N:
            flag = True
if flag:
    print("Yes")
else:
    print("No")
7
5 15
1 10 16 2 7 20 12

### FIXED CODE ###

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

cnt = [0, 0, 0]
for pi in p:
    if pi <= a:
        cnt[0] += 1
    elif pi <= b:
        cnt[1] += 1
    else:
        cnt[2] += 1
print(min(cnt))
n = int(input())
S = list(map(int, input().split()))
b=[]
for in range(n):
    b.append(S[i])
    b=b[::-1]
print(b)

### FIXED CODE ###

n = int(input())
S = list(map(int, input().split()))
S=S[::-1]
x=S[::2]
y=S[1::2]
b=x+y[::-1]
print(*b, sep=" ")
s = input()
l =[]
for i in range(len(s)):
    if s[i] == "0":
        l.append("0")
    elif s[i] == "1":
        l.append("1")
    elif s[i] =="B":
        if len(l) == 0:
           pass
        else:
           del l[i - 1]
print("".join(l))

### FIXED CODE ###

s = input()
l =[]
for i in range(len(s)):
    if s[i] == "0":
        l.append("0")
    elif s[i] == "1":
        l.append("1")
    elif s[i] =="B":
        if len(l) == 0:
           pass
        else:
           del l[-1]
print("".join(l))
g_m=0
g_G=[]
g_cnt=0
A=[]
n = int(input())
for i in range(n):
    A.append(int(input()))
def insertionSort(A,n,g):
    global g_cnt
    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j-g
            g_cnt += 1
        A[j+g]=v
    
def shellSort(A,n):
    m=1
    G=[]
    j=1
    for i in range(0,10):
        G.append(j)
        j=3*j+1
    
    while G[m]<=n:
        m+=1
    G=G[:m]
    G.reverse()
    for i in range(0,m):
        insertionSort(A,n,G[i])
    return A,m,G
A,g_m,g_G=shellSort(A,n)
print(g_m)
print(" ".join(map(str,g_G)))
print(g_cnt)
print(*A,sep="\n")

### FIXED CODE ###

g_m=0
g_G=[]
g_cnt=0
A=[]
n = int(input())
for i in range(n):
    A.append(int(input()))
def insertionSort(A,n,g):
    global g_cnt
    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j-g
            g_cnt += 1
        A[j+g]=v
    
def shellSort(A,n):
    m=1
    G=[]
    j=1
    for i in range(0,100):
        G.append(j)
        j=3*j+1
    
    while G[m]<=n:
        m+=1
    G=G[:m]
    G.reverse()
    for i in range(0,m):
        insertionSort(A,n,G[i])
    return A,m,G
A,g_m,g_G=shellSort(A,n)
print(g_m)
print(" ".join(map(str,g_G)))
print(g_cnt)
print(*A,sep="\n")
class path_compressed_quick_union:
    def __init__(self, n):
        self.n = n
        self.data = [i for i in range(n)]
        self.size = [1 for i in range(n)]

    def root(self, p):
        while p != self.data[p]:
            self.data[p] = self.data[self.data[p]]
            p = self.data[p]
        return p

    def connected(self, p, q):
        return self.root(p) == self.root(q)

    def union(self, p, q):
        proot = self.root(p)
        qroot = self.root(q)
        if self.size[proot] < self.size[qroot]:
            self.data[qroot] = proot
            self.size[qroot] += self.size[proot]
        else:
            self.data[proot] = qroot
            self.size[proot] += self.size[qroot]



N, M = map(int,input().split())
uf = path_compressed_quick_union(N)
for i in range(M):
    a,b=map(int,input().split())
    uf.union(a,b)

print(len(set(uf.data))-1)


### FIXED CODE ###

class path_compressed_quick_union:
    def __init__(self, n):
        self.n = n
        self.data = [i for i in range(n)]
        self.size = [1 for i in range(n)]

    def root(self, p):
        while p != self.data[p]:
            self.data[p] = self.data[self.data[p]]
            p = self.data[p]
        return p

    def connected(self, p, q):
        return self.root(p) == self.root(q)

    def union(self, p, q):
        proot = self.root(p)
        qroot = self.root(q)
        if self.size[proot] < self.size[qroot]:
            self.data[qroot] = proot
            self.size[qroot] += self.size[proot]
        else:
            self.data[proot] = qroot
            self.size[proot] += self.size[qroot]



N, M = map(int,input().split())
uf = path_compressed_quick_union(N)
for i in range(M):
    a,b=map(int,input().split())
    uf.union(a-1,b-1)
ans = []
for i in range(N):
    ans.append(uf.root(i))
print(len(set(ans))-1)