A sequence a=\{a_1,a_2,a_3,......\} is determined as follows:
 - The first term s is given as input.
 - Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.
 - a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.
Find the minimum integer m that satisfies the following condition:
 - There exists an integer n such that a_m = a_n (m > n).

-----Constraints-----
 - 1 \leq s \leq 100
 - All values in input are integers.
 - It is guaranteed that all elements in a and the minimum m that satisfies the condition are at most 1000000.

-----Input-----
Input is given from Standard Input in the following format:
s

-----Output-----
Print the minimum integer m that satisfies the condition.

-----Sample Input-----
8

-----Sample Output-----
5

a=\{8,4,2,1,4,2,1,4,2,1,......\}. As a_5=a_2, the answer is 5.

Difficulty: EASY

Solutions:
import sys

def input():
	return sys.stdin.readline().strip()

def I():
	return int(input())

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

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def S():
	return input()

def LS():
	return input().split()
INF = float('inf')
s = I()
vs = set()
vs.add(s)
now = 0 + s
i = 1
while True:
	i += 1
	now = now / 2 if now % 2 == 0 else 3 * now + 1
	if now in vs:
		break
	else:
		vs.add(now)
print(i)


def f(n):
	if n % 2 == 0:
		return n / 2
	else:
		return 3 * n + 1
s = int(input())
cnt = 0
a = [s]
while True:
	temp = f(a[cnt])
	if temp in a:
		print(len(a) + 1)
		return
	a.append(temp)
	cnt += 1


def f(n):
	if n % 2 == 0:
		return n / 2
	else:
		return 3 * n + 1
s = int(input())
a = []
for i in range(1000000):
	if i == 0:
		a.append(s)
	elif f(a[-1]) in a:
		print(i + 1)
		break
	else:
		a.append(f(a[-1]))


s = int(input())
c = set([s])
i = 1
while True:
	i += 1
	if s & 1:
		s = 3 * s + 1
	else:
		s //= 2
	if s in c:
		print(i)
		break
	c.add(s)


s = int(input())
A = []
while s not in A:
	A.append(s)
	if s % 2 == 0:
		s //= 2
	else:
		s = 3 * s + 1
print(len(A) + 1)


a = int(input())
s = set()
i = 1
while True:
	if a in s:
		print(i)
		break
	s |= {a}
	if a % 2 == 0:
		a >>= 1
	else:
		a = 3 * a + 1
	i += 1


s = int(input())
t = {s}
m = 1
while True:
	if s % 2:
		s = 3 * s + 1
	else:
		s //= 2
	m += 1
	if s in t:
		print(m)
		break
	t.add(s)


s = int(input())
a = [s]
ans = 0
for i in range(1000000):
	if a[i] % 2 == 0:
		if a[i] / 2 in a:
			ans = i + 2
			break
		a.append(a[i] / 2)
	else:
		if 3 * a[i] + 1 in a:
			ans = i + 2
			break
		a.append(3 * a[i] + 1)
print(ans)


N = int(input())
S = set()
t = N
i = 1
while t not in S:
	S.add(t)
	i += 1
	if t % 2 == 0:
		t = t // 2
	else:
		t = 3 * t + 1
print(i)


S = int(input())
L = [S]
while True:
	v = L[-1]
	nv = [v // 2, 3 * v + 1][not 0 == v % 2]
	if nv in L:
		print(len(L) + 1)
		break
	L.append(nv)


s = int(input())
a = [0, s]
for n in range(2, 10 ** 6 + 1):
	if a[n - 1] % 2 == 0:
		an = a[n - 1] // 2
	else:
		an = a[n - 1] * 3 + 1
	if an in a:
		m = n
		break
	a.append(an)
print(m)


def fun(n):
	if n % 2:
		return 3 * n + 1
	return n // 2
a = [0] + [int(input())]
i = 1
while not fun(a[i]) in a:
	a.append(fun(a[i]))
	i += 1
print(i + 1)


s = int(input())
i = 1
if s == 1:
	print(4)
elif s == 2:
	print(4)
else:
	while s != 4:
		i += 1
		if s % 2 == 0:
			s = s / 2
		else:
			s = 3 * s + 1
	print(i + 3)


s = int(input())
a = s
S = set()
m = 1
while not a in S:
	m += 1
	S.add(a)
	if a % 2 == 0:
		a = a // 2
	else:
		a = 3 * a + 1
print(m)


s = int(input())
sl = []
count = 1
while s not in sl:
	sl.append(s)
	if s % 2 == 0:
		s /= 2
	else:
		s = 3 * s + 1
	count += 1
print(count)


a = []
a.append(int(input()))
i = 0
while len(a) == len(set(a)):
	if a[i] % 2 == 0:
		a.append(a[i] / 2)
	else:
		a.append(a[i] * 3 + 1)
	i += 1
print(i + 1)


def func(n: int) -> int:
	return n // 2 if n % 2 == 0 else n * 3 + 1

def answer(s: int) -> int:
	sequence_a = [s]
	while True:
		num = func(sequence_a[-1])
		if num in sequence_a:
			return len(sequence_a) + 1
		sequence_a.append(num)

def main():
	s = int(input())
	print(answer(s))

def __starting_point():
	main()
__starting_point()


s = int(input())
li = set()
counter = 1
while s not in li:
	li.add(s)
	s = int(s / 2 if s % 2 == 0 else 3 * s + 1)
	counter += 1
print(counter)


s = int(input())
TMP = [s]
if s == 1 or s == 2:
	print(4)
else:
	while TMP[-1] != 1:
		if TMP[-1] % 2 == 0:
			TMP.append(TMP[-1] // 2)
		elif TMP[-1] % 2 != 0:
			TMP.append(3 * TMP[-1] + 1)
	print(len(TMP) + 1)


s = int(input())
x = s
l = [s]
for i in range(2, 1000001):
	if x % 2 == 0:
		x = x // 2
	else:
		x = 3 * x + 1
	if l.count(x) > 0:
		print(i)
		exit()
	l.append(x)


s = int(input())
list_a = [s]
for i in range(1000000):
	if list_a[i] % 2 == 0:
		list_a.append(list_a[i] / 2)
	else:
		list_a.append(3 * list_a[i] + 1)
for (index, ai) in enumerate(list_a, 1):
	if ai in list_a[:index - 1]:
		print(index)
		break


S = int(input())
a = []
while S not in a:
	a.append(S)
	if S % 2 == 0:
		S //= 2
	else:
		S = 3 * S + 1
print(len(a) + 1)


n = int(input())
li = []
while not n in li:
	li.append(n)
	if n % 2 == 0:
		n //= 2
	else:
		n = n * 3 + 1
print(len(li) + 1)


s = int(input())
lst = [0] * 100000
ans = 1
while lst[s] == 0:
	lst[s] += 1
	ans += 1
	if s % 2 == 0:
		s = s // 2
	else:
		s = 3 * s + 1
print(ans)


s = int(input())
a = []
ans = 1
a.append(s)
while 1:
	if s % 2 == 0:
		s = s // 2
	else:
		s = 3 * s + 1
	ans = ans + 1
	if s in a:
		break
	a.append(s)
print(ans)


n = int(input())
a = []
while n not in a:
	a.append(n)
	n = [3 * n + 1, n // 2][n % 2 == 0]
print(len(a) + 1)


s = int(input())
a = s
d = []
while a not in d:
	d.append(a)
	a = [a / 2, 3 * a + 1][int(a % 2)]
print(len(d) + 1)


a = int(input())
b = []
b.append(a)
while True:
	if a % 2 == 0:
		a = a / 2
		if a in b:
			print(len(b) + 1)
			break
		else:
			b.append(a)
	elif a % 2 != 0:
		a = 3 * a + 1
		if a in b:
			print(len(b) + 1)
			break
		else:
			b.append(a)


s = int(input())
A = [s]
ans = 1
while True:
	ans += 1
	s = s / 2 if s % 2 == 0 else 3 * s + 1
	if s in A:
		break
	A.append(s)
print(ans)


s = int(input())
if s == 2 or s == 1:
	print(4)
	exit()
n = 4
while s != 4:
	n += 1
	if s % 2 == 0:
		s = s // 2
	else:
		s = 3 * s + 1
print(n)


s = int(input())
a = set()
while not s in a:
	a.add(s)
	s = s // 2 if s % 2 == 0 else 3 * s + 1
print(len(a) + 1)


N = int(input())
s = set()
ans = 0
while N not in s:
	s.add(N)
	if N % 2 == 0:
		N //= 2
	else:
		N = 3 * N + 1
	ans += 1
print(ans + 1)


s = int(input())
i = 4
while s > 4 or 3 == s:
	s = [s // 2, s * 3 + 1][s % 2]
	i += 1
print(i)


S = int(input())
A = []
ans = 1
while S not in A:
	A.append(S)
	if S % 2 == 0:
		S = S // 2
	else:
		S = S * 3 + 1
	ans += 1
print(ans)


s = int(input())
A = [s]
i = 0
while len(A) == len(set(A)):
	if A[i] % 2 == 0:
		A.append(A[i] // 2)
	else:
		A.append(A[i] * 3 + 1)
	i += 1
print(i + 1)


H = [int(input())]
i = 0
while True:
	B = H[i]
	A = [B // 2, 3 * B + 1][B % 2 > 0]
	i += 1
	if A in H:
		break
	else:
		H.append(A)
print(i + 1)


s = int(input())
l = [s]
a = set(l)
for i in range(10 ** 6):
	if l[-1] % 2 == 0:
		n = l[-1] // 2
	else:
		n = 3 * l[-1] + 1
	if n not in a:
		a.add(n)
		l.append(n)
	else:
		print(len(l) + 1)
		break


k = int(input())
ans = 0
s = set()
while 1:
	ans += 1
	if k in s:
		print(ans)
		break
	s.add(k)
	if k % 2 == 0:
		k = k / 2
	else:
		k = 3 * k + 1


S = int(input())
a = [S]
temp = S
i = 0
while i < 200:
	i += 1
	if temp % 2 == 0:
		a.append(temp // 2)
	else:
		a.append(temp * 3 + 1)
	temp = a[-1]
for n in range(200):
	for m in range(n + 1, 200):
		if a[n] == a[m]:
			print(m + 1)
			return


S = int(input())
a = S
A = []
i = 1
while True:
	i += 1
	A += [a]
	a = int(a / 2 if a % 2 == 0 else 3 * a + 1)
	if a in A:
		break
print(i)


S = int(input())
(setf, i) = (set(), 1)
while S not in setf:
	setf.add(S)
	S = S // 2 if S % 2 == 0 else S * 3 + 1
	i += 1
print(i)


s = int(input())
l = []
b = s
i = 0
while b not in l:
	l.append(b)
	a = l[-1]
	if a % 2 == 0:
		b = a // 2
	else:
		b = a * 3 + 1
	i += 1
print(i + 1)


s = int(input())
a = [s]
for i in range(1, 1000001):
	if a[i - 1] % 2 == 0:
		x = a[i - 1] // 2
		if x in a:
			print(i + 1)
			break
		else:
			a.append(x)
	else:
		y = a[i - 1] * 3 + 1
		if y in a:
			print(i + 1)
			break
		else:
			a.append(y)


n = int(input())
l = [0] * 1000001
count = 1
while not l[n]:
	l[n] = 1
	n = 3 * n + 1 if n & 1 else n >> 1
	count += 1
print(count)


s = int(input())
mp = [False] * (10 ** 6 + 1)

def even_f(n):
	return n // 2

def odd_f(n):
	return 3 * n + 1
mp[s] = True
now = s
for i in range(1, 10 ** 6 + 1):
	if now % 2 == 0:
		now = even_f(now)
	else:
		now = odd_f(now)
	if mp[now]:
		savei = i
		break
	mp[now] = True
print(savei + 1)


from sys import stdin
s = int(stdin.readline().strip())
mem = []
a = s
for i in range(1000000):
	if a in mem:
		print(i + 1)
		return
	mem.append(a)
	if a % 2 == 0:
		a = a // 2
	else:
		a = 3 * a + 1


s = int(input())
ans = [s]
i = 1
if s == 1 or s == 2:
	ans = 4
else:
	while ans[i - 1] != 4:
		if ans[i - 1] % 2 == 0:
			ans.append(ans[i - 1] // 2)
		else:
			ans.append(ans[i - 1] * 3 + 1)
		i += 1
	ans = i + 3
print(ans)


s = int(input())
n = 1
while 1:
	if s == 1 or s == 2 or s == 4:
		print(n + 3)
		break
	if s % 2 == 1:
		s = 3 * s + 1
	else:
		s //= 2
	n += 1


s = int(input())
a = [s]
b = set([s])
i = 0
while len(b) == i + 1:
	a.append([a[i] // 2, 3 * a[i] + 1][a[i] % 2 != 0])
	b.add(a[i + 1])
	i += 1
print(i + 1)


a = int(input())
i = 1
li = [a]
import copy
while True:
	if li[i - 1] % 2 == 0:
		b = li[i - 1] // 2
	else:
		b = 3 * li[i - 1] + 1
	if b in li:
		print(i + 1)
		return
	li.append(b)
	i += 1


a = int(input())
A = []
cnt = 1
while a not in A:
	A.append(a)
	a = a // 2 if a % 2 == 0 else 3 * a + 1
	cnt += 1
print(cnt)


url = 'https://atcoder.jp//contests/abc116/tasks/abc116_b'

def calc(n):
	if n % 2 == 0:
		return n // 2
	else:
		return 3 * n + 1

def main():
	s = int(input())
	ans = [s]
	while True:
		tmp = calc(ans[-1])
		ans.append(tmp)
		if ans.index(tmp) != len(ans) - 1:
			print(len(ans))
			break

def __starting_point():
	main()
__starting_point()


a = int(input())
m = {}
for i in range(1000000):
	if a in m:
		print(i + 1)
		break
	m[a] = i
	if a % 2 == 0:
		a //= 2
	else:
		a = 3 * a + 1


a = [int(input())]
f = lambda n: n // 2 if n % 2 == 0 else 3 * n + 1
i = 2
while f(a[-1]) not in a:
	a.append(f(a[-1]))
	i += 1
print(i)


s = int(input())
a = [0] * 1000010
i = 1
a[s] = 1
while True:
	i += 1
	s = s // 2 if s % 2 == 0 else 3 * s + 1
	if a[s] == 0:
		a[s] = i
	else:
		print(i)
		break


s = int(input())
(l, a) = ([s], s)
for i in range(2, pow(10, 7) + 1):
	a = a // 2 if a % 2 == 0 else 3 * a + 1
	l.append(a)
	if l.count(a) == 2:
		print(i)
		exit()


s = int(input())
L = []
n = 1
while not s in L:
	L.append(s)
	if s % 2 == 0:
		s //= 2
	else:
		s = s * 3 + 1
	n += 1
print(n)


S = int(input())
a = []
while not str(S) in a:
	a.append(str(S))
	S = (S % 2 == 0) * (S // 2) + (S % 2 == 1) * (S * 3 + 1)
print(len(a) + 1)


N = int(input())
L = set()
i = 4
while 1:
	if N in [1, 2, 4]:
		print(i)
		exit()
	N = N * 3 + 1 if N % 2 else N // 2
	i += 1


n = int(input())
c = 1
l = [n]
while True:
	c += 1
	if n % 2 == 1:
		n = 3 * n + 1
	else:
		n = n // 2
	if n in l:
		print(c)
		break
	l.append(n)


s = int(input())
a = list()
n = 1
while s not in a:
	a.append(s)
	if s % 2 == 0:
		s = s / 2
	else:
		s = 3 * s + 1
	n += 1
else:
	print(n)


s = int(input())
a = [s]

def func(n):
	if n % 2 == 0:
		a.append(n // 2)
	elif n % 2 == 1:
		a.append(3 * n + 1)
i = 1
while True:
	func(a[-1])
	i += 1
	if a.count(a[-1]) == 2:
		break
	else:
		pass
print(i)


n = int(input())
ans = 1
while n != 4 and n != 2 and (n != 1):
	ans += 1
	if n % 2 == 0:
		n = n / 2
	else:
		n = 3 * n + 1
print(ans + 3)


s = int(input())
k = 1
while not s in [1, 2, 4]:
	if s % 2 == 0:
		s //= 2
	else:
		s = 3 * s + 1
	k += 1
print(k + 3)


s = int(input())
l = [4, 2, 1]
cnt = 1
while s not in l:
	if s % 2 == 0:
		s = s // 2
		cnt += 1
	else:
		s = s * 3 + 1
		cnt += 1
print(cnt + 3)


s = int(input())
max_ = 1000000
chk = [0] * max_
a = s
i = 1
while i <= max_:
	if chk[a] == 0:
		chk[a] += 1
	else:
		print(i)
		return
	if a % 2 == 0:
		a = int(a / 2)
	else:
		a = 3 * a + 1
	i += 1


s = int(input())
list_a = [None]
list_a.append(s)
ans = 0
for i in range(1, 10 ** 6 + 1):
	if list_a[i] % 2 == 0:
		list_a.append(list_a[i] // 2)
	else:
		list_a.append(3 * list_a[i] + 1)
	if list_a[i] in list_a[:i]:
		ans = i
		break
print(ans)


s = int(input())
count = 1
n = s
check = 0
list = [s]
for i in range(30000):
	if n % 2 == 0:
		n = n / 2
		list.append(n)
	else:
		n = n * 3 + 1
		list.append(n)
	count = count + 1
	list.sort()
	for j in range(len(list) - 1):
		if list[j] == list[j + 1]:
			check = 1
			break
	if check == 1:
		break
print(count)


a = int(input())
s = set()
for i in range(1, 1000002):
	if a in s:
		print(i)
		exit()
	s.add(a)
	if a % 2 == 0:
		a = a // 2
	else:
		a = a * 3 + 1


s = int(input())
a_list = [s]
a = s
while True:
	if a % 2 == 0:
		a = a // 2
	else:
		a = 3 * a + 1
	if a in a_list:
		break
	else:
		a_list.append(a)
ans = len(a_list) + 1
print(ans)


s = int(input())
a = [s]
while True:
	if a.count(a[-1]) == 2:
		print(len(a))
		return
	if a[-1] % 2 == 0:
		a.append(a[-1] / 2)
	else:
		a.append(3 * a[-1] + 1)


l = [int(input())]
while True:
	if l[-1] % 2 == 0:
		l.append(l[-1] // 2)
	else:
		l.append(l[-1] * 3 + 1)
	if l.count(l[-1]) > 1:
		print(len(l))
		break


s = int(input())
i = 2
while ~-s:
	s = [s // 2, s * 3 + 1][s % 2]
	i += 1
print(max(i, 4))


s = int(input())
if s < 3:
	print(4)
	return
cnt = 1
val = s
while True:
	if cnt > 1 and val == 1:
		break
	if val % 2 == 0:
		val = val // 2
	else:
		val = val * 3 + 1
	cnt += 1
print(cnt + 1)


S = int(input())
array = []
array.append(S)
while True:
	count = 0
	if S % 2 == 0:
		S = S / 2
		array.append(S)
	else:
		S = 3 * S + 1
		array.append(S)
	for i in range(len(array)):
		if S == array[i]:
			count += 1
			if count == 2:
				print(i + 1)
				return


n = int(input())
c = 0
x = []
while True:
	c += 1
	if n in x:
		print(c)
		break
	x.append(n)
	if n % 2 == 0:
		n = n // 2
	else:
		n = 3 * n + 1


s = int(input())
li = []
cnt = 1
while s not in li:
	li.append(s)
	if s % 2 == 0:
		s /= 2
	else:
		s = s * 3 + 1
	cnt += 1
print(cnt)


import sys
input = sys.stdin.readline

def main():
	S = int(input())
	x = set()
	x.add(S)
	i = 1
	prev = S
	while True:
		i += 1
		if prev % 2 == 0:
			prev = prev // 2
		else:
			prev = prev * 3 + 1
		if prev in x:
			print(i)
			return
		x.add(prev)

def __starting_point():
	main()
__starting_point()


s = int(input())
S = [str(s)]
i = 1
while True:
	if s % 2 == 0:
		i += 1
		s = s // 2
		S.append(str(s))
		if S.count(str(s)) == 2:
			print(i)
			return
	else:
		i += 1
		s = int(3 * s + 1)
		S.append(str(s))
		if S.count(str(s)) == 2:
			print(i)
			return
pass


s = int(input())
cnt = 1
box = set()
while not s in box:
	box.add(s)
	if s % 2 == 0:
		s = s / 2
	else:
		s = 3 * s + 1
	cnt += 1
print(cnt)


s = int(input())
a = [0] * (10 ** 6 + 1)
c = [0] * (10 ** 6 + 1)
a[1] = s
c[s] = 1
for i in range(2, 10 ** 6 + 1):
	v = a[i - 1] // 2 if a[i - 1] % 2 == 0 else 3 * a[i - 1] + 1
	a[i] = v
	if c[v] == 1:
		print(i)
		return
	c[v] = 1


s = [int(input())]
i = 2
while 1:
	j = s[-1]
	if j % 2:
		f = 3 * j + 1
	else:
		f = j // 2
	if s.count(f):
		break
	else:
		s.append(f)
		i += 1
print(i)


s = int(input())
a = s
ans = 0
if a == 1 or a == 2 or a == 4:
	ans = 4
else:
	for i in range(10 ** 6 + 1):
		if a % 2 == 0:
			a = int(a / 2)
		else:
			a = 3 * a + 1
		if a == 4:
			ans = i + 5
			break
print(ans)


s = int(input())
x = s
st = set()
while x not in st:
	st.add(x)
	if x % 2 == 0:
		x //= 2
	else:
		x = x * 3 + 1
print(len(st) + 1)


s = int(input())
li = []
li.append(s)
for i in range(1, 1000000000):
	if li[i - 1] % 2 == 0:
		li.append(li[i - 1] // 2)
	else:
		li.append(li[i - 1] * 3 + 1)
	for j in range(len(li) - 1):
		if li[j] == li[i]:
			print(i + 1)
			return


s = int(input())
col = []
a = s
count = 1
while True:
	col.append(a)
	if a % 2 == 0:
		a = a / 2
	else:
		a = a * 3 + 1
	if a in col:
		print(count + 1)
		break
	count += 1


x = int(input())
count = 1
while x != 1 and x != 2 and (x != 4):
	if x % 2 == 0:
		x = x // 2
	else:
		x = x * 3 + 1
	count += 1
print(count + 3)


s = int(input())
A = [s]
idx = 1
while True:
	n = A[idx - 1]
	if n % 2:
		f = 3 * n + 1
	else:
		f = n / 2
	idx += 1
	A.append(f)
	if len(A) != len(set(A)):
		break
print(idx)


s = int(input())
line = [0 for i in range(1000001)]
ans = 1
line[s] += 1
while True:
	ans += 1
	if s % 2 == 0:
		s = int(s / 2)
	else:
		s = 3 * s + 1
	line[s] += 1
	if line[s] > 1:
		break
print(ans)


N = int(input())
if N == 1 or N == 2:
	print(4)
else:
	m = 0
	while N > 1:
		if N % 2 == 0:
			N = N // 2
		else:
			N = 3 * N + 1
		m += 1
	print(m + 2)


s = int(input())
cnt = 2
se = set([s])
b = s // 2 if s % 2 == 0 else 3 * s + 1
while b not in se:
	cnt += 1
	se.add(b)
	b = b // 2 if b % 2 == 0 else 3 * b + 1
print(cnt)


import sys
import copy
s = int(input())

def f(n):
	if n % 2 == 0:
		return int(n / 2)
	else:
		return 3 * n + 1
for i in range(1000000):
	if i == 0:
		a = [s]
	else:
		a.append(f(a[i - 1]))
	if a.count(a[i]) == 2:
		print(i + 1)
		return


s = int(input())

def f(x):
	if x % 2 == 0:
		return int(x / 2)
	else:
		return 3 * x + 1
i = 1
m_max = 1000000
b_s = s
b = set([s])
while i <= m_max:
	i += 1
	a = f(b_s)
	if a in b:
		break
	b.add(a)
	b_s = a
print(i)


s = int(input())
exist_set = set()
index = 1
while s not in exist_set:
	exist_set.add(s)
	s = s // 2 if s % 2 == 0 else 3 * s + 1
	index += 1
print(index)


n = int(input())
a = [n]
cnt = 1
while len(set(a)) == len(a):
	if n % 2 == 0:
		n //= 2
	else:
		n = 3 * n + 1
	a.append(n)
	cnt += 1
print(cnt)


s = int(input())
l = []
while s not in l:
	l += [s]
	if s % 2 == 0:
		s = s / 2
	else:
		s = 3 * s + 1
print(len(l) + 1)


n = int(input())
k = set()
i = 1
while True:
	if n in k:
		break
	k.add(n)
	i += 1
	n = 3 * n + 1 if n & 1 else n // 2
print(i)


A = int(input())
p = A
C = []
while A not in C:
	C.append(A)
	if A % 2 == 0:
		A = A // 2
	else:
		A = A * 3 + 1
print(len(C) + 1)


N = int(input())
if N == 1 or N == 2:
	print(4)
	exit()
ans = 1
while N != 4:
	N = N // 2 if not N % 2 else N * 3 + 1
	ans += 1
print(ans + 3)


import sys
s = int(input())
f = [0 for _ in range(1000005)]
f[s] = 1
n = s
for i in range(1000005):
	if n % 2 == 0:
		n = int(n / 2)
	else:
		n = int(3 * n + 1)
	if f[n] == 1:
		print(i + 2)
		return
	else:
		f[n] = 1


N = int(input())
memo = [N]
while True:
	if N % 2 == 0:
		N //= 2
	else:
		N = 3 * N + 1
	if N in memo:
		break
	memo.append(N)
print(len(memo) + 1)


import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque, Counter
from decimal import Decimal
import functools

def v():
	return input()

def k():
	return int(input())

def S():
	return input().split()

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

def X():
	return list(input())

def L():
	return list(input().split())

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

def lcm(a, b):
	return a * b // math.gcd(a, b)
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7
cnt = 0
ans = 0
num = []
inf = float('inf')
al = 'abcdefghijklmnopqrstuvwxyz'
AL = al.upper()

def f(n):
	if n % 2 == 0:
		return n // 2
	else:
		return 3 * n + 1
s = k()
num.append(s)
while True:
	cnt += 1
	s = f(s)
	if s in num:
		print(cnt + 1)
		return
	else:
		num.append(s)


def func(x):
	if x % 2 == 0:
		return x // 2
	else:
		return 3 * x + 1
A = [True for i in range(1000001)]
N = int(input())
count = 1
while A[N]:
	A[N] = False
	N = func(N)
	count += 1
print(count)


s = int(input())
ans = [0] * 1000001
cnt = 1
while True:
	if ans[s] == 0:
		ans[s] += 1
		if s % 2 == 0:
			s = s // 2
		else:
			s = 3 * s + 1
		cnt += 1
	if ans[s] != 0:
		print(cnt)
		return


a = int(input())
b = []
c = 0
while a:
	if a in b:
		a = 0
	b.append(a)
	if a % 2 == 0:
		a /= 2
	else:
		a = 3 * a + 1
	c += 1
print(c)


n = int(input())
log = []
cnt = 1
while n not in log:
	cnt += 1
	log += [n]
	n = 3 * n + 1 if n % 2 else n // 2
print(cnt)


s = int(input())
arr = []
ans = 0

def calc(n, cnt):
	arr.append(n)
	if cnt >= 1000000:
		return n
	if n % 2 == 0:
		n = int(n / 2)
	else:
		n = int(3 * n + 1)
	if n in arr:
		return cnt
	cnt += 1
	calc(n, cnt)
calc(s, 0)
print(len(arr) + 1)


a = int(input())
x = set()
x.add(a)
i = 1
while True:
	i += 1
	if a % 2 == 0:
		a //= 2
	else:
		a = 3 * a + 1
	if a in x:
		break
	x.add(a)
print(i)


n = int(input())
l = [n]
i = 1
while True:
	i += 1
	if n % 2 == 0:
		n = n / 2
	else:
		n = 3 * n + 1
	if n in l:
		print(i)
		break
	else:
		l += [n]


s = int(input())
i = 1
r = [s]
while True:
	i += 1
	s = s // 2 if s % 2 == 0 else 3 * s + 1
	if s in r:
		print(i)
		break
	r += [s]


s = int(input())

def collatz(n):
	if n % 2 == 0:
		return n // 2
	else:
		return 3 * n + 1
coll = s
i = 1
while 1:
	if coll == 1 or coll == 2 or coll == 4:
		print(i + 3)
		break
	coll = collatz(coll)
	i += 1


s = int(input())
a = [s]
i = 2
while True:
	now = a[-1] / 2 if a[-1] % 2 == 0 else 3 * a[-1] + 1
	if now in a:
		print(i)
		break
	a.append(now)
	i += 1


l = [int(input())]
i = 0
while True:
	a = l[i] // 2 if l[i] % 2 == 0 else 3 * l[i] + 1
	if a in l:
		break
	else:
		l.append(a)
		i += 1
print(len(l) + 1)


s = int(input())
sec = [s]
count = 1
while s:
	if sec[-1] % 2 == 0:
		sec.append(sec[-1] / 2)
	else:
		sec.append(3 * sec[-1] + 1)
	count += 1
	if sec[-1] in sec[:-1]:
		print(count)
		break


s = int(input())
A = []
ans = 1
while s not in A:
	A.append(s)
	s = s // 2 * (s % 2 == 0) + (3 * s + 1) * (s % 2 != 0)
	ans += 1
else:
	print(ans)


s = int(input())
box = set()
box.add(s)
for i in range(2, 1000000):
	if s % 2 == 0:
		s //= 2
	else:
		s = s * 3 + 1
	if s in box:
		print(i)
		return
	else:
		box.add(s)


s = int(input())

def calc(n):
	if n % 2 == 0:
		return n / 2
	else:
		return 3 * n + 1
ans = []
ans.append(s)
for i in range(1000001):
	if calc(ans[i]) in ans:
		print(len(ans) + 1)
		return
	else:
		ans.append(int(calc(ans[i])))


a = int(input())
l = [a]
for i in range(1000000):
	if a % 2 == 0:
		a = a // 2
	else:
		a = a * 3 + 1
	if l.count(a) == 2:
		print(1 + max([i for (i, x) in enumerate(l) if x == a]))
		break
	else:
		l.append(a)


s = int(input())
a = []
a.append(s)
n = 1
while a.count(s) == 1:
	n += 1
	if s % 2 == 0:
		s = s / 2
	else:
		s = 3 * s + 1
	a.append(s)
print(n)


S = int(input())
(s, c) = (S, 1)
result = [s]
while True:
	if s % 2 == 0:
		s = s // 2
	elif s % 2 == 1:
		s = s * 3 + 1
	result.append(s)
	c += 1
	if len(set(result)) < len(result):
		break
print(c)


a = int(input())
da = True
ap = [a]
count = 1
while da:
	if a % 2 == 0:
		a = a // 2
		ap.append(a)
	elif a % 2 == 1:
		a = 3 * a + 1
		ap.append(a)
	count += 1
	if len(set(ap)) < len(ap):
		print(count)
		da = False


s = int(input())
l = [s]
i = 1
while 1:
	i += 1
	s = s / 2 if s % 2 == 0 else 3 * s + 1
	if s in l:
		print(i)
		exit()
	else:
		l.append(s)


s = int(input())
st = set([s])
i = 1
while 1:
	if s % 2:
		s = 3 * s + 1
	else:
		s //= 2
	if s in st:
		print(i + 1)
		break
	st.add(s)
	i += 1


s = int(input())
a = []
d = 1
while s not in a:
	a.append(s)
	if s % 2 == 0:
		s = s / 2
	else:
		s = 3 * s + 1
	d += 1
print(d)


s = int(input())
if s == 1 or s == 2:
	print(4)
	return

def function(n):
	if n % 2 == 0:
		return int(n / 2)
	else:
		return int(n * 3 + 1)
i = 0
count = 0
a = []
a.append(s)
while count < 2:
	a.append(function(a[i]))
	if a[i] == 4:
		count += 1
	i += 1
print(i)


s = [int(input())]
i = 0
while 1 > 0:
	if s[i] % 2 > 0:
		b = 3 * s[i] + 1
	else:
		b = s[i] // 2
	if b in s:
		print(i + 2)
		break
	i += 1
	s += [b]


n = int(input())
g = []
i = n
j = 0
while 1:
	j += 1
	if i in g:
		break
	else:
		g.append(i)
	if i % 2 == 0:
		i = i // 2
	else:
		i = 3 * i + 1
print(j)


s = int(input())
l = [s]
ans = 2
while True:
	if s % 2:
		s = 3 * s + 1
	else:
		s = s // 2
	if s in l:
		break
	else:
		l.append(s)
		ans += 1
print(ans)


n = int(input())
l = [n]
while True:
	if n % 2 == 0:
		n //= 2
	else:
		n = n * 3 + 1
	if n in l:
		break
	else:
		l.append(n)
print(len(l) + 1)


s = int(input())
num_lists = [s]
cnt = 1
while True:
	if num_lists[-1] % 2 == 0:
		tmp = num_lists[-1] / 2
	else:
		tmp = num_lists[-1] * 3 + 1
	cnt += 1
	if tmp in num_lists:
		ans = cnt
		break
	else:
		num_lists.append(tmp)
print(ans)


s = int(input())
a = {s}

def f(x):
	if x % 2 == 0:
		return x // 2
	else:
		return 3 * x + 1
ax = f(s)
m = 2
while ax not in a:
	a.add(ax)
	ax = f(ax)
	m += 1
print(m)


s = int(input())

def p(n):
	if n % 2 == 0:
		return n // 2
	else:
		return 3 * n + 1
l = [s]
cnt = 1
while True:
	cnt += 1
	s = p(s)
	if s in l:
		print(cnt)
		return
	else:
		l.append(s)


s = int(input())

class Solution:

	def __init__(self, s):
		self.s = s

	def function_a(self):
		if self.s % 2 == 0:
			return self.s / 2
		else:
			return 3 * self.s + 1

	def answer(self):
		list_a = [self.s]
		self.s = self.function_a()
		ans = 2
		while self.s not in list_a:
			list_a.append(self.s)
			self.s = self.function_a()
			ans += 1
		print(ans)
conditon = Solution(s)
conditon.answer()


a = int(input())
b = 0
if a == 2:
	print(4)
elif a == 1:
	print(4)
else:
	while a != 4:
		if a % 2 == 0:
			a = a // 2
			b = b + 1
		else:
			a = 3 * a + 1
			b = b + 1
	print(b + 4)


S = int(input())
a = [S]
cnt = 1
while True:
	if S % 2 == 0:
		S /= 2
	else:
		S = 3 * S + 1
	cnt += 1
	if S in a:
		break
	else:
		a.append(S)
print(cnt)


s = int(input())
c = 1
if s == 2 or s == 1:
	print(4)
else:
	while s != 4:
		if s % 2 == 0:
			s = s / 2
		else:
			s = s * 3 + 1
		c += 1
	print(c + 3)


s = int(input())
n = s
ans = 1
se = set()
while n not in se:
	se.add(n)
	if n % 2 == 0:
		n //= 2
	else:
		n = n * 3 + 1
	ans += 1
print(ans)


s = int(input())
a = []
na = []
a.append(s)
for i in range(1, 10 ** 6):
	if a[i - 1] % 2 == 0:
		a.append(a[i - 1] / 2)
	else:
		a.append(a[i - 1] * 3 + 1)
	na = set(a)
	if len(na) != i + 1:
		print(i + 1)
		return


s = int(input())
l = []
l.append(s)
for i in range(10 ** 7):
	if s % 2 == 0:
		s = int(s / 2)
	else:
		s = 3 * s + 1
	if s in l:
		break
	else:
		l.append(s)
print(i + 2)


s = int(input())
l = [0] * 1000010
for i in range(0, 1000010):
	l[s] += 1
	if l[s] == 2:
		print(i + 1)
		break
	if s % 2 == 0:
		s = s // 2
	else:
		s = 3 * s + 1


n = int(input())
i = 1
s = set()
while n not in s:
	s.add(n)
	i += 1
	if n % 2:
		n = 3 * n + 1
	else:
		n //= 2
print(i)


def f(a):
	if a % 2 == 0:
		return a // 2
	else:
		return 3 * a + 1
s = int(input())
cnt = 1
while s != 4 and s != 2 and (s != 1):
	cnt += 1
	s = f(s)
print(cnt + 3)


a = int(input())
n = 1
log = {a}
while n == len(log):
	if a % 2 == 0:
		a //= 2
	else:
		a = a * 3 + 1
	log.add(a)
	n += 1
print(n)


s = int(input())
l = []
a = 0
l.append(s)
for i in range(1000000):
	a += 1
	if s % 2 == 0:
		s = round(s / 2)
	else:
		s = s * 3 + 1
	if l.count(s) != 0:
		print(a + 1)
		break
	else:
		l.append(s)


def collatz(n):
	return 3 * n + 1 if n % 2 else n // 2
(a, n) = ([], int(input()))
while len(set(a)) == len(a):
	a.append(n)
	n = collatz(n)
print(len(a))


s = int(input())
l = []

def myfunc(x):
	if x % 2 == 0:
		x = x // 2
	else:
		x = 3 * x + 1
	return x
for i in range(10 ** 6):
	l.append(s)
	s = myfunc(s)
	if s in l:
		print(i + 2)
		break


s = int(input())
a = [0] * 10 ** 6
a[0] = s

def f(x):
	if x % 2 == 0:
		return x // 2
	else:
		return 3 * x + 1
t = 0
while f(a[t]) > 0:
	p = f(a[t])
	if p in a:
		print(t + 2)
		return
	a[t + 1] = p
	t += 1


s = int(input())
L = []
for c in range(2, 10 ** 6 + 1):
	L.append(s)
	if s % 2 == 0:
		s = s // 2
	elif s % 2 == 1:
		s = s * 3 + 1
	if s in L:
		break
print(c)


s = int(input())
list_a = [s]
if s % 2 == 0:
	s = s / 2
else:
	s = 3 * s + 1
current = 2
while s not in list_a:
	list_a.append(s)
	if s % 2 == 0:
		s = s / 2
	else:
		s = 3 * s + 1
	current += 1
print(current)


a = [int(input())]
i = 0
while True:
	if a[i] % 2 == 0:
		a.append(int(a[i] / 2))
	else:
		a.append(int(3 * a[i] + 1))
	if a.count(a[i]) == 2:
		break
	i += 1
print(i + 1)


s = int(input())
t = set()
count = 1
while s not in t:
	t.add(s)
	count += 1
	s = s // 2 if s % 2 == 0 else 3 * s + 1
print(count)


S = int(input())
A = set([])
while S not in A:
	A.add(S)
	if S % 2 == 0:
		S //= 2
	else:
		S = S * 3 + 1
print(len(A) + 1)


s = int(input())
e = set()
m = 1
while s not in e:
	e.add(s)
	s = s // 2 if s % 2 == 0 else s * 3 + 1
	m += 1
print(m)


s = int(input())
st = set()
st.add(s)
for i in range(2, 10 ** 6):
	t = s // 2 if s % 2 == 0 else 3 * s + 1
	if t in st:
		print(i)
		break
	st.add(t)
	s = t


import sys
import math as mp
l = []
vl = int(input())
while vl not in l:
	l.append(vl)
	if vl % 2 == 0:
		vl //= 2
	else:
		vl = 3 * vl + 1
print(len(l) + 1)


s = int(input())
a = []
ai = s
i = 1
while ai not in a:
	a.append(ai)
	i += 1
	if ai % 2 == 0:
		ai //= 2
	else:
		ai = 3 * ai + 1
print(i)


import sys
s = int(input())
cnt = 0
if s == 1 or s == 2:
	print('4')
	return
while s != 4:
	if s % 2 != 0:
		s = 3 * s + 1
		cnt += 1
	elif s % 2 == 0:
		s = s // 2
		cnt += 1
if s == 4:
	print(cnt + 4)


def readinput():
	s = int(input())
	return s

def main(s):
	hist = [0] * 1000001
	i = 1
	n = s
	hist[n] += 1
	while hist[n] <= 1:
		if n % 2 == 0:
			n = n // 2
		else:
			n = 3 * n + 1
		i += 1
		hist[n] += 1
	return i

def __starting_point():
	s = readinput()
	ans = main(s)
	print(ans)
__starting_point()


s = int(input())
lst = [s]
prev = s
for m in range(2, 1000001):
	if prev % 2 == 0:
		i = int(prev / 2)
	else:
		i = 3 * prev + 1
	if i in lst:
		print(m)
		break
	lst.append(i)
	prev = i


s = int(input())
se = set()
m = 1
while True:
	if s in se:
		answer = m
		break
	se.add(s)
	m += 1
	s = 3 * s + 1 if s & 1 else s // 2
print(answer)


a = int(input())
A = []
n = 1
while True:
	n += 1
	A += [a]
	if a % 2 == 0:
		a //= 2
	else:
		a = 1 + 3 * a
	if a in A:
		print(n)
		break


def f(n):
	return n // 2 if not n % 2 else 3 * n + 1
s = int(input())
l = [s]
while 1:
	v = f(l[-1])
	if v in l:
		print(len(l) + 1)
		break
	l.append(v)


s = int(input())

def f(n):
	if n % 2 == 0:
		return n / 2
	else:
		return 3 * n + 1
x = set()
ans = 0
while True:
	ans += 1
	if s in x:
		print(ans)
		break
	x.add(s)
	s = f(s)


s = int(input())
a = [s]
b = 1
while True:
	if s % 2 == 0:
		s = s // 2
	else:
		s = 3 * s + 1
	if s in a:
		print(len(a) + 1)
		return
	a.append(s)


s = int(input())
ls = []
n = s
while n not in ls:
	ls.append(n)
	if n % 2 == 0:
		n = n / 2
	else:
		n = 3 * n + 1
print(len(ls) + 1)


n = int(input())
l = [n]
i = 1
while len(set(l)) == i:
	if n % 2 == 0:
		n = n / 2
	else:
		n = 3 * n + 1
	l.append(n)
	i += 1
print(i)


x = int(input())
L = [x]
n = 1
while 1:
	n += 1
	x = 3 * x + 1 if x % 2 else x // 2
	if x in L:
		print(n)
		break
	else:
		L.append(x)


def main():

	def f(n):
		return 3 * n + 1 if n % 2 else n // 2
	s = int(input())
	a = [s]
	for i in range(1, 11 ** 6):
		x = f(a[i - 1])
		if x in a:
			return len(a) + 1
			return
		a.append(x)
print(main())


from collections import defaultdict
d = defaultdict(bool)
n = int(input())
for i in range(1000000):
	if d[n]:
		print(i + 1)
		return
	d[n] = True
	if n & 1:
		n = n * 3 + 1
	else:
		n >>= 1


s = int(input())
v_to_i = {}
cnt = 1
while not s in v_to_i:
	v_to_i[s] = cnt
	s = s // 2 if s % 2 == 0 else s * 3 + 1
	cnt += 1
print(cnt)


import sys
input = sys.stdin.readline

def func(n):
	ans = 0
	if n % 2 == 0:
		ans = n // 2
	else:
		ans = 3 * n + 1
	return ans

def main():
	s = int(input())
	dp = [s]
	counter = 0
	if s == 1 or s == 2:
		print(4)
		return
	while counter < 1000001:
		n = dp.pop()
		tmp = func(n)
		dp.append(n)
		dp.append(tmp)
		counter += 1
		if tmp == 4:
			print(dp.index(tmp) + 4)
			break

def __starting_point():
	main()
__starting_point()


s = int(input())

def f(n):
	if n % 2 == 0:
		return n // 2
	else:
		return 3 * n + 1
a = [0] * 10 ** 8
a[s] = 1
cnt = 1
for _ in range(10 ** 7):
	s = f(s)
	cnt += 1
	if a[s]:
		print(cnt)
		break
	a[s] = 1


s = int(input())
(x, a) = (set([s]), s)
while 1:
	if a % 2:
		a = 3 * a + 1
	else:
		a //= 2
	if a in x:
		break
	else:
		x.add(a)
print(len(x) + 1)


a = int(input())
dic = {}
dic[a] = 1
i = 1
while True:
	i += 1
	if a % 2 == 0:
		a //= 2
	else:
		a = 3 * a + 1
	if a in dic:
		break
	dic[a] = 1
print(i)


an = int(input())
n = 1
a = []
while an not in a:
	a.append(an)
	n += 1
	an = an / 2 if an % 2 == 0 else an * 3 + 1
print(n)


s = int(input())
p = []
p.append(s)
i = 1
while s != 0:
	if s % 2 == 0:
		s = int(s / 2)
	else:
		s = 3 * s + 1
	i += 1
	if s in p:
		print(i)
		break
	p.append(s)


s = int(input())
ans = 1
a = [4, 2, 1]
while not s in a:
	ans += 1
	if s % 2 == 0:
		s //= 2
	else:
		s = s * 3 + 1
print(ans + 3)


a = int(input())
s = set([a])
for i in range(10 ** 6):
	if a % 2 == 0:
		a = a // 2
	else:
		a = 3 * a + 1
	if a not in s:
		s.add(a)
	else:
		print(i + 2)
		break


s = int(input())
A = []
count = 1
while s not in A:
	A += [s]
	count += 1
	if s % 2 == 0:
		s = s // 2
	else:
		s = 3 * s + 1
print(count)


s = int(input())
S = {s}
i = 1
while True:
	i += 1
	if s % 2 == 0:
		s //= 2
	else:
		s = 3 * s + 1
	if s in S:
		break
	S.add(s)
print(i)


s = int(input())
cnt = 1
S = [s]
while 1:
	cnt += 1
	if s % 2 == 0:
		s //= 2
	else:
		s = 3 * s + 1
	if s in S:
		print(cnt)
		break
	S.append(s)


s = int(input())
cnt = [s]
while True:
	if s % 2 == 0:
		s //= 2
	else:
		s = s * 3 + 1
	if s in cnt:
		print(len(cnt) + 1)
		break
	else:
		cnt.append(s)


s = int(input())
l = [s]
l.append(3 * s + 1 if s % 2 else s // 2)
i = 1
while l.count(l[i]) < 2:
	l.append(3 * l[i] + 1 if l[i] % 2 else l[i] // 2)
	i += 1
print(i + 1)


s = int(input())
a = set()
i = 1
while True:
	a.add(s)
	i += 1
	s = s // 2 if s % 2 == 0 else 3 * s + 1
	if s in a:
		print(i)
		exit()


(s,) = map(int, input().split())
l = {s: 1}
a = s
i = 1
while True:
	i += 1
	a = a // 2 if a % 2 == 0 else 3 * a + 1
	if a in l:
		print(i)
		break
	l[a] = 1


s = int(input())
t = []
k = 1
while s not in t:
	t += [s]
	s = 3 * s + 1 if s % 2 else s // 2
	k += 1
print(k)


s = int(input())
a = []
a.append(s)
for i in range(1000000):
	if a[i] % 2 == 0:
		a.append(a[i] // 2)
	else:
		a.append(3 * a[i] + 1)
	for j in range(i - 1):
		if a[i + 1] == a[j]:
			print(len(a))
			return


n = int(input())
a = []
m = 1
while True:
	a.append(n)
	n = n / 2 * ((n + 1) % 2) + (3 * n + 1) * (n % 2)
	m = m + 1
	if n in a:
		break
print(m)


s = int(input())
visited = [False] * (10 ** 6 + 1)
visited[s] = True
cnt = 1
while True:
	if s & 1:
		s = s * 3 + 1
	else:
		s //= 2
	cnt += 1
	if visited[s]:
		print(cnt)
		break
	visited[s] = True


s = int(input())
ans_list = [s]
curr_value = s
index = 1
while True:
	if curr_value % 2 == 0:
		curr_value = int(curr_value / 2)
	else:
		curr_value = 3 * curr_value + 1
	index += 1
	if curr_value in ans_list:
		break
	else:
		ans_list.append(curr_value)
print(index)


s = int(input())
M = 10 ** 6
a = [0] * M
for i in range(M):
	if a[s] > 0:
		print(i + 1)
		break
	a[s] += 1
	s = [s // 2, 3 * s + 1][s % 2 == 1]


n = int(input())
data = [0] * 1000000
data[0] = n
i = 2
if n % 2 == 0:
	data[1] = n // 2
else:
	data[1] = 3 * n + 1
while data[i - 1] not in data[0:i - 2]:
	if data[i - 1] % 2 == 0:
		data[i] = data[i - 1] // 2
	else:
		data[i] = 3 * data[i - 1] + 1
	i += 1
print(i)


s = int(input())
S = [s]
while S[:-1].count(S[-1]) == 0:
	if S[-1] % 2 == 0:
		S.append(S[-1] / 2)
	else:
		S.append(S[-1] * 3 + 1)
print(len(S))