Harryxun/stf_run huggingface dataset:
def getN():
    return int(input())


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


def getList():
    return list(map(int, input().split()))

class UnionFind():
    def __init__(self, N):
        self.par = [i for i in range(N+20)]

    def root(self, n):
        if self.par[n] == n:
            return n
        else:
            return self.root(self.par[n])

    def isgroup(self, a, b):
        if self.root(a) == self.root(b):
            return True
        else:
            return False

    def merge(self, m, n):
        rm = self.root(m)
        rn = self.root(n)
        if rm == rn:
            pass
        else:
            self.par[rn] = rm

N,M = getNM()
pos = getList()
uf = UnionFind(N)
for i in range(M):
    x, y = getNM()
    uf.merge(x,y)

ans = 0

for i, p in enumerate(pos):
    if uf.isgroup(i+1, p):
        #print(i+1, p)
        ans += 1
    else:
        pass

#roots = [uf.root(i) for i in range(N+1)]
print(ans)

### FIXED CODE ###

import sys
from collections import defaultdict, deque
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

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

    def update(self):
        for i in range(len(self.par)):
            self.par[i] = self.find(i)

def solve():
    n,m = getList()
    nums = getList()
    uf = UnionFind(n)
    for i in range(m):
        x, y = getList()
        uf.union(x, y)
    uf.update()
    st1 = [[] for i in range(n + 1)]
    st2 = [[] for i in range(n + 1)]
    for i in range(n):
        st1[uf.par[i+1]].append(i+1)
        st2[uf.par[i+1]].append(nums[i])

    ans = 0
    for s1, s2 in zip(st1, st2):
        ans += len(list(set(s1) & set(s2)))



    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()
import sys
import bisect

input = sys.stdin.readline

L, R = map(int, input().split())

LR = list(range(L, R+1))
N = len(LR)
index = bisect.bisect_left(LR, 2019)
if index == 0:
    i, j = LR[0], LR[1]
elif index == N:
    i, j = LR[-2], LR[-1]
else:
    i, j = LR[index-1], LR[index]

modi = i % 2019
modj = j % 2019
print(modi * modj)

### FIXED CODE ###

import sys

input = sys.stdin.readline

L, R = map(int, input().split())

def main():
    if R // 2019 != L // 2019:
        ans = 0
    else:
        # ansLi = L % 2019
        # ansLj = (L+1) % 2019
        # ansL = ansLi * ansLj

        # ansRi = R % 2019
        # ansRj = (R-1) % 2019
        # ansR = ansRi * ansRj
        ansL = L*(L+1) % 2019
        ansR = R*(R-1) % 2019

        ans = min(ansL, ansR)

    return int(ans)

# print(main())

def search_all():
    if R // 2019 != L // 2019:
        return 0
    ans = float("inf")
    for i in range(L, R):
        for j in range(i+1, R+1):
            ans = min(i*j % 2019, ans)
            if ans == 0:
                break
    return ans

print(search_all())
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, x = map(int, readline().split())

v = a * a * b
s = x / a


if x < v / 2:
    # print(math.degrees(math.atan(2 * s / b / b)))
    print(90 - math.degrees(math.atan(2 * s / b / b)))
else:
    print(90 - math.degrees(math.atan(a / (b - (2 * s / a - b)))))



### FIXED CODE ###

import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, x = map(int, readline().split())

v = a * a * b
s = x / a

if x == v:
    print(0)
    exit()

if x <= v / 2:
    # print(math.degrees(math.atan(2 * s / b / b)))
    print(90 - math.degrees(math.atan(2 * x / a / b / b)))
else:
    print(90 - math.degrees(math.atan(a / (b - (2 * s / a - b)))))
n=input()
n=list(n)
if n[len(n)-1]==3:
  print("bon")
elif n[len(n)-1]==0 or n[len(n)-1]==1 or n[len(n)-1]==6 or n[len(n)-1]==8:
  print("pon"):
else:
  print("hon")

### FIXED CODE ###

n=int(input())
n=n%10

if n in [2,4,5,7,9]:
  print("hon")
elif n in [0,1,6,8]:
  print("pon")
else:
  print("bon")
a=[0,0,0]
a[0],a[1],a[2]=map(int,input().split())
a=sorted(a)
sa1=a[2]-a[0]
sa2=a[2]-a[1]
if (a[0]%2==a[1]%2==a[2]%2):
  print(sa1//2 + sa2//2)
else:
  if (sa1%2==0 and sa2%2==1):
    print((sa1//2)+1 + (sa2+1)//2)
  elif (sa1%2==1 and sa2%2==0):
    print(((sa1+1)//2) (sa2//2)+1)
  else:
    print((sa2-sa1)//2+sa1)

### FIXED CODE ###

a=[0,0,0]
a[0],a[1],a[2]=map(int,input().split())
a=sorted(a)
sa1=a[2]-a[0]
sa2=a[2]-a[1]
if (a[0]%2==a[1]%2==a[2]%2):
  print(sa1//2 + sa2//2)
else:
  if (sa1%2==0 and sa2%2==1):
    print((sa1//2)+1 + (sa2+1)//2)
  elif (sa1%2==1 and sa2%2==0):
    print(((sa1+1)//2)+(sa2//2)+1)
  else:
    print((sa2-sa1)//2+sa1)
def get_primenumber(N):
    #素数リスト
    prime_list = [2]
    #3からNまでの数字を一つずつ取り出す
    for num in range(3,N+1,2):
      #取り出した数字が素数リストの要素で割れなければ素数リストに追加する
      if all( num % prime != 0 for prime in prime_list):
        prime_list.append(num)

    return prime_list

def main():
    prime = []
    ans = []
    number = int(input())
    prime = get_primenumber(50000)
    for i in range(number):
        if number < prime[i]:
            ans.append(prime[i])
            
    print(min(ans))

if __name__ == "__main__":
    main()

### FIXED CODE ###


import math
def prime(n):
    for i in range(2, int(math.sqrt(n))):
        if n % i == 0: return False
    return True
 
X = int(input())
 
for i in range(X, 10**8):
    if prime(i):
        print(i)
        exit(0)
 
print('No prime number in this range')
a,b=map(int,input().split())
if a<=b:
  print(unsafe)
else:
  print(safe)

### FIXED CODE ###

a,b=map(int,input().split())
if a<=b:
  print("unsafe")
else:
  print("safe")
N,A = map(int,input().split())
if N%500 <= A:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

N,A=int(input()),int(input())
print('Yes' if N%500<=A else 'No')
X,Y=map(int,input())
print(X+Y//2)


### FIXED CODE ###

X,Y=map(int,input().split())
print(X+Y//2)
d={'AC':0,'WA':0,'TLE':0,'RE':0}
for _ in range(int(input()):
	d[input()]+=1
print('AC X',d['AC'])
print('WA X',d['WA'])
print('TLE X',d['TLE'])
print('RE X',d['RE'])
               
               

### FIXED CODE ###

d={'AC':0,'WA':0,'TLE':0,'RE':0}
for _ in range(int(input())):
	d[input()]+=1
print('AC x',d['AC'])
print('WA x',d['WA'])
print('TLE x',d['TLE'])
print('RE x',d['RE'])
from collections import deque

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

def intinp():
    return int(input())


N, M = mapint_inp()
ABs = [list(mapint_inp()) for _ in range(N)]

adjacency_matrix = [[0]*(N+1) for _ in range(N+1)]

for AB in ABs:
    A, B = AB
    # 隣接しているA,Bに関して、
    # A番目のリストに値Bを、B番目のリストに値Aを追加して
    # 隣接を管理する
    adjacency_matrix[A].append(B)
    adjacency_matrix[B].append(A)

result = [0]*(N+1)

q = deque([1])
while q:
    now = q.popleft()
    for i in adjacency_matrix[now]:
        if result[i] == 0:
            result[i] == now
            q.append(i)

print("Yes")
print('\n'.join(str(i) for i in result[2:]))

### FIXED CODE ###

from collections import deque

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

def intinp():
    return int(input())


n, m = mapint_inp()
graph = [[] for _ in range(n)]
ans = [0]*n

for _ in range(m):
    a, b = mapint_inp()
    a -= 1; b -= 1
    graph[a].append(b)
    graph[b].append(a) 

q = deque([0])
visited = [False]*n
visited[0] = True
while q:
    now = q.popleft()
    for i in graph[now]:
        if visited[i]: continue
        visited[i] = True
        ans[i] = now
        q.append(i)

print("Yes")
for i in range(1, n):
    print(ans[i]+1)
N = int(input())
a = map(int, input().split())

sorted_list = sorted(a)
print(sorted_list)
num = 0
last_num = 0

for i in range(N):
    if len(sorted_list) == 1:
        if i == 0:
            last_num = sorted_list[num]
        last_num = (sorted_list[num] + last_num) / 2
        break
    x = sorted_list[num]
    y = sorted_list[num+1]
    z = (x + y) / 2
    last_sum = z
    sorted_list.pop(num)
    sorted_list.pop(num)

print(last_num)


### FIXED CODE ###

n = int(input())
v = sorted(list(map(int, input().split())))
ans = v[0]

for i in range(n-1):
    ans = (ans + v[i+1]) / 2
print(ans)
da = list(map(int,input().split()))

k = [[0 for i in range(2)]for j in range(10001)]

i = 0

su = 0

j = 0

while da[0] != 0 and da[1] != 0:

	i = 0
	su = 0
	j = 0
	for i in range(da[0]):
		k[i][0],k[i][1] = list(map(int,input().split()))
		su += k[i][0] * k[i][1]

	sorted(k,key = lambda x: x[1],reverse = True)
	while da[1] != 0:
		if da[1] >= k[j][0]:
			su -= k[j][0] * k[j][1]
			da[1] -= k[j][0]
			j += 1
			if j == i:
				break

		else:
			su -= da[1] * k[j][1]
			da[1] = 0

	print(su)

	da = list(map(int,input().split()))
	if da[0] == 0 and da[1] == 0:
		break
	k = [[0 for i in range(2)]for j in range(10001)]



### FIXED CODE ###

da = list(map(int,input().split()))

k = [[0 for i in range(2)]for j in range(10001)]
i = 0
su = 0
j = 0

while da[0] + da[1] != 0:
	i = 0
	su = 0
	j = 0
	for i in range(da[0]):
		k[i][0],k[i][1] = map(int,input().split())


	k = sorted(k,key = lambda x: x[1],reverse = True)

	while j != i + 1:
		if da[1] > k[j][0]:
			da[1] -= k[j][0]
			j += 1
		elif da[1] <= k[j][0] and da[1] > 0:
			su += (k[j][0] - da[1]) * k[j][1]
			da[1] = 0
			j += 1
		else:
			su += k[j][0] * k[j][1]
			j += 1

	print(su)

	da = list(map(int,input().split()))

	k = [[0 for i in range(2)]for j in range(10001)]
n = int(input())
h = []
na = ["a","b", "c", "d", "e", "f", "g",
        "h", "i", "j", "k", "l", "m", "n", "o", "p", "q",
        "r", "s", "t", "u", "v", "w", "x", "y", "z"]
name = ""

if n < 26:
    h.append(n)
else:
    while n >= 27:
        tmp = n%26
        n //= 26
        h.append(tmp)
        print(n)

    print(n)
    if n != 0:
        h.append(n)

h = h[::-1]
if h[-1] == 0:
    h.pop(-1)
    for i in h:
        name += na[-i]
else:
    for i in h:
        name += na[-i-1]

print(name)

### FIXED CODE ###

n = int(input())
h = []
tmp = ["a", "b", "c", "d", "e", "f", "g",
       "h", "i", "j", "k", "l", "m", "n", "o", "p", "q",
        "r", "s", "t", "u", "v", "w", "x", "y", "z"]
name = ""

while n != 0:
    mod = n % 26
    h.append(mod)
    n //= 26
    if mod == 0:
        n -= 1
h.reverse()
for i in h:
    name += tmp[i - 1]
print(name)
N = int(input())
A = list(map(int, input().split()))

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

if d[-1] < 0:
    print(-1)
    print(aaaaaaa)
    exit()
else:
    d[-1] = A[-1]
for i in range(N, 0, -1):
    x = d[i]
    x += A[i-1]
    if d[i-1] * 2 < x:
        y = x - A[i-1]
        if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
            x = d[i-1] * 2
    if d[i-1]*2 < x:
        print(-1)
        print(aaaaaaa)
        exit()
    d[i-1] = min(x, d[i-1]+A[i-1])
# print(d)
print(sum(d))


### FIXED CODE ###

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

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

if d[-1] < 0:
    print(-1)
    exit()
else:
    d[-1] = A[-1]
for i in range(N, 0, -1):
    x = d[i]
    x += A[i-1]
    if d[i-1] * 2 < x:
        y = x - A[i-1]
        if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
            x = d[i-1] * 2
    d[i-1] = min(x, d[i-1]+A[i-1])
print(sum(d))
N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for i in range(M)]

answer = [None] * N
for si, ci in sc:
    if answer[si - 1] > ci:
        answer[si - 1] = ci

if answer[0] is None or answer[0] == 0:
    print('-1')
    exit()

for i, value in enumerate(answer):
    if answer[i] is None:
        answer[i] = 0

answer = ''.join(map(str, answer))
print(answer)


### FIXED CODE ###

N, M = list(map(int, input().split()))
sc = [list(map(int, input().split())) for i in range(M)]

answer = [None] * N
for si, ci in sc:
    digit = si - 1
    if answer[digit] is not None and answer[digit] != ci:
    # if answer[digit] != ci:
        print('-1')
        exit()
    
    answer[digit] = ci

if answer[0] == 0 and N != 1:
    print('-1')
    exit()

if answer[0] is None and N == 1:
    answer[0] = 0
elif answer[0] is None:
    answer[0] = 1

for i, value in enumerate(answer):
    if answer[i] is None:
        answer[i] = 0

answer = int(''.join(map(str, answer)))
print(answer)
n=int(input().split())
a=[0]*n
b=list(map(int,input().split()))
a[0]=b[0]
a[n-1]=b[n-2]

for i in range(1,n-1):
  a[i]=min(b[i-1],b[i])

print(sum(a))  
  


### FIXED CODE ###

n=int(input())
a=[0]*n
b=list(map(int,input().split()))
a[0]=b[0]
a[n-1]=b[n-2]
ans=0

for i in range(1,n-1):
  a[i]=min(b[i-1],b[i])

print(sum(a))
N = int(input())
C =　[0]*4
for i in range(N):
  M = input()
  if M == "AC":
    C[0] += 1
  else M == "WA":
    C[1] += 1
  else M == "TLE":
    C[2] += 1
  else M == "RE":
    C[3] += 1
    
print("AC" + " × " + str(C[0]))
print("WA" + " × " + str(C[1]))
print("TLE" + " × " + str(C[2]))
print("RE" + " × " + str(C[3]))
 


### FIXED CODE ###

N = int(input())
C = [0]*4
for i in range(N):
  M = input()
  if M == "AC":
    C[0] += 1
  elif M == "WA":
    C[1] += 1
  elif M == "TLE":
    C[2] += 1
  elif M == "RE":
    C[3] += 1
    
print("AC x " + str(C[0]))
print("WA x " + str(C[1]))
print("TLE x " + str(C[2]))
print("RE x " + str(C[3]))
import math
n,x=map(int,input().split())
l = [abs(int(i) - x) for i in input().split()]
ans = l[0]
for i in l:
    ans = math.gcd(ans,i)
print(ans)

### FIXED CODE ###

import functools
def gcd( a, b ):
    while b != 0:
        a, b = b,a%b
    return a
n,x=map(int,input().split())
l = [abs(int(i) - x) for i in input().split()]
print(functools.reduce(gcd,l))
A,B = map(int,input().rstrip().split())
if A == B:
    print(A*A)
else:
    print(max(A,B) * (max(A,B) - 1)

### FIXED CODE ###

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

X = max(A,B)
if A == B:
    G = X * 2
else:
    Y = max(A,B) - 1
    G = X + Y
print(G)
#それぞれの桁を考えた時にその桁を一つ多めに払うのかちょうどで払うのかで場合分けする

import math
n=int(input())
k=math.floor(math.log10(n))+1#桁数
n=str(n)#それぞれの桁にアクセスするためにイテラブルにする

#それぞれの桁を見ていくが、そのままと一つ多い状態から引く場合と二つあることに注意
dp=[[-1,-1] for _ in range(k)]
for i in range(k):
    if i==0:
        dp[i][0]=min(1+(10-int(n[i])),int(n[i]))
        dp[i][1]=min(1+(10-int(n[i])-1),int(n[i])+1)
    else:
        dp[i][0]=min(dp[i-1][1]+(10-int(n[i])),dp[i-1][0]+int(n[i]))
        dp[i][1]=min(dp[i-1][1]+(10-int(n[i])-1),dp[i-1][0]+int(n[i])+1)

print(dp[k-1][0])

### FIXED CODE ###

#それぞれの桁を考えた時にその桁を一つ多めに払うのかちょうどで払うのかで場合分けする

n=[int(x) for x in list(input())]#それぞれの桁にアクセスするためにイテラブルにする
k=len(n)

#それぞれの桁を見ていくが、そのままと一つ多い状態から引く場合と二つあることに注意
dp=[[-1,-1] for _ in range(k)]
dp[0]=[min(1+(10-n[0]),n[0]),min(1+(10-n[0]-1),n[0]+1)]
for i in range(1,k):
    dp[i]=[min(dp[i-1][1]+(10-n[i]),dp[i-1][0]+n[i]),min(dp[i-1][1]+(10-n[i]-1),dp[i-1][0]+n[i]+1)]
print(dp[k-1][0])
# coding : utf-8

import numpy as np

N = int(input())
X = np.array([int(i) for i in input().split()])

X = np.sort(X)
maxl = np.max(X)
Xed = (X - int(maxl/2))**2
com = X[np.where(np.min(Xed))]
print(maxl,X[com[0]])


### FIXED CODE ###

# coding : utf-8

import numpy as np

N = int(input())
X = np.array([int(i) for i in input().split()])

X = np.sort(X)
maxl = np.max(X)
Xed = (X - maxl/2)**2
com = X[np.where(Xed == np.min(Xed))]

print(maxl,com[0])
s=input()
def cal(n):
  if len(s)==1:
    return 0
  else:
    new=s[0]
    ans=0
    cnt=0
    for i in range(1,n):
      if s[i]!=new:
        new=s[i]

        cnt=0

        ans+=(i+1)

        

      else: s[i]==new:

          
        cnt+=1

        ans+=cnt

    return ans


### FIXED CODE ###

s=list(input())
import collections
dics=collections.Counter(s)
num=len(s)
ans=num*(num-1)//2
for i in dics.values():
  ans-=(i*(i-1)//2)
print(ans+1)
N=int(input())
A=list(map(int,input().split()))

from collections import Counter
counter=Counter(A)

LIST=sorted(list(counter.keys()),reverse=True)

L=len(LIST)

i=0
ANS=0
while i<L:
    #print(i,counter,ANS)
    if counter[LIST[i]]==0:
        i+=1
    else:
        for k in range(33):
            if 2**k<=LIST[i]:
                continue
            if 2**k>LIST[i]*2:
                i+=1
                break
            if counter.get(2**k-LIST[i],0)>0:
                if LIST[i]!=2**k-LIST[i]:                        
                    counter[LIST[i]]-=1
                    counter[2**k-LIST[i]]-=1
                    ANS+=1
                else:
                    if counter[LIST[i]]>=2:
                        counter[list[i]]-=2
                        ANS+=1
                    

print(ANS)

### FIXED CODE ###

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

from collections import Counter
counter=Counter(A)

LIST=sorted(list(counter.keys()),reverse=True)

L=len(LIST)

i=0
ANS=0
while i<L:
    #print(i,counter,ANS)
    if counter[LIST[i]]==0:
        i+=1
    else:
        for k in range(1,33):
            if 2**k<=LIST[i]:
                continue
            if 2**k>LIST[i]*2:
                i+=1
                break
            if counter.get(2**k-LIST[i],0)>0:
                if LIST[i]!=2**k-LIST[i]:
                    x=min(counter[LIST[i]],counter[2**k-LIST[i]])
                    counter[LIST[i]]-=x
                    counter[2**k-LIST[i]]-=x
                    ANS+=x
                else:
                    if counter[LIST[i]]>=2:
                        x=counter[LIST[i]]//2
                        counter[LIST[i]]-=x*2
                        ANS+=x
                    

print(ANS)
N = int(input())

anss = set()
for X in range(1, int(N**0.5)+2):
    if (N-X) % X == 0:
        m = (N-X) // X
        if N//m == N%m:
            anss.add(m)

for m in range(1, int(N**0.5)+2):
    if N//m == N%m:
        anss.add(m)

print(sum(anss))


### FIXED CODE ###

N = int(input())

anss = set()
for X in range(1, int(N**0.5)+2):
    if (N-X) % X == 0:
        m = (N-X) // X
        if m <= 0: continue
        if N//m == N%m:
            anss.add(m)

for m in range(1, int(N**0.5)+2):
    if N//m == N%m:
        anss.add(m)

print(sum(anss))
a = int(input())
b = int(input())
c = int(input())

num = 3

if a == b:
    num = num - 1
    if b == c:
        num = num - 1
elif b == c:
    num = num - 1
    
print('num')

### FIXED CODE ###

a = input().split()
num = 3

if a[0] == a[1]:
    num = num - 1
    if a[0] == a[2]:
        num = num - 1
elif a[0] == a[2]:
    num = num - 1
elif a[1] == a[2]:
    num = num - 1
    
print(num)
n = int(input())
l = map(int,input().split())
count = 0
if len(l) < 3:
  print(0)
  exit()
l = sorted(l)
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if l[i] != l[j] != l[k] and l[i]+l[j] > l[k]:
        count += 1
print(count)
    

### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))
if len(l) < 3:
  print(0)
  exit()
count = 0
l = sorted(l)
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if l[i] != l[j] != l[k] and l[i]+l[j] > l[k]:
        count += 1
print(count)
s = int(input())
ans = 1
nums = set()
while s not in nums:
  ans += 1
  if s % 2 == 0: s // = 2
  else: s = s * 3 + 1
  nums.add(s)
print(ans)


### FIXED CODE ###

s = int(input())
ans = 1
nums = set()
while s not in nums:
    ans += 1
    nums.add(s)
    if s % 2 == 0: s //= 2
    else: s = s * 3 + 1
print(ans)
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
k=min(k,41)

for j in range(k):
    b=[0 for i in range(n)]
    for i in range(n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    for i in range(1,n):
        b[i]+=b[i-1]
    a=b
    if e==n:
        break
print(" ".join(map(str,a)))

### FIXED CODE ###

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
k=min(k,41)

for j in range(k):
    b=[0 for i in range(n)]
    for i in range(n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    for i in range(1,n):
      b[i]+=b[i-1]
    a=b
print(" ".join(map(str,a)))
n = int(input())
l = []
for i in range(1,n**(0.5)):
  a = 2*i
  l.append(a)
print(l[-1])

### FIXED CODE ###

n = int(input())
p = 1
for i in range(10):
  p = p*2
  if(p>n):
    print(2**i)
    break
import numpy as np
h,w=map(int,input().split())
icon=list()
for i in range(h):
    icon.append(list(input().split()))

row=[False]*h
col=[False]*w

for i in range(h):
    for j in range(w):
        if icon[i][j]=='#':
            row[i]=True
            col[j]=True

for  i in range(h):
    if row[i]==True:
        for j in range(w):
            if col[j]==True:
                print(icon[i][j],end='')
        print()  

### FIXED CODE ###

import numpy as np
h,w=map(int,input().split())
"""
入力はスペースなしだった
文字列としてリストの行にぶち込む必要あり
icon=list()
for i in range(h):
    icon.append(list(input().split()))

"""
icon=[''] * h
for i in range(h):
    icon[i]=input()


row=[False]*h
col=[False]*w

for i in range(h):
    for j in range(w):
        if icon[i][j]=='#':
            row[i]=True
            col[j]=True

for  i in range(h):
    if row[i]==True:
        for j in range(w):
            if col[j]==True:
                print(icon[i][j],end='')
        print()
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
n=int(input())
i = list(map(int, input().split()))
ave=sum(i) / n
ans=0
as=Decimal(str(f)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
for k in range(n):
  ans+=(as-i[k])**2
print(ans)  

### FIXED CODE ###

import numpy as np
n=int(input())
i = list(map(int, input().split()))
ia=np.array(i)
ave=np.mean(ia)
ans=0
for k in range(n):
  ans+=(round(ave, 0)-i[k])**2
print(int(ans))
a, b, k = map(int, input().split())

print(max(0, a-k)+' '+max(0, a+b-k))

### FIXED CODE ###

a, b, k = map(int, input().split())

print(str(max(0, a-k))+' '+str(max(0, min(b, a+b-k))))
x = str(input())
lx = len(x)
num = lx - 2
head = int(x[:num])
body = int(x[num:])
up = head * 5
if body <= up:
    print("1")
else:
    print("0")

### FIXED CODE ###

x = str(input())
lx = len(x)
num = lx - 2
if int(x) >= 100:
    head = int(x[:num])
    body = int(x[num:])
    up = head * 5
    ans = int(0)
    if body <= up:
        ans = 1
    else:
        ans = 0
else:
    ans = 0
print(ans)
A,B,C,D = list(map(int,input.split(" ")))

if B<C:
    res = 0
else:
    res = min(B,D) - max(A<C)
print(res)

### FIXED CODE ###

N = int(input())
N = str(N)
if N[::-1] == N:
  print('Yes')
else:
  print('No')
antenna = [int(input()) for _ in range(N)]
k = int(input())

print("Yay!" if max(antenna) - min(antenna) <= k else ":(")

### FIXED CODE ###

b=True
a=[int(input()) for i in range(5)]
k=int(input())
for j in range(5):
  for l in range(5):
    if a[j]-a[l] > k:
      b=False
if b:
  print("Yay!")
else:
  print(":(")