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):


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


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

    res = set()

    m = 1

    while True:
        if s in res:
            print(m)
            return
        res.add(s)
        m += 1
        s = f(s)


if __name__ == '__main__':
    main()

Solution (Python):
def f(n):
    return 3 * n + 1 if n % 2 else n / 2
a = int(input())
li = set([a])
ans = 1
while True:
    ans += 1
    a = f(a)
    if a in li:
        break
    else:
        li.add(a)

print(ans)

Solution (Python):
a = int(input())
time = 0
ch_1 = 2
ch_2 = 2
ch_4 = 2
while True:
    time += 1
    if a == 1:
        ch_1 -= 1
        if ch_1 == 0:
            break
    if a == 2:
        ch_2 -= 1
        if ch_2 == 0:
            break
    if a == 4:
        ch_4 -= 1
        if ch_4 == 0:
            break
    if a % 2 == 0:
        a = a / 2
    else:
        a = a * 3 + 1

print(int(time))

Solution (Python):
import math
import sys
from operator import itemgetter








a = list(range(0))
a.append(int(input()))


ans = 0
while(ans == 0):
	p = 0
	if (a[-1] == 1):
		p = 4
	elif (a[-1] % 2 == 0):
		p = a[-1]//2
	else:
		p = a[-1]*3+1
	
	if (p in a):
		ans = len(a)+1
	else:
		a.append(p)

print(ans)

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

f = lambda n: n // 2 if n % 2 == 0 else 3 * n + 1

while True:
    a.append(f(a[i-1]))
    i += 1

    if a[-1] in a[:-1]:
        break

print(i)

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

s = int(input())
a = [0]
for i in range(1, 1000001):
    if i == 1:
        a.append(s)
    else:
        a.append(f(a[i-1]))
        if a.count(a[-1]) == 2:
            print(i)
            break

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



an = s
n=1
while(True):
    A.append(an)
    if an%2==0:
        
        an=int(an/2)
    else:
        an=an*3+1
    n+=1

    if an in A:
        break

print(n)

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

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

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

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

Solution (Python):



if __name__=='__main__':
  S = int(input())
  f = lambda x: int(x/2) if x%2==0 else int(3*x+1)
  li = [S]
  m = 1
  curr = S
  while True:
    curr = f(curr)
    m += 1
    if curr in li:
      break
    li += [curr]
  print(m)

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

t = [s]
u = 0
v = 0

while u == 0:
    v += 1
    if s % 2 == 0:
        s = s//2
        t.append(s)
    else:
        s = 3*s + 1
        t.append(s)
    for i in range(0,v):
        if s == t[i]:
            u += 1

print(v+1)

Solution (Python):
lis=[0 for i in range(1000000)]
s=int(input())
k=1
lis[s]+=1
while True:
    k+=1
    if s%2==0:
        s=s//2
    else:
        s=3*s+1
    if lis[s]==1:
        break
    lis[s]=lis[s]+1

print(k)

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

while True:
    arr.append(a)
    if a % 2 == 0:
        a = a /2
    else:
        a = 3*a + 1
    
    if a in arr:
        arr.append(a)
        break

print(len(arr))

Solution (Python):
MAX_RANGE = 99999999999

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

def main():
    s = float(input().strip())

    def a(i):
        if i < 1:
            raise ValueError
        elif i == 1:
            return s
        else:
            return f(a(i-1))

    a_s = [None, s]
    for i in range(2, MAX_RANGE):  
        value = a(i)
        for j in range(1, i):  
            if a_s[j] == value:
                print(i)
                return
        a_s.append(value)

    


if __name__ == "__main__":
    main()

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

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

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

a = s
arr = []
count = 1


while not(a in arr):
    arr.append(a)
    if a % 2 == 0:
        a = a / 2
    else:
        a = 3 * a + 1
    count += 1

print(count)

Solution (Python):



a = int( raw_input())

my_list=[]
my_list.append(a)
for i in range (1, 1000000):
    if a % 2 == 1:
        a = a*3 + 1
    else:
        a = a/2

    for j in range( len(my_list) ):
        if a == my_list[j]:
            print i+1
            exit()
    my_list.append( a )

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

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

def ans1(s):
    a = list()
    a.append(s)
    a.append(f(s))

    while True:
        x = f(a[-1])
        if x in a:
            return len(a) + 1
        else:
            a.append(x)

def ans2(s):
    if s == 1:
        return 4
    
    if s == 2:
        return 4
    
    n = s
    i = 0
    while n != 4:
        n = f(n)
        i += 1
    return i + 4

s = int(input())
print(ans2(s))

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

def ans1(s):
    a = list()
    a.append(s)
    a.append(f(s))

    while True:
        x = f(a[-1])
        if x in a:
            return len(a) + 1
        else:
            a.append(x)

s = int(input())
print(ans1(s))

Solution (Python):


s = int(input())
i = 0
A = []
m = 0

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

A.append(s)

while m == 0:
    A.append(f(A[i]))
    if len(A) != len(set(A)):
        m = i+2
    i += 1

print(m)

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

inf = 1
i = 0
list = [s]
while(inf == 1):
    if list[i] % 2 == 1:
        tmp = 3*list[i] + 1
    elif list[i] % 2 == 0:
        tmp = list[i]/2
    for j in list:
        if j == tmp:
            print(i+2)
            inf = 0
            break
    list.append(tmp)
    i += 1

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

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

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

S = [s]
m = 2
i = ABC_B(s)
while(i not in S):
    m = m + 1
    S.append(i)
    i = ABC_B(i)
    
print(m)

Solution (Python):
def cal_a(a_prev):
    """Calculate a[i] when i > 1, according to below formula
    f(n) = n/2 if n is even, and f(n) = 3n + 1 if n is odd.
    """
    return a_prev // 2 if a_prev % 2 == 0 else a_prev * 3 + 1

a_cur = int(input())
found = set()
index = 1
while a_cur not in found:
    found.add(a_cur)
    a_cur = cal_a(a_cur)
    index += 1

print(index)

Solution (Python):
def cal_a(a_prev):
    """Calculate a[i] when i > 1, according to below formula
    f(n) = n/2 if n is even, and f(n) = 3n + 1 if n is odd.
    """
    return a_prev // 2 if a_prev % 2 == 0 else a_prev * 3 + 1

a_cur = int(input())
found = {}
index = 1
while a_cur not in found:
    found[a_cur] = index
    a_cur = cal_a(a_cur)
    index += 1

print(index)

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

l=list()
ans=1

l.append(first)

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

s=set(l)
new=first

while(len(l)==len(s)):
    new=new_num(new)
    l.append(new)
    s=set(l)
    ans+=1
    
print(ans)

Solution (Python):
l = list()
l.append(int(input()))
s = set(l)

while(1):
    if(int(l[-1] % 2) == 0):
        l.append(int(l[-1]/2))
    else:
        l.append(int(l[-1]*3 + 1))
    s = set(l)
    if(len(s) != len(l)):
        print(len(l))
        break

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

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


N = 1000000

a = [0]*N
a[0] = s
for i in range(0,N):
	if a[i]%2 == 0:
		a[i+1] = a[i]/2
	if a[i]%2 == 1:
		a[i+1] = 3*a[i]+1
	
	for j in range(0,i):
		if a[j] == a[i]:
			print(i+1)
			exit()

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


def main():
    s = int(input())
    aa = {s}
    a = f(s)
    for i in range(2, 1000001):
        if a in aa:
            print(i)
            break
        aa.add(a)
        a = f(a)


if __name__ == "__main__":
    main()

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

a=set([s])

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

    if s in a:
        print(len(a)+1)
        break
    else:
        a.add(s)

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

Solution (Python):
import numpy as np
import gc

if __name__ == '__main__':
    s=int(input())
    l=[]
    l.append(s)
    flag=False
    for i in range(1,1000000):
        if s%2:
            s=3*s+1
        else:
            s=s/2
        l.append(s)
        for j in range(0,i):
            if s==l[j]:
                print(i+1)
                del l
                gc.collect()
                flag=True
                break
        if flag:
            break

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

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

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

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

s = int(input())
slist = []
p = calc(s)
slist.append(s)
slist.append(p)
s = p
while slist.count(p) != 2:
    p = calc(s)
    slist.append(p)
    s = p
slist.remove(p)
print(slist.index(p)+2)

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

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

f=1
ans = 1

al = [0 for i in range(10000)]

al[s]=1

while f>0:
    ans+=1
    
    if s%2==0:
        s=s//2
    else:
        s=3*s+1
       
    if al[s]==1:
        f=-1
    else:
        al[s]=1
        
print(ans)

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

s = int(input())
ans= [s]
i = 0
while True:
    s = f(ans[i])
    if s in ans:
        print(i+2)
        break
    else:
        ans.append(s)
        i +=1

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

a = int(input())
A = [a]
while True:
  b = calc(a)
  A.append(b)
  c = A.count(a)
  a = b
  if c == 2:
    break
print(len(A)-1)

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

a_n = int(input())
appeared = {a_n}

i = 1
while True:
    i += 1
    a_n = f(a_n)
    if a_n in appeared:
        print(i)
        break
    appeared.add(a_n)

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

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

Solution (Python):
n = int(input())
i = 1
table = [False for _ in range(10**6)]
while True:
    if table[n]:
        print(i)
        exit()
    else:
        table[n] = True
    if n % 2 == 0:
        n = n // 2
    else:
        n = 3 * n + 1
    i += 1

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


s = int(input())
a = [s]
i = 0
while True:
  s = f(a[i])
  if s in a:
    print(i+2)
    break
  else:
    a.append(s)
    i += 1

Solution (Python):
a = int(input())
i = 1
while(True):
  if a == 4:
    print(i+3)
    break
  elif a == 2 or a == 1:
  	print(i+3)
  	break
  else:
    if a % 2 == 0:
      a //= 2
      i += 1
    else:
      a = a*3 + 1
      i += 1

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

    hoge.append(N)

Solution (Python):
import sys
s=int(input())
a=[s]
t=s
for i in range(1000001):
    if t%2==0:
        t=t//2
    else:
        t=3*t+1
    a.append(t)
    if i>=2 and a[i+1]==a[i-2]:
        print(i+2)
        sys.exit()

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

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

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

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

if s in (1, 2):
    res = 4
else:
    ai = s
    cnt = 1
    while ai != 4:
        ai = f(ai)
        cnt += 1

    res = cnt + 3

print(res)

Solution (Python):
s = int(input())
occs = set()
i = 1

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

Solution (Python):
a = []
a.append(int(input()))
ans = 0
def f_even(x):
        return x//2

def f_odd(x):
        return 3 * x + 1

for i in range(1000000):
        if a[i] % 2 == 0:
                a.append(f_even(a[i]))
        if a[i] % 2 == 1:
                a.append(f_odd(a[i]))
        for t in range(i):
                if a[i+1] == a[t]:
                        ans = i + 2
                        break
        else:
                continue
        break
print(ans)

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

l = [i]
count = 0
f = True
while f:
  if l[-1] % 2 == 0:
    x = l[-1] / 2
  else:
    x = 3 * l[-1] + 1
  
  for y in l:
    if y == x:
      f = False
  l.append(x)

print len(l)

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

from collections import defaultdict
d = defaultdict(lambda: 0)
a = int(input())
d[a] = 1
for i in range(10**6):
    a = f(a)
    if d[a] != 0:
        print(i+2)
        break
    else:
        d[a] = 1

Solution (Python):
S = int(input())
fs = []
fs.append(S)
i = 2
while(True):
    if S % 2 == 0:
        ap = S / 2
    else :
        ap = 3 * S + 1
    for f in fs:
        if ap == f:
            print(i)
            exit()
    
    fs.append(ap)
    S = ap
    i += 1

Solution (Python):
s = int(input())
def f(n):
    return n // 2 if n % 2 == 0 else 3 * n + 1
table = {s}
for i in range(2,1000001):
    t = f(s)
    if t in table:
        print(i)
        break
    table.add(t)
    s = t

Solution (Python):
d = dict()
s = int(input())
d[s] = 1
i = 2
n = s

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

while True:
	c = f(n)
	if c not in d:
		d[c] = 1
	else:
		print(i)
		quit()
	n = c
	i += 1

Solution (Python):


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = INT()
N = 1000000

aN = [0] * (N+1)
aN[0] = s
c = Counter()
c[aN[0]] += 1
for i in range(1, N+1):
    n = aN[i-1]
    if n % 2 == 0:
        aN[i] = n // 2
    else:
        aN[i] = 3*n + 1
    if c[aN[i]] == 0:
        c[aN[i]] += 1
    else:
        print(i+1)
        exit()

Solution (Python):


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

    ft = [False] * 1001010
    ft[s] = True
    n = s
    i = 1
    while True:
        i += 1
        if n % 2 == 0:
            n //= 2
        else:
            n = 3 * n + 1
        if ft[n]:
            break
        ft[n] = True

    print(i)


if __name__ == '__main__':
    main()

Solution (Python):
colatz=[1,2,4]
colatz.append(int(input()))
if colatz[3]==1 or colatz[3]==2 or colatz[3]==4:
    print(4)
else:
    b=3
    while colatz[b]!=4:
        if colatz[b]%2==0:
            colatz.append(colatz[b]/2)
        else: colatz.append(3*colatz[b]+1)
        b=b+1
    print(b+1)

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

Solution (Python):
import sys

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




s = int(input())

x = list()
x.append(s)

for i in range(1000000):
    s = hoge(s)
    
    
    if(s in x):
        print(len(x)+1)
        break
    x.append(s)

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


s = int(input())

already_exist = [s]
a = s
cnt = 1
while f(a) not in already_exist:
    a = f(a)
    already_exist.append(a)
    cnt += 1

print(cnt + 1)

Solution (Python):
s = int(input())
for m in range(1, 1000001):
    for k in range(1, m + 1):
        if k == 1:
            a = s
        else:
            if a % 2 == 0:
                a = int(a / 2)
            else:
                a = 3 * a + 1
    for n in range(1, m):
        if n == 1:
            b = s
            if a == b:
                print(m)
                break
        else:
            if b % 2 == 0:
                b = int(b / 2)
            else:
                b = 3 * b + 1
            if a == b:
                print(m)
                break
    else:
        continue
    break

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

Solution (Python):
s = [int(input())]
if(s[0] in [1,2,4]):
  pass
else:
  while(s[-1]!=4):
    if(s[-1]%2==0):
      s.append(int(s[-1]/2))
    else:
      s.append((s[-1]*3+1))
print(len(s)+3)

Solution (Python):
def calc(_input):
  amari = _input % 2
  if amari == 0:
    return _input/2
  else:
    return _input*3 + 1

a = int(input())
b = []
b.append(a)
i = 1
while True:
  i += 1
  c = calc(a)
  if c in b:
    print(i)
    break
  else:
    b.append(c)
    a = c

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

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

if __name__ == "__main__":
    n = int(input())
    tmpset = set()
    res = 1
    while (n not in tmpset):
        tmpset.add(n)
        n = f(n)
        res += 1
    print(res)

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

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

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

a = s
dic = {a:True}

while True:
    if a & 1:
        a = a*3+1
    else:
        a //= 2

    if a in dic:
        print(len(dic) + 1)
        break

    dic[a] = True

Solution (Python):
import sys
S = int(input())
a_list = []
a_list.append(S)

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

for i in range(10000):
    if i>1:
        tmp=function(a_list[i-2])
        a_list.append(tmp)
        for j in range(i-1):
            if a_list[i-1]==a_list[j]:
                print(i)
                sys.exit()

Solution (Python):
def f(x):
	if x % 2 == 0:
		return x//2
	else:
		return 3*x+1
 
s = int(input())
a = [s]
m = 1
while True:
	t = f(s)
	m += 1
	if t not in a:
		a.append(t)
		s = t
	else:
		break
print(m)

Solution (Python):
def odd(n):
    return int(3 * n + 1)

def even(n):
    return int(n / 2)

num_list = [int(input())]
flag = True
m = 1
delete_num = 0
while(flag):
    if(num_list[-1] % 2 == 0):
        num_list.append(even(num_list[-1]))
    else:
        num_list.append(odd(num_list[-1]))
    num_len = len(num_list)
    delete_num = num_list[-1]
    m += 1
    if(delete_num in num_list[:num_len-1]):
        flag = False
print(m)

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

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

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

a = [s]

i = 2
while True:
    a_i = func(s)
    if a_i in a:
        print(i)
        break
    else:
        i += 1
        a.append(a_i)
        s = a_i

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

while flag:
  if a % 2 == 0:
    a = int(a / 2)
  else:
    a = a * 3 + 1
  for x in list:
    if a == x:
      ans = len(list) + 1
      flag = 0
      break
  list.append(a)
print(ans)

Solution (Python):
n = int(input())
cnt = 1
if n>=3:
    cnt = cnt + 1
elif n==2:
    cnt = cnt + 2
else:
    cnt = cnt + 3
while n != 1:
    if n % 2 == 0:
        n /= 2
    else:
        n = 3*n+1
    cnt += 1
print(cnt)

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

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

print(k+3)

Solution (Python):
def collatz(n, count):
    if (n == 1) or (n == 2) or (n == 4):
        return count + 3
    elif n % 2:
        return collatz(3 * n + 1, count + 1)
    else:
        return collatz(n // 2, count + 1)

s = int(input())
print(collatz(s, 1))

Solution (Python):
s = int(input())
def functionF(n):
    result = n/2 if n % 2 == 0 else 3 * n + 1
    return int(result)

def calc(s):
    array = []
    for i in range(1,1000000):
        if i == 1:
            array.append(s)
        elif i > 1:
            array.append(functionF(array[i - 2]))
            for k in range(1, i):


                if array[i-1] == array[k-1]:
                    print(i)
                    return
calc(s)

Solution (Python):
S=int(input())
a=S
ans=[a]
for i in range(2,1000001):
    if a%2==1:
        a = a*3+1
    else:
        a = a//2

    if a in ans:
        print(i)
        exit()
    else:

        ans.append(a)

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

ans = 0

a = [S]

while True:
    ans += 1
    if a[ans - 1] % 2 == 0:
        an = a[ans - 1] / 2
    else:
        an = a[ans - 1] * 3 + 1
    if an in a:
        break
    a.append(an)

print(ans + 1)

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

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

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


s = int(input())
check = {s: True}
m = 1

while True:
    s = collats(s)
    m += 1

    if s in check:
        print('%d' % m)
        break
    check[s] = True

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

Solution (Python):
s = int(input())
cnt = 0
if s == 3:
  cnt += 5
while(s > 4):
  cnt += 1
  if s % 2 == 0:
    s //= 2
  else:
    s = s * 3 + 1
print(cnt + 4)

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

def f(n):
  if n%2 == 0:
    return n // 2
  else:
    return 3*n + 1
  
A = set()
X = [0] * 1000010

X[1] = S
A.add(S)

for i in range(2,1000001):
  X[i] = f(X[i-1])
  A.add(X[i])
  if i > len(A):
    break
    
print(i)

Solution (Python):
li=list(map(int,input().split()))


def f(n):
    return n/2 if n%2==0 else 3*n+1
a=li[0]
list=[a]
n=2

while True:
    if not f(list[-1]) in list:
        list.append(f(list[-1]))
        n+=1
    else:
        print(n)
        break

Solution (Python):
def solve(s):
    S = set()
    S.add(s)
    i = 1
    a = s
    while True:
        if a % 2 == 0:
            a = a / 2
        else:
            a = 3*a + 1
        if a in S:
            return i+1
        S.add(a)
        i += 1

s = int(input())
print(solve(s))

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

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

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

def check(a, k):    
    for l in range(1, len(a)-k): 
        if a[k] == a[k+l]:
            print(k+l+1)
            return False
    return True

a = [s]
i = 0
flg = 1

while(flg):
    a.append(func(a[i]))
    
    for k in range(len(a)):
        if not check(a, k):
            flg = 0
            break
    i += 1

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

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

a = [s]
i = 0
flg = 1

while(flg):
    a.append(func(a[i]))
    
    for k in range(len(a)):
        for l in range(1, len(a)-k): 
            if a[k] == a[k+l]:
                print(k+l+1)
                break
        else:
            continue
        break
    else:
        i += 1
        continue
    break

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

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

a = [s]
i = 0
flg = 1
while(flg):
    a.append(func(a[i]))
    
    for k in range(len(a)):
        for l in range(1, len(a)-k): 
            if a[k] == a[k+l]:
                print(k+l+1)
                flg = 0
                break
        if flg == 0:
            break
        
    i += 1

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

Solution (Python):
from sys import stdin


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


def main():
    s = int(stdin.readline().rstrip())
    am = s
    tmp = {am}
    for m in range(2, 1000001):
        am = f(am)
        if am in tmp:
            print(m)
            return
        tmp.add(am)


if __name__ == "__main__":
    main()

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

s = int(input())

memo = []

for m in range(1,1000000000000000):
    if m == 1:
        memo.append(s)
    else:
        if f(memo[-1]) in memo:
            print(int(m))
            exit(0)
        else:
            memo.append(f(memo[-1]))

Solution (Python):
s = int(raw_input())
flag = 1
L = [s]
val = s
while flag == 1:
    if val % 2 == 0:
        val /= 2
        val = int(val)
        
    else:
        val = val*3 + 1
        
    if val in L:
        flag = 0
        point = len(L) + 1
        val = int(val)
        print(point)
    L.append(val)

Solution (Python):
n = int(input())
x = set()
cnt = 1
x.add(n)

while True:
    
    cnt += 1
    
    if n%2 == 0:
        n /=2
        
    else:
        n = n * 3 + 1

    if n in x:
        print(cnt)
        break
    else:
        x.add(n)

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

exist = set()
cnt = 1

while True:
    if s not in exist:
        exist.add(s)
        if s % 2 == 0:
            s //= 2
        else:
            s = 3 * s + 1
        cnt += 1
    else:
        print(cnt)
        exit()

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

n = S
a = {S}
for i in range(1, 10**6+1):
    if n%2==0:
        n = n//2
    else:
        n = 3*n+1
    
    if n in a:
        print(i+1)
        exit()
    else:
        a.add(n)

Solution (Python):
a = list(map(int,input().split()))
m=0
ans = 0
while m < 1000001:
	if a[m]%2==0:
		a.append(a[m]//2)
	else:
		a.append(3*a[m]+1)
	for i in range(m):
		if a[i] == a[m]:
			ans = m+1
			break
	if ans > 0:
		break
	m+=1
print(ans)

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


def suuretu(sa, hairetu):
    hairetu.append(float(sa))

    for i in range(len(hairetu)):
        for j in range(len(hairetu)):
            if hairetu[i] == hairetu[j] and i != j:
                print(max(i, j)+1)
                return 

    if sa % 2 == 0:
        suuretu(float(sa)/2, hairetu)
    else:
        suuretu(3*float(sa)+1, hairetu)


suuretu(float(s), a)