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

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement


from operator import itemgetter
from sys import stdin

from operator import mul
from functools import reduce
from collections import Counter

import collections



j=0
k=0
n=3
r=1
a=[0]






"1行1つの整数を入力を取得し、整数と取得する"




"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

for i in number_list:
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''



"正方行列にstr型の値を入力"
'''




'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''











'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''




"aという変数に入っているものを大文字にして出力"

















'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''


'''
def cmb(n,r):
    
    r= min(n-r,r)
    
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    
    
    

    under = reduce(mul, range(1, r+1))
    
    
    
    

    return over // under
    
    
    
    
a = cmb(n, r)

'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''




for i in a.most_common(n):print(i)





 


'''









'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        
        if n % k == 0:
            return False
            
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  

'''

def factorial(x, mod=10**9+7):
    
    
    
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''











def main():
    
    w=1
    j=0
    k=0
    s=int(input())
    if s==1 or s==2:
        print(4)
        sys.exit()
    ans=[]
    anss=[0]*100000
    ans.append(s)
    anss[s]=anss[s]+1
    for i in range(2,10000):
        if s%2==0:
            s=s/2

            anss[int(s)]=anss[int(s)]+1
            
            
            
            if anss[int(s)]>=2:
            
                print(i)
                sys.exit()
        else:
            s=3*s+1
            
            
            anss[int(s)]=anss[int(s)]+1
            
            if anss[int(s)]>=2:
            
                print(i)
                sys.exit()

    
    
    
    
    
    DP = np.zeros(w+1, dtype=int)
    exdp=np.zeros((3,4)) 
    
    
    
        
        
    
    
        
        
    


    "1行1つの整数を入力を取得し、整数と取得する"
    
    
    "12 21 332 とか入力する時に使う"
    "1行に複数の整数の入力を取得し、整数として扱う"
    
    


    
    
    
    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]
    

    ls = ["a", "b", "c", "d", "e"]


    
    

    
    

    
    
    
    
    
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Solution (Python):

import sys


def solve(s: int):

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

    d = set()
    ai = s
    i = 1
    while ai not in d:
        d.add(ai)
        ai = f(ai)
        i += 1

    print(i)


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())
ans = []

for i in range(2, 1000002):
  ans.append(s)
  if s % 2 == 0:
    s /= 2
  else:
    s = 3 * s + 1
  if s in ans:
    print(i)
    break

Solution (Python):
s = int(input())
hashSet = set([s])

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

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

    res = [int(input())]
    idx = 0
    while True:
        i = func(res[idx])
        if i not in res:
            res.append(i)
        else:
            print(len(res) + 1)
            break
        idx += 1


resolve()

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

s = int(input())

reached = []
def F(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1

counter = 1
a = []
a.append(s)
while True:
    counter += 1
    tmp = F(a[-1])
    if tmp in a:
        ans = counter
        break
    a.append(tmp)

print(ans)

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

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

Solution (Python):


S=int(input())
List=[S]

i=1
while 1==1:
    i+=1
    if S%2==0:
        S=S/2
    else:
        S=(S*3)+1
    List.append(S)
    
    if len(List) != len(set(List)):
        break
    
    
print(i)

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

a = []
f={}
a.append(s)

cnt =0
n=0

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

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

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

print(ans)

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

A = [s]
n = (s/2 if s%2==0 else 3*s+1)
ans = 1

while n not in A:
    ans +=1
    A.append(n)
    n = (n/2 if n%2==0 else 3*n+1)

print(ans+1)

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

A = [s]
n = (s/2 if s%2==0 else 3*s+1)
ans = 1

while n not in A:
    ans +=1
    A.append(n)
    if n%2 == 0:
        n = n/2
    else:
        n = 3*n+1

print(ans+1)

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

appear = {s:0,}
i = 0
while True:
    i += 1
    if s%2 == 0:
        s //= 2
    else:
        s = 3*s + 1
    if s in appear:
        break
    else:
        appear[s] = i

print(i+1)

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

a = int(input())
A = set()
ans = 1
while a not in A:
  A.add(a)
  ans += 1
  a = f(a)

print(ans)

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

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

fd = {s:1}
for i in range(2,10**10) :
  s = f(s)
  if s in fd :
    print(i)
    break
  else :
    fd[s] = 1

Solution (Python):
s = int(input())
S = [s]
cnt = 1

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

Solution (Python):
def f(s):
    cnt = 0
    st = set()

    cnt += 1
    st.add(s)

    while True:
        cnt += 1

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

        if tmp in st:
            break

        st.add(tmp)
        s = tmp
    return cnt


s = int(input())
ans = f(s)
print(ans)

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

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

seen = [s]

while True:
	n = collatz(s)
	if n in seen:
		break
	seen.append(n)
	s = n

print(len(seen) + 1)

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

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

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

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

if s == 1 or s == 2 or s ==4 :
 print(4)

else:
 i = 2
 while s > 1:
  if s%2==0:
   s=s/2
  else:
   s=3*s+1
  i += 1
 print(i)

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

print(i+1)

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

Solution (Python):
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [str(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))
def f(n):
    
    if n%2 == 0:
        return n//2
    else:
        return 3*n + 1
if __name__ == "__main__":
    n = i()
    c = 0
    cnt = 1
    l = [n]
    
    while c < 2:
        n = f(n)
        cnt += 1
        if n in l:
            print(cnt)
            break
        l.append(n)

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

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

Solution (Python):
S=int(input())
arr=[]
h={}
def calc(n):
  if n % 2 ==0:
    return n/2
  else:
    return 3*n+1

for i in range(1000000):
  if i == 0:
    a = S
  else:
    a = calc(arr[i-1])
  if a in h:
    print(i+1)
    exit(0)
  arr.append(a)
  h[a]=i+1

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(100000):
    x = f(a[i])
    if(x in a):
        print(i + 2)
        exit()
    a.append(x)

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

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

Solution (Python):

s = int(input())

a = [0] * 1000000

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

    if a[i] in set(a[:i-1]):
        print(i+1)
        break

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

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7


va=I()
if va==1:
    print(4)
    sys.exit()
if va==2:
    print(4)
    sys.exit()
if va==4:
    print(4)
    sys.exit()
else:
    for i in range(1,10**6+10):
        if va%2==0:
            va=va//2
        else:
            va=3*va+1
        if va==4:
            print(i+4)
            sys.exit()

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

Solution (Python):

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

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

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

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

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

ans = 0
set1 = set()
while True:
    if s in set1:
        print(ans+1)
        exit()
    else:
        set1.add(s)
        s = f(s)
        ans += 1

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

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

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

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

while 1 > 0:
    a += 1
    if s % 2 == 0:
        t = s //2
    else:
        t = 3 * s + 1
    if t in ls:
        print(a)
        break
    else:
        s = t
        ls.append(s)

Solution (Python):
def f(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n + 1
s = int(input())
ans = [s]
cnt = 0
while True:
    ans.append(f(s))
    if f(s) == 4:
        cnt += 1
        if cnt == 2:
            break
    s = f(s)

for i in range(len(ans)-1):
    for j in range(i+1, len(ans)):
        if ans[i] == ans[j]:
            print(j+1)
            break
    else:
        continue
    break

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

Solution (Python):
s=int(input())
a=set()
a.add(s)
prev=s
for m in range(2,10**6+1):
    
    if prev%2:
        if prev*3+1 in a:
            print(m)
            exit()
        else:
            prev=prev*3+1
        a.add(prev)
    else:
        if prev//2 in a:
            print(m)
            exit()
        else:
            prev=prev//2
        a.add(prev)

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

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

i = 1
hist = {s:i}
while 1:
  s = f(s)
  i+=1
  if s in hist:
    print(i)
    break
  else:
    hist[s]= i

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

Solution (Python):
a = []
a.append(int(input()))
if a[0] in {1, 2}:
    s = a[0]
else:
    s = 4
cnt_s = 0
for i in range(10**6):
    if a[i] == s:
        cnt_s += 1
    if cnt_s == 2:
        break

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

Solution (Python):
s=int(input())
a=[0,s]
i=1
while 1:
    i+=1
    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:
        print(i)
        exit()

Solution (Python):
from collections import defaultdict
a = int(input())
idxs = defaultdict(int)
idxs[a] = 1
i = 1
ans = None
while True:
  i += 1
  if a % 2 == 0:
    a //= 2
  else:
    a = 3 * a + 1
    
  if not idxs[a]:
    idxs[a] = i
  else:
    ans = i
    break

print(ans)

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

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

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

Solution (Python):
def resolve():
    s=int(input())
    l=[s]
    for i in range(10**6):
        if l[i]%2==0:
            l.append(l[i]//2)
            if (len(set(l)))!=len(l):
                print(i+2)
                break
        else:
            l.append(3*l[i]+1)
            if (len(set(l)))!=len(l):
                print(i+2)
                break
resolve()

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

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

print(ans)

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

print(len(ans)+1)

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

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

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

def f(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n+1
a = [s]
i = 1
while True:
    i += 1
    p = f(a[-1])
    if p in a:
        print(i)
        break
    a.append(p)

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

l = list()
l.append(s)

num = s

while 1:
    if num % 2 == 0:
        num = num // 2
    else:
        num = 3*num + 1
    if num in l:
        break
    l.append(num)

print(len(l)+1)

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

la = [s]

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

Solution (Python):
def solve():
   N = int(input())
   table = [False] *1000000
   table[N] = True
   count = 1
   while True:
       if N&1:
           N = 3*N + 1
       else:
           N = N//2
       count += 1
       if not table[N]:
           table[N] = True
       else:
           print(count)
           break

if __name__ == '__main__':
    solve()

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

Solution (Python):


import sys

s=int(input())

if s==1 or s==2:
    print(4)
else:
    cnt=1
    tmp=s
    while True:
        if tmp==4:
            print(cnt+3)
            break
        cnt+=1
        if tmp%2==0:
            tmp=tmp/2
        else:
            tmp=tmp*3+1

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

Solution (Python):
x=set()
s=int(input())
ans=0
while True:
    ans+=1
    if s in x:
        print(ans)
        break
    x.add(s)

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

Solution (Python):
s = int(input())
v = [False] * (10**6 + 1)

v[s] = True
a = s

for i in range(2, 10**6+1):
    if a % 2 == 0:
        a = a // 2
    else:
        a = 3 * a + 1

    if v[a]:
        break
    else:
        v[a] = True

print(i)

Solution (Python):
def I(): return int(input())
N = I()
ans = 0
a = [N]
set_a ={N}
i = 0
while 1:
    i += 1
    if a[i-1]%2==0:
        a.append(a[i-1]//2)
    else:
        a.append(a[i-1]*3+1)
    if a[i] in set_a:
        print(i+1)
        break
    else:
        set_a.add(a[i])

Solution (Python):

import numpy as np
import sys

input = sys.stdin.readline

s = int(input())

if s == 1 :
    n = 2
elif s == 2:
    n = 1
else:
    n = 3

ans = 1

while s != 4:
    if s%2 == 0 :
        s = s/2
    else:
        s = 3*s + 1
    
    
    ans+=1


print(ans+n)

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

d = {}

n = 1

while s not in d:
    d[s] = n
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
    n += 1

print(n)

Solution (Python):
from collections import defaultdict
d = defaultdict(int)
import sys
sys.setrecursionlimit(10**8)
def f(n,i):
  d[n]+=1
  if d[n]==2:
    return i
  if n%2==0:
    x=n//2
  else:
    x=3*n+1
  return f(x,i+1)
print(f(int(input()),1))

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

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


a_list = [s]
i = 1
while True:
    if i == 1:
        pass
    else:
        n = a_list[i-2]
        a_list.append(func(n))
    i += 1
    if len(a_list) != len(set(a_list)):
        print(len(a_list))
        break

Solution (Python):
import numpy as np
n = int( input())

def f(num):
  if num%2 ==0:
    return n/2
  else :
    return 3*n+1
x=  [n]
a = 1
while True:
  n = f(n)
  if n in x :
    a+=1
    break
  else :
    x.append(n)
    a +=1
print(a)

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

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

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

List = []
List.append(s)

if s==1 or s==2 or s==4:
    print(4)

else:
    for i in range(1000000):
        if List[i]%2 == 0:
            List.append(List[i]/2)
        else:
            List.append(List[i]*3+1)
        if List[i+1] == 4:
            Answer=i+5
            break

    print(Answer)

Solution (Python):
import math
import sys


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


s = int(input())
list = [s]
x = s
cnt = 1
while(True):
    x = f(x)
    cnt += 1
    if x in list:
        break
    else:
        list.append(x)

print(cnt)

Solution (Python):
s = int(input())
apple = []
count = 0

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

while s not in apple:
    apple.append(s)
    s = func_1(s)
    count += 1
else:
    print(count + 1)

Solution (Python):
s=int(input())
l=[]
cnt=0
while True:
    if s not in l:
        l.append(s)
        cnt +=1
    else:
        print(cnt+1)
        break

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

Solution (Python):


def solve():

    S = int(input())
    list = []
    list.append(S)

    i = 0

    while True:
        s = list[i]

        v = 0

        if s % 2 == 0:
            v = s//2
            if v in list:
                print(i+2)
                exit()
            list.append(v)
        else:
            v = 3*s+1
            if v in list:
                print(i+2)
                exit()
            list.append(v)

        i += 1


if __name__ == "__main__":
    solve()

Solution (Python):
s = int(input())
m = 1
if s == 1:
    print(4)
elif s == 2:
    print(4)
else:
    while 1:
        if s == 1:
            break
        if s % 2 == 0:
            s = s // 2
            m += 1
        else:
            s = 3*s+1
            m += 1
    m += 1
    print(m)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

s = INT()
ans = 4
while not (s == 4 or s == 2 or s == 1):
    if s % 2 == 0:
        s //= 2
    else:
        s = s * 3 + 1
    ans += 1
print(ans)

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


check = [False for _ in range(1000005)]

s = int(input())
cnt = 1
check[s] = True
while (1):
    s = f(s)
    cnt += 1
    if check[s]:
        print(cnt)
        exit()
    else:
        check[s] = True

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def F(x):
    if x&1:
        return 3*x + 1
    else:
        return x // 2

S = ir()
se = set()
dp = S; se.add(dp)
count = 1
while True:
    count += 1
    dp = F(dp)
    if dp in se:
        break
    se.add(dp)

print(count)

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

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

count = 1

x = [0] * 1000000
x[s] = 1
while True:
    if s % 2 == 0:
        s = s / 2
    else:
        s = 3 * s + 1
    count += 1
    if x[int(s)] == 1:
        print(count)
        break
    else:
        x[int(s)] = 1

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = INT()
a = [s]
i = 0
p = len(set(a))-1

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

print(i+1)

Solution (Python):
s = int(input())
A = []
B = zip(A)
i = s
count = 0
while i not in A:
    A.append(i)
    if i % 2 == 0:
        i /= 2
    else:
        i = 3*i+1
    count += 1

print(count+1)