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):
import sys
sys.setrecursionlimit(100000)

s=int(input())
seen=set()
a=s
seen.add(a)
idx=1

while True:
    if a%2==0:
        a//=2
    else:
        a=3*a+1
    idx+=1
    if a in seen:
        print(idx)
        exit()
    seen.add(a)

Solution (Python):


s_int = int(input().strip())

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

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

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

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

pre = [s]

for i in range(2,10**6+1) :
    if s%2 == 0 :
        s //= 2
    else :
        s = 3*s + 1
    if s in pre :
        print(i)
        exit()
    else :
        pre.append(s)

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

memo = []

for i in range(1,1000000*3+1):
    if i == 1:
        memo.append(n)

    if memo[-1]%2 == 0:
        a = memo[-1]//2
    else:
        a = (memo[-1]*3)+1

    if a in memo:
        print(i+1)
        exit()
    else:
        memo.append(a)

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

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

def make_a(i):
    if a[i-1] % 2 == 0:
        ai = a[i-1] // 2
        if ai in a:
            print(i + 1)
            exit()
        else:
            a.append(ai)
    else:
        ai = 3 * a[i-1] + 1
        if ai in a:
            print(i + 1)
            exit()
        else:
            a.append(ai)
    return make_a(i+1)

make_a(1)

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

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

from collections import defaultdict
d = defaultdict(int)
d[a] += 1


for i in range(2, 1000001):
    
    if a % 2 == 0:
        a //= 2
    else:
        a = 3*a + 1
        
    if d[a] == 1:
        print(i)
        break
    else:
        d[a] += 1

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

_set = set()
_set.add(S)

_ = 10**7
cnt = 1
before_num = S

for n in range(_):
  cnt += 1
  _ = before_num
  
  if _%2==0:
    this_num = _/2
  else:
    this_num = 3*_+1
  _set.add(this_num)
  
  if len(_set) < cnt:
    ans = cnt
    break
  
  before_num = this_num
    
print(ans)

Solution (Python):
def fanc(x):
  if x%2==0:
    return x//2
  else:
    return 3*x+1
  
x=int(input())
l=[]
i=1
while not x in set(l):
  l.append(x)
  x=fanc(x)
  i+=1
print(i)

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

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

cnt = 1
while(True):
  if s == 1 or s == 2 or s == 4:
    ans = cnt+3
    break
  s = f(s)
  cnt += 1

print(ans)

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):
s = int(input())
a = set([s])
i = 1

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

print(i+1)

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

Solution (Python):

def f(n):
    if n%2==0:
        return n//2
    else:
        return 3*n+1
    
s=int(input())
A=[0,s]
for i in range(2,10**7+1):
    x=f(A[i-1])
    if x in A:
        print(i)
        exit()
    A.append(x)

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

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

S = set()
S.add(a)
c = 2
while True:
  a = f(a)
  if a in S:
    break
  else:
    S.add(a)  
  c += 1

print(c)

Solution (Python):
import sys

s = int(input())

sequence = [s] * 1000000

i = 1
while True:
    n = sequence[i - 1]
    if n % 2 == 0:
        sequence[i] = sequence[i - 1] // 2
    else:
        sequence[i] = 3 * sequence[i - 1] + 1

    for j in range(i):
        if sequence[i] == sequence[j]:
            print(i + 1)
            sys.exit()
    i += 1

Solution (Python):
s=int(input())
a=[0]*10**6
a[0]=s
def f(n):
    if n%2==0:
        return int(n/2)
    else:
        return 3*n+1
for i in range(1,10**6):    
    a[i]=f(a[i-1])
    if a[i] in a[:i]:
        ans=i+1
        break
print(ans)

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

if s==1:
    print(4)
elif s==2:
    print(4)
else:
    no=1
    cnt=0
    if s==4:
        cnt+=1
    for i in range(1000000):
        no+=1
        if s%2==0:
            s=int(s/2)
        else:
            s=3*s+1
        if s==4:
            cnt+=1
        if cnt==2:
            break
    print(no)

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

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

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

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

d = dict()

for i in range(1000000):
    if s in d:
        print(i+1)
        break
    else:
        d[s] = 0
        if s % 2 == 0:
            s = s//2
            continue
        else:
            s = 3*s + 1
            continue

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

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


S=[];A=[];f=-1
if s==1:
  print(4)
elif s==2:
  print(4)
elif s==3:
  print(9)
elif s==4:
  print(4)
else:
  S.append(s)
  i=1;p=-1
  while p!=4:
    if S[i-1]%2==0:
      S.append(S[i-1]//2)
      
    else:
      S.append(S[i-1]*3+1)
      
    p=S[-1]
    i=i+1
  
  for i in range(len(S)-1):
    for j in range(i+1,len(S)):
      if S[i]==S[j]:
        f=1
        print(j)
        break
  if f==-1:
    print(len(S)+3)

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


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


a = [0, s]
cnt = 1
while True:
    res = func(a[cnt])
    cnt += 1

    if res in a:
        break

    a.append(res)

print(cnt)

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

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

Solution (Python):
s = int(input())
record = [s]
count = 1

while (True):
    if (s % 2) == 0:
        s = s // 2
    else:
        s = 3 * s + 1
    
    record.append(s)
    count += 1
    
    if (record.count(s) == 2):
        print(count)
        exit()

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

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

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

a = []
for i in range(1000000):
    if s in a:
        print(i+1)
        break
    else:
        a.append(s)
        s = f(s)

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

for i in range(1000000):
    if a[i-3]==a[i]:
        print(i+1)
        break

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

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

s=int(input())
a=[s]
for i in range(2,10**10):
    s=f(s)
    if s in a:
        print(i)
        exit()
    a.append(s)

Solution (Python):
s = int(input())
nums = {s}
leng= 1
count = 1
while True:
    count += 1
    if s%2 == 0:
        s /= 2
    else:
        s = s*3+1
    nums.add(s)
    if len(nums) == leng:
        print(count)
        quit()
    else:
        leng = len(nums)

Solution (Python):
def f(n):
    if n %2 == 0:return n//2
    else: return 3*n+1
s = int(input())
nums = [s] + [0]*10**6
for i in range(1000000):
    if f(nums[i]) in nums:
        print(i+2)
        break
    else:
        nums[i+1] = f(nums[i])

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

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

l = [s]

def f(n):
    if n % 2 == 0:
        a = n // 2
    else:
        a = 3 * n + 1
    if a in l:
        return
    l.append(a)
    f(a)

f(s)
print(len(l) + 1)

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

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

lis = [s]
now = s
for i in range(1000000):
    next = make_col(now)
    if next in lis:
        print(i+2)
        break
    else:
        lis.append(int(next))
        now = next

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

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

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

a = []
a.append(s)

for i in range(1000000):
    tmp = f(a[i])
    if tmp in a:
        ans = i
        break
    else:
        a.append(tmp)

print(ans+2)

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

Solution (Python):




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

    result = []

    while S not in result:
        result.append(S)
        if S % 2 == 0:
            S = S // 2
        else:
            S = 3 * S + 1

    print(len(result) + 1)


if __name__ == "__main__":
    main()

Solution (Python):
s=int(input())
def f(k):
  if k%2==0:
    return k//2
  else:
    return 3*k+1
n=1
li=[]
if s==1 or s==2 or s==4:
  li.append(s)
while True:
  s=f(s)
  n+=1
  if s==1 and s not in li:
    li.append(s)
  elif s==2 and s not in li:
    li.append(s)
  elif s==4 and s not in li:
    li.append(s)
  elif s==1 and s in li:
    print(n)
    exit()
  elif s==2 and s in li:
    print(n)
    exit()
  elif s==4 and s in li:
    print(n)
    exit()

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

s = int(input())

box = [-1]*(int(1e6+1))

box[s] = 1

i = 1

while 1:
    if box[collaz(s)] == 1:
        print(i+1)
        break
    else:
        box[collaz(s)] = 1
        s = collaz(s)
        i += 1

Solution (Python):
def collatz(n):
    if n%2==0:
        return int(n/2)
    else:
        return 3*n+1
    
a=int(input())
cnt=1
if a==1 or a==2:
    ans=cnt+3
else:
    while a !=4:
        a=collatz(a)
        cnt+=1
    ans=cnt+3  

print(ans)

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

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

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

while True:
	
	if i == 1:
		a.append(s)
	
	else:

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

	
	if a.count(a[-1]) >= 2:
		print(max([i for i, x in enumerate(a) if x == a[-1]]) + 1)
		exit()

	i += 1

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

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

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

    val = s
    ls = set([val])
    for m in range(2, 1000001):
        val = calc(val)
        if val in ls:
            print(m)
            exit()
        else:
            ls.add(val)
    
if __name__ == '__main__':
    main()

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

a = set()
n = s
c = 1

while n not in a:
    a.add(n)
    c += 1
    if n % 2 == 0:
        n //= 2
    else:
        n = 3 * n + 1 


print(c)

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


s = int(input())
As = [s]
num = collatz(s)
while num not in As:
    As.append(num)
    num = collatz(num)

print(len(As) + 1)

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

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

tmp = [s] + [0]*(10**6 - 1)
for i in range(1,10**6+1):
    if tmp[i-1]&1:
        tmp[i] = 3*tmp[i-1]+1
    else:
        tmp[i] = tmp[i-1]//2
    if tmp.count(tmp[i]) == 2:
        print(i+1)
        exit()

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

ans=[s]
for i in range(1000000):
  temp = func(ans[-1])
  try:
    t = ans.index(temp)
    print(i + 2)
    break
  except:
    ans.append(temp)

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

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

Solution (Python):
s = int(input())
a = {s}
a_i = s
def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1
ans = 1
for _ in range(10 ** 6 + 1):
    a_i = f(a_i)
    ans += 1
    if a_i in a:
        print(ans)
        break
    else:
        a.add(a_i)

Solution (Python):
s=int(input())
a=[-12345]*100000
for i in range(100000):
    
    a[i]=s
    if s%2==1:
        s=s*3+1
    else:
        s=s/2

    if s in a:
        print(i+2)
        break

Solution (Python):
s = int(input())
a = {s}
a_i = s


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


ans = 1
for _ in range(10**6+1):
    a_i = f(a_i)
    ans += 1
    if a_i in a:
        print(ans)
        break
    else:
        a.add(a_i)

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

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

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

Solution (Python):

s = int(input())

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

i = 0
flag = True
while flag:
    for j in range(i):
        if a[i] == a[j]:
            ans = i + 1
            flag = False
            break
    i += 1
print(ans)

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

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

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

Solution (Python):
s=int(input())
n=10**6
hist=[0]*(n+1)

a=s
ans=0
for i in range(n):
    if hist[a]==0:
        hist[a]+=1
    else:
        ans=i+1
        break
    if a%2==1:
        a=3*a+1
    else:
        a=a//2
print(ans)

Solution (Python):
def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3*n + 1
s = int(input())
a = [0]
a.append(s)
for i in range(2,10**7+1):
    x = a[-1]
    y = f(x)
    if y in a:
        print(i)
        break
    a.append(y)

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

while True:
  num.append(s)
  ans += 1
  if s%2 == 1:
    s = 3*s + 1
  else:
    s = s/2

  if s in num:
    print(ans)
    exit(0)

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

while True:
    if a[-1] % 2 == 0:
        num = a[-1] / 2
    else:
        num = a[-1] * 3 + 1

    if num in a:
        print(len(a) + 1)
        break
    else:
        a.append(num)

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

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

Solution (Python):
import sys
s = int(input())
def collatz(n):
    if n%2 == 0:
        return (n//2)
    else:
        return 3*n+1
A = [s]
while True:
    A.append(collatz(A[-1]))
    for i in range(0,len(A)):
        for j in range(0,len(A)):
            if A[i] == A[j] and i!= j:
                print(j+1)
                sys.exit(0)

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

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

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

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

if s==1 or s==2 or s==4:
  print(4)
  exit()
for i in range(1000000):
  s = f(s)
  if s==4:
    print(i + 5)
    break

Solution (Python):
import sys

s = int(input())

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

a = list()
a.append(s)
i = 1
r = 0
g = 0
while 1:
    n = f(a[i-1])
    for r in a:
        if r==n:
            print(i+1)
            sys.exit()
            
            
    a.append(n)
    i=i+1

Solution (Python):

inf = 10**6+1
visit = [0]*inf
s = int(input())
visit[s] = 1
cnt = 1
while True:
    cnt += 1
    if s % 2: s = s*3 + 1
    else: s = s // 2
    if visit[s]:
        print(cnt)
        exit(0)
    else: visit[s] = 1

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

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

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

Solution (Python):
S = int(input())
se = {S}
x = S
for i in range(2, 1000001):  
  if x%2 == 0:
    x = x//2
  else:
    x = 3*x+1
  if x in se:
    print(i)
    exit()
  se.add(x)

Solution (Python):
X = int(input())
list=[X]
count=1
while count <= 1000000:
    if X%2 == 0:
        X=X/2
    else:
        X=3*X+1
    count+=1
    if list.count(X) ==1:
        print(count)
        break
    list.append(X)

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

Solution (Python):
import sys
import math
import itertools

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

Solution (Python):
import sys
from bisect import bisect_left, insort_left

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)


def main():
    s = INT()

    a = s
    l = [a]
    for i in range(1000000):
        a = 3*a + 1 if a % 2 else a//2

        if bisect_left(l, a) == len(l):
            l.append(a)
        elif l[bisect_left(l, a)] == a:
            print(i + 2)
            sys.exit()
        else:
            insort_left(l, a)


if __name__ == '__main__':
    main()

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

def ff(a1, history, n):
    a2 = f(a1)
    n += 1
    if a2 in history:
        return n

    history.append(a2)

    return ff(a2, history, n)

s = int(input())
print(ff(s,[s],1))

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


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = {n}
flg = 1
i = 1
while flg:
  if n % 2 == 0:
    n //= 2
  else:
    n = 3*n + 1
  if n in s:
    print(i+1)
    flg = 0
  else:
    s.add(n)
  i += 1

Solution (Python):


s = int(input())

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

a = [s]

i = 2
while True:
    b = func(a[i-1-1])
    if b in a:
        break
    a.append(b)
    i += 1
    
print(i)

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

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

a = [s]

i = 2
while True:
    b = func(a[i-1-1])
    if b in a:
        break
    a.append(b)
    i += 1
    
print(i)

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

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

print(len(cnt))

Solution (Python):
s = int(input())
list = [[0]*1000000]
list[0] =s
key = 0
for i in range(1,100000):
    if (list[i-1])%2 == 0:
            key = (list[i-1])//2
            if key in list:
                print(i+1)
                exit()
            else:
                list.append(key)

    else:
            key = 3*(list[i-1])+1
            if key in list:
                print(i+1)
                exit()
            else:
                list.append(key)

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

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

def odd(n):
    n = (3 * n) + 1
    return n

results = [S]
while True :
    if S % 2 == 0:
        S = even(S)
    else :
        S = odd(S)
    if S in results:
        results.append(S)
        break
    else :
        results.append(S)

print(len(results))

Solution (Python):
def check(s,i):
    if s in l:
        return i
    if s % 2 == 0:
        l.append(s)
        ans = check(s//2, i+1)
    else:
        l.append(s)
        ans = check(3 * s + 1, i + 1)
    return ans
s = int(input())
l = [s]
ans = 0
if s % 2 == 0:
    ans = check(s//2,2)
else:
    ans = check(3 * s + 1,2)
print(ans)

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

calRList = []

calRList.append(a1)

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

Solution (Python):
s = int(input())
nums = set()
a = [0] * 1000001

a[0] = s
nums.add(s)
for i in range(1, 1000002):
    if a[i - 1] % 2 == 0:
        a[i] = a[i - 1] // 2
    else:
        a[i] = a[i - 1] * 3 + 1
    if a[i] in nums:
        ans = i + 1
        print(ans)
        break
    else:
        nums.add(a[i])

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

lis = []

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

    if s in lis:
        print(len(lis)+1)
        flag = False

Solution (Python):
s = int(input())
a = {s}
ans = 1

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

    ans += 1

    if s in a:
        break
    else:
        a.add(s)

print(ans)

Solution (Python):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

s = ni()

def collatz(x, i):
    if x <= 1:
        return i
    if x % 2 == 0:
        return collatz(x / 2, i + 1)
    else:
        return collatz(3 * x + 1, i + 1)

if s <= 2:
    print(4)
else:
    print(collatz(s, 1) + 1)

Solution (Python):
s = int(input())
d = {}
cnt = 1
while True:
    if s in d:
        print(cnt)
        break
    d[s] = cnt
    if s % 2:
        s = s * 3 + 1
    else:
        s = s//2
    cnt += 1

Solution (Python):
def examA():
    L = LI(); L.sort()
    ans = L[0]*L[1]//2
    print(ans)
    return

def examB():
    def fun(s):
        if s%2==0:
            return s//2
        else:
            return s*3+1
    S = I()
    d = defaultdict(bool)
    d[S] = True; cur = 1
    while(True):
        cur +=1
        S = fun(S)
        if d[S]:
            break
        d[S] = True
    print(cur)
    return

def examC():
    return

def examD():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,ALPHABET, _ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 1e-9
alphabet = [chr(ord('a') + i) for i in range(26)]
ALPHABET = [chr(ord('A') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

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

Solution (Python):
a = [list(map(int, s.split()))[0] for s in open(0)][0]

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

cnt = 1
li = [a]
while True:
    a = fn(a)
    cnt += 1
    if a in li:
        print(cnt)
        break
    li.append(a)

Solution (Python):
s=int(input())
l=[s]
i=0
ans="False"
while ans=="False":
	if l[i]%2==0:
		l.append(l[i]//2)
		i+=1
		if l[i] in l[:i-1]:
			ans="True"
	else:
		l.append(l[i]*3+1)
		i+=1
		if l[i] in l[:i-1]:
			ans="True"
print(len(l))

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

Solution (Python):
s = int(input())
d = {s:1}
def func(n,i):
    tmp = 0
    if n%2 == 0:
        tmp = n//2
    else:
        tmp = 3*n + 1
    if tmp in d:
        return i+1
    else:
        d[tmp] = 1
        return func(tmp,i+1)
print(func(s,1))

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

    if a not in v:
        v.append(a)
    else:
        break;

print(i)

Solution (Python):
a = int(input())
v = {}
v[a] = True
ans = 1
while True:
    ans += 1
    if a % 2 == 1:
        a = (a * 3) + 1
    else:
        a = (a//2)
    if v.get(a): 
        break
    else:
        v[a] = True
 
print(ans)

Solution (Python):
a = int(input())
v = []
v.append(a)
t = 1
i = -1
while t == 1:
    i += 1
    if v[i] % 2 == 1:
        b = (v[i] * 3) + 1
        if b not in v: 
            v.append(b)
        else:
            v.append(b)
            break;
            ans = i
    else:
        b = (v[i]//2)
        if b not in v:
            v.append(b)
        else:
            v.append(b)
            break;
            ans = i

print(i+2)

Solution (Python):

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

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

print(i)

Solution (Python):
s = int(input())
history = {}

ans = 1
n_tmp = s
while True:
  if history.setdefault(str(n_tmp), 0) > 0:
    break
  else:
    history[str(n_tmp)] = 1
  
  ans += 1
  if n_tmp % 2 > 0:
    n_tmp = 3 * n_tmp + 1
  else:
    n_tmp = n_tmp // 2
    
print(ans)

Solution (Python):
def p_b():
    s = int(input())
    u = {s}
    for i in range(1, 1000001):
        if s & 1 == 0:
            s //= 2
        else:
            s = 3 * s + 1
        if s in u:
            print(i + 1)
            exit()
        else:
            u.add(s)

            
p_b()

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

while(1):
   if (a[-1] % 2 == 0):
      fn = int(a[-1] / 2)
   else:
      fn = 3 * a[-1] + 1

   if(fn in a):
      print(len(a) + 1)
      break
   else:
      a.append(fn)

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

print(cnt+1)

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

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

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

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

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