Problem:
 Score : 200 points    Problem Statement 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 1 8      Sample Output 1 5  a=\{8,4,2,1,4,2,1,4,2,1,......\} . As a_5=a_2 , the answer is 5 .       Sample Input 2 7      Sample Output 2 18  a=\{7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4,2,1,......\} .       Sample Input 3 54      Sample Output 3 114

Solution (Python):
s = int(input())
a = [s]
ans = 1

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

for i in range(1000000):
	ans += 1
	s = f(s)
	if s in a:
		break

	a.append(s)


print(ans)

Solution (Python):

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

Solution (Python):
s = int(input())

a = []

a.append(s)
cont = True

i = 0
while cont:
    if a[i]%2 == 0:
        t = a[i]/2
    else:
        t = 3*a[i] + 1
    if t in a:
        cont = False
    else:
        i += 1
        a.append(t)

print(i+2)

Solution (Python):
from sys import stdin
s = int(stdin.readline().rstrip())
A = []
while True:
    if s not in A:
        A.append(s)
    else:
        break
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
print(len(A) + 1)

Solution (Python):
import collections
import copy
s = int(input())
same = 0
List = []
List.append(s)
while same == 0:
    if s % 2 == 0:
        s = s / 2
        List.append(s)
        unique = set(copy.copy(List))
        _List = collections.Counter(List)
        for v in unique:
            if _List[v] == 2:
                same += 1
    else :
        s = 3 * s + 1
        List.append(s)
        _List = collections.Counter(List)
        unique = set(copy.copy(List))
        for v in unique:
            if _List[v] == 2:
                same += 1
print(len(List))

Solution (Python):
s = int(input())
arr = []
set_num = {s}

for i in range(2,1000000):        
    if s % 2 == 0:
        s = s / 2
    else:
        s = 3 * s + 1
    if s in set_num:
        print(i)
        break
    else:
        set_num.add(s)

Solution (Python):
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)

Solution (Python):
s = int(input())

a = [s]
i = 0
tmp_fn = s
while True:
    if tmp_fn % 2 == 1:
        tmp_fn = a[i] * 3 + 1
        a.append(tmp_fn)
    else:
        tmp_fn = a[i] / 2
        a.append(tmp_fn)
    count = 0
    for j in range(len(a)):
        if a[j] == tmp_fn:
            count += 1
            if count == 2:
                print(j + 1)
                exit(0)
    i += 1

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

Solution (Python):
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)

Solution (Python):
n = int(input())
stop = 0
num_list = []
while stop == 0:
	if n in num_list:
		stop = 1
		print(num_list.index(n)+4)
	else:
		num_list.append(n)
		if n % 2 == 0:
			n //= 2
		else:
			n = 3 * n + 1

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

Solution (Python):
s = int(input())
l =[s]
m = 0
while l[m]<1000000:
    if l[m]%2:
        l.append(3*l[m]+1)
    else:
        l.append(l[m]//2)
    if l[m+1] in l[:m]:
        print(len(l))
        break
    else:
        m+=1

Solution (Python):

s = int(input())

lst_A = []

lst_A.append(s)

flg = "false"

while 1:

    if s % 2 == 0:
        s = int(s / 2)

    else:
        s = s * 3 + 1

    for i in range(len(lst_A)):

        if lst_A[i] == s:
            flg = "true"
            break

    if flg == "true":
        break

    lst_A.append(s)

print(len(lst_A) + 1)

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

Solution (Python):
s = int(input())
n = 1
tmp = s
if s == 1 or s == 2:
    print(4)
else:
    for i in range(1, 1000000):
        if tmp == 4:
            n = i
            break
        elif tmp % 2 == 0:
            tmp = tmp//2
        else:
            tmp = 3*tmp + 1
    print(n+3)

Solution (Python):

import sys

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

def solve(s: int):
    a = [s]
    a_prev = s
    for i in range(100000):
        a_i = f(a_prev)
        a_prev = a_i
        if a_i in a:
            break
        else:
            a.append(a_i)
        
    print(i+2)
        
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = int(next(tokens))  
    solve(s)

if __name__ == '__main__':
    main()

Solution (Python):
s = int(input())

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

l = [s]
a = s

for i in range(2, 10000):
  a = calc(a)
  if a in l:
    print(i)
    exit()
  else:
    l.append(a)

Solution (Python):
s = int(input())

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

l = [s]
a = s
cnt = 2
while True:
  tmp = calc(a)
  if tmp in l:
    print(cnt)
    exit()
  else:
    l.append(tmp)
    a = tmp
    cnt = cnt + 1

Solution (Python):
s = int(input())
f = lambda n: (n/2) if n%2==0 else (3*n + 1)
prevval = s
history = [s]
c = 2
while True:
    newval = f(prevval)
    if newval in history:
        break
    history.append(newval)
    c += 1
    prevval = newval
print(c)

Solution (Python):
S = int(input())

num_list = [S]

while True:
    if S % 2 == 0:
        S = int(S / 2)
    else:
        S = int(S * 3 + 1)

    if S in num_list:
        break;  
    num_list.append(S)

print(len(num_list)+1)

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

Solution (Python):


s = int(input())
li = []
li.append(s)
fl = True

while fl:
    
    if li[-1] % 2 == 0:
        n = int(li[-1] / 2)
        li.append(n)
    elif li[-1] % 2 == 1:
        n = li[-1]*3 + 1
        li.append(n)

    
    for j in range(0,len(li)-1):
        if li[j] == n:
            fl = False

print(len(li))

Solution (Python):
s = int(input())
list = [s]

for i in range(2, 1000000):
  if s%2 == 0:
    fn = int(s/2)
  else:
    fn = int(3*s+1)
  if fn in list:
    break
  list.append(fn)
  s = fn

print(i)

Solution (Python):
s = int(input())
M = 1000000

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

Solution (Python):
s = int(input())

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

a=[s]

for i in range(1000000):
	s = f(s)
	
	if s in a:
		print(len(a)+1)
		exit()
	a.append(s)

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


s = int(input())
a = [s]
c = 1
while True:
    c += 1
    ss = func(a[-1])
    if ss not in a:
        a.append(ss)
    elif ss in a:
        print(c)
        break

Solution (Python):
s = int(input())

flag = 1
i = 0
a = []
a.append(s)

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

Solution (Python):
s = int(input())
a = [s]
while 1:
    if a[-1] % 2:
        tmp = 3*a[-1] + 1
    else:
        tmp = a[-1]//2
    if tmp in a :
        print(len(a)+1)
        break
    else:
         a.append(tmp)

Solution (Python):
s = int(input())
a = [s]
i = 0

while a.count(a[i]) != 2:
    if a[i] % 2 == 0:
        a.append(a[i]//2)
    else:
        a.append(3*a[i] + 1)
    i += 1

ans = len(a)
print(ans)

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

s = int(input())
r = set([s])
m = 1

while True:
    m += 1
    s = f(s)
    if s in r:
        break
    else:
        r.add(s)

print(m)

Solution (Python):
s=int(input())  

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

a=[]  

while len(a)==len(set(a)):
  a.append(s)
  s=func(s)
  

print(len(a))

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

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

Solution (Python):
s = int(input())
l = []
flag = False
cnt = 0
tmp = 0
while flag==False:
  if tmp in l:
    cnt += 1
    flag = True
  else:
    if s % 2 == 0:
      tmp = s / 2
      l.append(s)
      s = tmp
      cnt += 1
    else:
      tmp = 3*s +1
      l.append(s)
      s = tmp
      cnt += 1
      
print(cnt)

Solution (Python):
s=int(input())

l=[s]*(10**6)
for i in range(10**6):
    if l[i]%2==0:
        l[i+1]=l[i]//2
    else:
        l[i+1]=3*l[i]+1
    if l[i]==4:
        print(i+4)
        exit()
    if l[i]==1:
        print(i+4)
        exit()
    if l[i]==2:
        print(i+4)
        exit()

Solution (Python):
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))

Solution (Python):
s = int(input())

a = [0 for _ in range(10 ** 5)]

ans = 1

while not a[s-1]:
    a[s-1] += 1
    if not s % 2:
        s = s // 2
    else:
        s = 3 * s + 1
    ans += 1

print(ans)

Solution (Python):
s = int(input())
D = {}
for i in range(1000001):
    if s in D:
        print(i + 1)
        exit()
    else:
        D[s] = 1
        if s % 2 == 0:
            s //= 2
        else:
            s = 3 * s + 1

Solution (Python):
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)

Solution (Python):

import sys

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


def solve(s: int):
    
    m_set = set()
    pn = s
    m_set.add(s)
    for m in range(1,100000000):
        nn = f(pn)
        if nn in m_set:
            print(m+1)
            return
        else:
            m_set.add(nn)
            pn = nn



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = int(next(tokens))  
    solve(s)

if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
count = 1
ls = [n]

while True:
    if n % 2 == 0:
        n = n / 2
    else:
        n = 3 * n + 1
    count+=1
    if n in ls:
        break
    else:
        ls.append(n)
print(count)

Solution (Python):
s = int(input())

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

memo = [False]*(10**6+1)
memo[s] = True
prev = s
for m in range(2,10**6+1):
    now = f(prev)
    if memo[now] == True:
        print(m)
        break
    else:
        memo[now] = True
    prev = now

Solution (Python):
s = int(input())


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


owned = {s}
n = 2
a = f(s)
while a not in owned:
    owned.add(a)
    a = f(a)
    n += 1
print(n)

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

s = int(input())
  
al = []
al.append(s)
cnum = s
for i in range(2,1000000):
  cnum = fn(cnum)
  if cnum in al[:-1]:
    print(i)
    exit()
  else:
    al.append(cnum)

Solution (Python):
n = int(input())
a = []
a.append(n)
sw = 0
count = 1

while True:
    count += 1 
    if n % 2 == 0:
        n = n / 2
    else :
        n = 3*n + 1
    
    for value in a:
        if value == n:
            print(count)
            sw = 1
            break

    if sw == 1:
        break
    a.append(n)

Solution (Python):
s = int(input())

def f(ai):
    return int(ai/2) if ai%2 == 0 else ai*3+1

cn = 0
seq = [s]
while True:
    ai = f(seq[cn])
    if ai in seq:
        print(cn+2)
        break
    seq.append(ai)
    cn += 1

Solution (Python):
def odd(a):
    return a/2

def even(b):
    return 3*b+1

num = int(input())
box = [num]
cnt = 0
answer = 0
while(True):
    if(num%2 == 0):
        num = odd(num)
    else:
        num = even(num)
    for i in range(len(box)-1):
        if(box[i] == num):
            answer = 1
    box.append(num)
    if(answer == 1):
        print(len(box))
        break

Solution (Python):
s = int(input())
n = 0
if s==1 or s == 2:
  print("4")
elif s==3:
  print("9")
if s >=4:
  s = 2*s
  while s % 2 == 0:
    s = s/2
    n += 1
    if s!=1 and s%2 == 1:
      s = 3*s+1
      n+=1
    if s == 1:
      print(n+1)
      break

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]









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

Solution (Python):
s = int(input())
check = {};count = 1
check['{}'.format(s)] = True
while 1==1:
    count += 1
    if s % 2== 0:s = s//2 
    else:s = 3*s + 1
    try:
        if check['{}'.format(s)] == True:
            break
    except:pass
    check[str(s)] = True
print(count)

Solution (Python):
num = int(input())
count = 1
ls = [num]
while True:
    if num % 2 == 0: num = num / 2
    else: num = (3 * num) + 1
    count += 1
    if num in ls: break
    else: ls.append(num)

print(count)

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

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

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

Solution (Python):
import sys
s = int(input())
a = [s]
x = 0
for i in range(1000000):
    if a[i] % 2 == 0:
        x = a[i] / 2
        if x in a:
            print(a.index(x) + 4)
            sys.exit(0)
        else:
            a.append(x)
    else:
        x = 3 * a[i] + 1
        if x in a:
            print(a.index(x) + 4)
            sys.exit(0)
        else:
            a.append(x)

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

Solution (Python):
s = int(input())
intlist = list()
intlist.append(s)
i = 0
end = True
while end:
    s2 = 0
    if intlist[i] % 2 == 0:
        s2 = intlist[i] / 2
    else:
        s2 = 3 * intlist[i] + 1
    i += 1
    for j in intlist:
        if s2 == j:
            print(i + 1)
            end = False
            break
    intlist.append(s2)

Solution (Python):
s = int(input())
min = 1000000
arr = [s]
count = 0
count_No1 = 0
n = 0
flg_exit = 0

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

while (not flg_exit) or (min == 1000000):
    temp = func(arr[count])
    if temp == 1:
        count_No1 = count_No1 + 1
        flg_exit = 1 if count_No1 == 2 else flg_exit
    if (temp in arr) and (count_No1 != 1):
        min = count if count < min else min
    else:
        arr.append(int(temp))
        count = count + 1

count = 4 if s == 1 else count
count = 4 if s == 2 else count

print(count)

Solution (Python):

"""
B - Collatz Problem
https://atcoder.jp/contests/abc116/tasks/abc116_b

"""
import sys


def solve(s):
    d = {s: s}
    ans = 1
    while True:
        ans += 1
        s = s/ 2 if s%2==0 else s*3+1
        if s in d:
            return ans
        d[s] = s


def main(args):
    s = int(input())
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
s = int(input())

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

Solution (Python):
S = int(input())

def main():
    a = [S]
    curr = S
    while a.count(curr) <= 1:
        curr = curr // 2 if curr % 2 == 0 else 3 * curr + 1
        a.append(curr)
    print(len(a))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import bisect
input = sys.stdin.readline

N = int(input())

p = N
s = set()
s.add(p)
c = 1

while True:
    if p % 2 == 0:
        p = p // 2
    else:
        p = p * 3 + 1
    c += 1
    if p in s:
        print(c)
        break
    else:
        s.add(p)

Solution (Python):
def collatz(num):
  if num % 2 == 0:
    return num // 2
  else:
    return 3*num + 1

s = int(input())
appeared = set()

target = s
c = 1
while target not in appeared:
  appeared.add(target)
  target = collatz(target)
  c += 1
  
print(c)

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

s = int(input())
ed = defaultdict(int)
cnt = 1
ed[s] = 1
while True:
    cnt += 1
    if s%2 == 0:
        s //= 2
    else:
        s = 3*s + 1
    if ed[s]:
        break
    else:
        ed[s] = 1

print(cnt)

Solution (Python):
a=int(input())
b=set()
b.add(a)
while(len(b)):
    count=len(b)
    if a%2==1:
        a=a*3+1
    else:
        a=a//2
    b.add(a)
    if count==len(b):
        break
print(len(b)+1)

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

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

Solution (Python):

s = int(input())
count = 1
num_set = {s}
def f(a):
    if a%2 == 0:
        return a/2
    else:
        return 3*a + 1
while (1):
    s = f(s)
    count += 1
    if s in num_set:
        print(count)
        break
    else:
        num_set.add(s)

Solution (Python):
arr = [int(input())]
pivot = 0
while pivot not in arr[:-1]:
  if arr[-1] % 2 == 0:
    arr.append(arr[-1]/2)
    pivot = arr[-1]
  else:
    arr.append(3*arr[-1] + 1)
    pivot = arr[-1]
print(len(arr))

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

Solution (Python):
s = int(input())

AM = [0] * 100010
AM[s] = 1
idx = 1
tmp = s
while True:
    if tmp%2 == 0:
       tmp //= 2 
    else:
        tmp = 3*tmp+1
    AM[tmp] += 1
    if AM[tmp] == 2:
        break
    idx += 1
    
print(idx+1)

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

Solution (Python):


n = int(input())

i = 1
while n > 0:
    if n == 4 or n == 2 or n == 1:
        break
    i += 1
    if n % 2 == 0:
        n = n / 2
    else:
        n = n*3+1

print(i+3)

Solution (Python):
def f(a, n, i):
    if n % 2 == 0:
        x = n//2
    else:
        x = 3*n+1

    if x in a:
        print(i)
        return
    else:
        a.append(x)
        return f(a, x, i+1)


s = int(input())
a = [s]
f(a, s, 2)

Solution (Python):
import sys
input = sys.stdin.readline

s = int(input())
l = []
l.append(s)
L = 1
for i in range(1000000):

    if s % 2 == 0:
        s = s // 2
    else:
        s = 3*s + 1

    l.append(s)

    if L == len(set(l)):
        print(i+2)
        exit()
    else:
        L = len(set(l))

Solution (Python):
def calc_a(i, s):
    if i == 1:
        return s
    else:
        return f(calc_a(i-1, s))


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


if __name__ == '__main__':
    S = int(input())

    an_list = []

    for m in range(1, 1000001):
        am = calc_a(m, S)
        if am in an_list:
            break
        else:
            an_list.append(am)

    answer = m
    print(answer)

Solution (Python):
s=int(input())
an = []
i = 0
while 1:
  i+=1
  if i == 1:
    an.append(s)
  else:
    if s % 2 == 0:
      s = s//2
    elif s % 2 == 1:
      s = 3*s+1
    an.append(s)
    if an.count(s) == 2:
      break
print(i)

Solution (Python):
s = input()
s = int(s)

def f(n):
  if n%2 is 0:
    return n//2
  return 3*n +1

p = set()
p.add(s)

count = 1
n = s
while True:
  count += 1
  n = f(n)
  if n in p:
    print(count)
    break
  p.add(n)

Solution (Python):
S=int(input())
count=1
for i in range(1000000):
    if S==8:
        print(count+4)
        break
    elif S==4:
        print(count+3)
        break
    elif S==2:
        print(count+3)
        break
    elif S==1:
        print(count+3)
        break
    elif S%2==0:
        S//=2
        count+=1
    else:
        S=S*3+1
        count+=1

Solution (Python):
s = int(input())

a = [s]
for n in range(2, 1000001):
    if a[-1] % 2 == 0:
        a.append(int(a[-1]/2))
    else:
        a.append(3*a[-1]+1)

    try:
        a.index(a[-1], 0, -1)
        print(n)
        break
    except ValueError:
        continue

Solution (Python):
s = int(input())


a = [s]
for n in range(2, 1000001):
    if a[-1] % 2 == 0:
        a.append(int(a[-1]/2))
    else:
        a.append(3*a[-1]+1)

    try:
        a.index(a[-1], 0, -1)
        print(n)
        break
    except ValueError:
        continue

Solution (Python):
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)

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

print(i + 1)

Solution (Python):
def collatz(x):
    if x%2==0:
        return x//2
    else:
        return 3*x+1

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

while(1):
    a.append(collatz(a[-1]))
    if a[-1] in a[:-1]:
        break
    n+=1

print(n)

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

Solution (Python):
n = int(input())
if n <= 2:
    print(4)
    exit()

ls = [n]
m = 0

for i in range(1, 120):
    n = int(n/2) if int(n%2) == 0 else 3*n+1
    ls.append(n)
    if n == 4:
        break

print(ls.index(4)+4)

Solution (Python):
n = int(input())
ls = [n]
m = 0

for i in range(1, 1000001):
    if int(n%2) == 0:
        n = int(n/2)
    else:
        n = 3*n+1

    if n in ls:
        m = i+1  
        break
    ls.append(n)

print(m)

Solution (Python):
import copy
s = int(input())

num_list = [s]
unique_set = set(num_list)
record_list = []
n = 0

for m in range(1000000):
    n += 1
    before = num_list[m]
    if before % 2 == 0:
        after = int(before / 2)
        num_list.append(after)
    else:
        after = int(3 * before + 1)
        num_list.append(after)
    if after in unique_set:
        print(n + 1)
        break
    unique_set.add(after)

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

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


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

while True:
    a.append(fn(a[len(a) - 1]))
    if len(a) != len(set(a)):
        print(len(a))
        break

Solution (Python):
def is_unique(list):
    return len(list) == len(set(list))


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


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

while True:
    a.append(fn(a[len(a) - 1]))
    if not is_unique(a):
        print(len(a))
        break

Solution (Python):
s = int(input())
a = [s]
m = 100000
i = 0
while i<= m :
    if a[i] % 2 == 0:
        s = int(s/2)
    else:
        s = s*3+1
    i += 1
    if s in a:
        print(i+1)
        exit()
    else:
        a.append(s)

Solution (Python):
s = int(input())

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

counter = 0
a = [s]
while True:
    ai = f(a[counter])
    if ai in a:
        break
    a.append(ai)
    counter += 1
print(counter+2)

Solution (Python):
s = int(input())
A = [s]
m = 100000
i = 0
while i <= m:

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

Solution (Python):
s = int(input())

i = 1
m = 1000000
while s != 4 and s != 2 and s != 1:
    
    if s % 2 == 0:
        s = s/2
    else:
        s = 3*s+1
    
    i += 1

print(i+3)

Solution (Python):
s = int(input())
l = [s]
num = s
while True:
    if num % 2 == 0:
        res = num / 2
    else:
        res = num * 3 +1
    l.append(res)
    if len(l) != len(set(l)):
        break
    else:
        num = res
print(len(l))

Solution (Python):
s = int(input())
count = 1
M = [0]*s
M[s-1] = 1
while max(M) < 2:
    if s % 2 == 0:
        s = int(s / 2)
        M[s-1] = M[s-1]+1
    else:
        s = 3 * s + 1
        M.extend([0]*s)
        M[s-1] = M[s-1] + 1
    count = count + 1
print(count)

Solution (Python):
s = int(input())

tmp = {}

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

Solution (Python):
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)

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

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

Solution (Python):
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)

Solution (Python):
s = int(input())
A = []

A.append(s)
a = s
for i in range(10000):
    if a % 2 == 0:
        a = int(a/2)
        A.append(a)
    else:
        a = 3*a+1
        A.append(a)
    if A.count(a) == 2:
        print(len(A))
        break

Solution (Python):
s = int(input())

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

history = {s}
a = s
i = 1
while True:
    i += 1
    a = f(a)
    if a in history:
        print(i)
        break
    history.add(a)

Solution (Python):
s = int(input())

a = []
a.append(s)

for i in range(100000):
  if a[i] % 2 == 0:
    a.append(a[i] // 2)
  else:
    a.append(a[i] * 3 + 1)
  for j in range(i):
    if a[i] == a[j]:
      print(i+1)
      break
  else:
    continue
  break

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

Solution (Python):
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)

Solution (Python):
s = int(input())
a = []
a.append(s)

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

while True:
    s = f1(s)
    if s in a:
        print(len(a)+1)
        break
    else:
        a.append(s)

Solution (Python):
s = int(input())
aa = [s]
for i in range(10000):
	if s%2 == 0:
		s = s//2
	elif s%2 ==1:
		s = 3*s + 1
		
	if s in aa:
		print(i+2)
		break
	
	aa.append(s)

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

Solution (Python):
s = int(input())

alist = []
alist.append(s)
for i in range(1000000):
    if s % 2 == 0:
        a = int(s / 2)
    else:
        a = 3 * s + 1
    s = a
    alist.append(a)
for num in alist:
    if alist.count(num) > 1:
        index = alist.index(num)
        alist.pop(index)
        find = alist.index(num)
        print(find + 2)
        break
    else:
        continue

Solution (Python):
s = int(input())
a = [s]

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

for i in range(1000000):
    an = f(a[i])
    if an in a:
        m = i + 2
        break
    else:
        a.append(an)

print(m)

Solution (Python):
import sys
s = int(input())

ans = 1

while True:
    if s == 1 or s == 2 or s == 4:
        ans += 3
        print (ans)
        sys.exit()
    else:
        if s%2 == 0: 
            s = s//2
        else:
            s = 3 * s + 1
        ans += 1

Solution (Python):
from collections import defaultdict, deque
s = int(input())
d = defaultdict(int)
d[s] = 1
index = 1
while(1):
  if s % 2 == 0:
    s = s // 2
  else:
    s = 3 * s + 1
  index += 1
  if d[s] == 1:
    break
  d[s] = 1
print(index)

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

s = int(input())
a = [0] * 1
a[0] = s
ans = 1

for i in a:
    b = f(i)
    ans += 1
    if b in a:
        break
    a.append(b)
print(ans)