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
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def gcd(a, b):
    if a == 0:
        return b
    if b == 0:
        return a

    if a > b:
        return gcd(b, a % b)
    else:
        return gcd(a, b % a)


def gcd_multi(nums):
    if len(nums) == 0:
        return 0
    if len(nums) == 1:
        return nums[0]

    ret = gcd(nums.pop(), nums.pop())
    while len(nums) > 0:
        ret = gcd(ret, nums.pop())
    return ret


def solve(inputs):
    [S] = string_to_int(inputs[0])
    current = S
    appeared_set = {current}
    i = 1
    while 1:
        i += 1
        if current % 2 == 0:
            current /= 2
        else:
            current = 3 * current + 1

        if current in appeared_set:
            return i

        appeared_set.add(current)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

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

seen = set([s])
i = 2
while collatz(s) not in seen:
    s = collatz(s)
    seen.add(s)
    i += 1
print(i)

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

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

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

a_list = [int(input())]

count = 0
while True:
	target = f(a_list[-1])
	if target in a_list:
		a_list.append(target)
		print(len(a_list))
		break
	else:
		a_list.append(target)

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

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

    a = s
    cnt = 1
    memo = set()
    memo.add(a)
    while True:
        a = f(a)
        cnt += 1
        if a in memo:
            break
        memo.add(a)
    print(cnt)


main()

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

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

print(a+1)

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


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


d = dict()
d[s] = 1
an = s
i = 2
while True:
    an = f(an)
    if d.get(an) is not None:
        print(i)
        break
    d[an] = i
    i += 1

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

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

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

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

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

Solution (Python):
import collections
s = int(input())
result = [s]
tmp = s
while True:
  if collections.Counter(result).most_common()[0][1] == 2:
    break
  elif tmp%2 == 0:
    x = tmp/2
  elif tmp%2 > 0:
    x = (3*tmp) + 1
  tmp = x
  result.append(int(x))
print(len(result))

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

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

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

s = int(input())
r = set([s])
for i in range(1000000):
    s = f(s)
    if s in r:
        print(i+2)
        break
    r.add(s)

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

s = int(input())
r = set([s])
for i in range(1000000):
    s = f(s)
    if s in r:
        print(i+2)
        break
    r.add(s)

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

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

    if a in memo:
        print(m)
        break
    else:
        memo.append(a)

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

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

print(answer)

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

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

memo = [False]*(M+1)
ans = -1
cnt = 1
while True:
    if memo[s]:
        ans = cnt
        break
    else:
        memo[s] = True
        cnt += 1
        if s % 2 == 0:
            s //= 2
        else:
            s = s * 3 + 1
print(ans)

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

Solution (Python):



s = int(input())

a = [s]

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

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

ss = []

ss.append(s)
i = 1

def has_dup(list):
    return len(list) != len(set(list))

while(has_dup(ss) == False):
    if(ss[-1] % 2 == 0):
        ss.append(ss[-1]/2)
    else:
        ss.append(3*ss[-1]+1)
    i += 1

print(i)

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

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

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

def f(n):
  if n%2 == 0:
    return n/2
  else:
    return 3 * n + 1
a = s
tmp =[]
count = 0
while True:
  tmp += [a]
  a = f(a)
  count += 1
  
  if a in tmp:
    print(count+1)
    exit()

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

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

print(i)

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

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

ans = [s]
flag = 0
while 1:
    s = collaz(s)
    if s not in ans:
        ans.append(s)
    else:
        ans.append(s)
        break
print(len(ans))

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

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

s = [int(input())]

for i in range(1000001):
    s.append(f(s[i]))
    if len(set(s)) == i + 1:
        print(i + 2)
        exit()

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

arr = [-1] * 1000000
arr[0] = n

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

	if i >= 3 and arr[i] == arr[i-3]:
		print(i + 1) 
		break

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


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

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

Solution (Python):

s = int(input())




ls = [s]

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

for i in range(1000000):
  num = f(ls[i])
  if ls.count(num) == 1:
    print(len(ls)+1)
    quit()
  ls.append(num)

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

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

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

print(i + 3)

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

s = int(input())

l = []
l.append(s)

c = 1

while f(s) not in l:
    s = f(s)
    l.append(s)
    c+=1

print(c+1)

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

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

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

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())
listS=[s]
for i in range(10**6):
  if listS[i]%2==0:
    if listS[i]//2 in listS:
      m=i+2
      break      
    listS+=[listS[i]//2]
  else:
    if 3*listS[i]+1 in listS:
      m=i+2
      break
    listS+=[3*listS[i]+1]
print(m)

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

def a(i):
    if i == 1:
        return s
    else:
        return f(a(i-1))

list = []
for i in range(1,1000000):
    list.append(a(i))
    if len(list) != len(set(list)):
        print(i)
        break

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

Solution (Python):
s = int(input())
f = set()
f_now = s
i = 1
while True:
    f.add(f_now)
    
    if f_now%2==0:
        f_next = int(f_now/2)
    else:
        f_next = int(f_now*3 + 1)
    
    
    f_and = f&{f_next} 
    if len(f_and)==0:
        f_now = f_next
        i+=1
    else:
        break

print(i+1)

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

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

a=[]
a.append(s)
for i in range(1,1000000):
    p=func(a[i-1])
    if not p in a:
        a.append(p)
    else:
        print(i+1)
        break

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

t3 = 0
na4 = []
na4.append(n1)
i2 = 1
r1 = 0
while True:
    if na4[i2 - 1] % 2 == 0:
        t3 = na4[i2 - 1] // 2 
    else:
        t3 = (3 *  na4[i2 - 1] ) + 1
    for i5 in range(len(na4)):
        if na4[i5] == t3:
            r1 = len(na4) + 1
    i2 += 1
    na4.append(t3)
    if r1 != 0:
        break

print(r1)

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

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

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

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

Solution (Python):
s=int(input())
e = set([s])
a = s
for i in range(1,1000000):
    if a%2 == 0:
        a = a//2
    else:
        a = 3*a+1
    
    e |= e^set([a])
    
    if len(e) == i:
        print(i+1)
        break

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

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

print(len(a) + 1)

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

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

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

Solution (Python):
import bisect
s = int(input())
a = []
a.append(s)
tmp = s
m = 1

while True:
	if tmp % 2 == 0:
		tmp //= 2
	else:
		tmp = 3 * tmp + 1
		
	m += 1
	i = bisect.bisect_left(a, tmp)
	
	if i < (m - 1) and tmp == a[i]:
		break
	else:
		bisect.insort_left(a, tmp)

print(m)

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

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

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

S = n()
seen = set()
seen.add(S)
m = 1
while True:
    m += 1
    if S % 2 == 0:
        S //= 2
    else:
        S = 3*S + 1
    if S in seen:
        print(m)
        import sys
        sys.exit()
    seen.add(S)

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

s=int(input())
l=[s]
if s==2 or s==1:
    print("4")
    exit()

ans=0
while l[ans]!=4:
    l.append(f(l[ans]))
    ans+=1
print(ans+4)

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

def func(n):
    if n%2==0:
        return n/2
    else:
        return 3*n+1
    
A = [s]
m = 1
while 1:
    m+=1
    if func(A[-1]) in A:
        print(m)
        break
    else:
        A.append(func(A[-1]))

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

i = 0
while(True):
    i += 1
    if(s % 2 == 0):
        s = s / 2
        List.append(s)
    else:
        s = 3 * s + 1
        List.append(s)

    a = List[-1]
    if(List.count(a) != 1):
        break

print(i+1)

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

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

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

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

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

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

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

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

Solution (Python):
s = int(input())
a = [s]
def f(n):
    if n % 2 == 0:
        return n // 2
    elif n % 2 == 1:
        return 3*n + 1

count = 1

while True:
    count += 1
    n = f(a[-1])
    if n in a:
        break
    else:
        a.append(n)

print(count)

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


def abc():
    s = int(input().rstrip())

    pre = 0
    ns = []
    for i in range(1, 1000001):
        if i == 1:
            a = s
        else:
            a = f(pre)
        if a in ns:
            print(i)
            return
        ns.append(a)
        pre = a


abc()

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

for i in range(1000000):
    if len(l) != len(set(l)):
        ans = len(l)
        break

    if l[i] % 2 == 0:
        next = l[i]//2
        l.append(next)
    else:
        next = 3 * l[i] + 1
        l.append(next)

print(ans)

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

s = int(input())

an = [s]
i = 1
while True:
  i += 1
  an_1 = col(an[-1])
  if an_1 in an:
    break
  else:
    an.append(an_1)

print(i)

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

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

print(answer)

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

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

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

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

Solution (Python):
def next(n):
	if n%2:
		return 3*n+1
	return n/2
cnt = {}
s = int(input())
cnt[s] = 1
i = 1
while True:
	w = next(s)
	i += 1
	if w in cnt:
		print(i)
		break
	cnt[w] = 1
	s = w

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

a = [s]

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

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

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

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


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

candidate = [s]  
  
for i in range(2, 1000001):
  tmp = func(candidate[-1])
  if tmp in candidate:
    print(i)
    break
  else:
    candidate.append(tmp)

Solution (Python):


s=int(input())

list=[s]
i=1
answer=0

while answer==0:
	if list[i-1]%2==0:
		list.append(list[i-1]//2)
	else:
		list.append(3*list[i-1]+1)

	for j in range(i):
		if list[i]==list[j]:
			answer=i+1

	i+=1 


print(answer)

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

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

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

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

    if i == 0:
        a.append(s)
    elif i > 0:
        if a[i - 1] % 2 == 0:
            a.append(a[i - 1] / 2)
        elif a[i - 1] % 2 == 1:
            a.append(3 * a[i - 1] + 1)
        if a[i] in a[:i]:
            print(i + 1)
            exit()
    i += 1

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

a = [0]
count = 0

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

    return ans

while True:
    if count == 0:
        a[0] = s
        count += 1
    else:
        a.append(f(a[count-1]))
        if a[count] in a[:(count-1)]:
            print(count+1)
            exit()
        else:
            count += 1

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

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

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

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

a = ['
i = 0
while i < 1000001:
  i += 1
  if i == 1:
    a.append(s)
  else:    
    if a[i-1]%2 == 0:
      ai = a[i-1] / 2
    else:
      ai = 3 * a[i-1] + 1
   
    if ai in a:
      print(i)
      exit()
    
    a.append(ai)

Solution (Python):
a = int(input())
t = set()
t.add(a)
for i in range(2,1000001):
    if a % 2 == 0:
        a //= 2
    else:
        a = 3*a + 1
    if a in t:
        break
    t.add(a)
print(i)

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

Solution (Python):
import sys
from collections import deque

input = sys.stdin.readline

s = int(input())
a = deque()
a.append(s)
counter = 0

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

for i in range(10000000):
    if a[i] == 4:
        break
    counter += 1
    if a[i] % 2 == 0:
        a.append(int(a[i]/2))
    else:
        a.append(3*a[i] + 1)

print(counter + 4)

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

dic = {}
for i in range(1000000):
    if s in dic:
        print(i+1)
        break
    dic[s] = 1
    if s % 2:
        s = 3 * s + 1
    else:
        s //= 2

Solution (Python):
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

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

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

st = []
x = s

while st.count(x) == 0:
    st.append(x)
    if x % 2 == 0:
        x = x // 2
    else:
        x = 3*x + 1

print(len(st) + 1)

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

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

a = [-1] * 1000000
a[0] = s
ans = 0

for i in range(1,1000000) :
    val = f(a[i-1])
    if val in a :
        ans = i + 1
        break
    a[i] = val

print(ans)

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

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

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

ans=1
l=[a]
t=a
while True:
    ans+=1
    t=f(t)
    if t in l:
        print(ans)
        exit()
    l+=[t]

Solution (Python):
s = int(input())
memo = [-1]
memo.append(s)
def a(n):
    if memo[n-1] % 2 == 0:
        pre = memo[n-1]/2
        for i in memo:
            if i == pre:
                return n
        memo.append(pre)
        return a(n+1)
    else:
        pre = 3 * memo[n-1] + 1
        for i in memo:
            if i == pre:
                return n
        memo.append(pre)
        return a(n+1)

print(a(2))

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

s = int(input())
if s==1 or s==2:
    print(4)
    exit()
cnt = 1
while s>1:
    s = f(s)
    cnt += 1
print(cnt+1)

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

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

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

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

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

count = 0
while True:
    a.append(f(a[count]))
    if f(a[count+1])in(a):
        break
    count += 1

print(count+3)

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

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

Solution (Python):
def p(a):
    print(a)

s=int(input())

list=[s]

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

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

while True:
    if s%2 == 0 :
        s = int(s/2)
    else:
        s = 3*s + 1
    ans += 1
    for t in S:
        if s == t:
            print(ans)
            break
    else:
        S.append(s)
        continue
    break

Solution (Python):
def solve(string):
    s = int(string)
    limit = 1000000
    i = 2
 
    d = {s: 1}
    m = s
    while i < limit:
        if m % 2 == 0:
            m = m // 2
        else:
            m = m*3 + 1
 
        if m in d:
            break
        else:
            d[m] = 1
 
        i += 1
 
    return i
 
 
if __name__ == "__main__":
    print(solve(input()))

Solution (Python):



s = int(input())






a_list=[]
a_list.append(s)
i=0
flag=0
while(flag==0):
  i+=1
  before_a = a_list.pop(-1)
  a_list.append(before_a)
  
  if before_a%2==0:
    after_a = before_a/2
  else:
    after_a = (3 * before_a) + 1
  
  
  
  for j in range(i):
    if a_list[j]==after_a:
      flag = 1
      break
  else:
    a_list.append(after_a)
    
print(i+1)

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

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

    print(res)

Solution (Python):
n = int(input())
a = [n]
number = 2

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

Solution (Python):
s = int(input())
prev = s
v = {s}

for i in range(10**6):
    if prev%2==0:
        next = prev//2
    else:
        next = prev*3+1
    if next in v:
        print(i+2)
        break        
    v.add(next)
    prev = next

Solution (Python):
n = int(input())
a = [n]
number = 2

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

Solution (Python):
n=int(input())
l=[0]*100000
ans=0
while True:
    l[n]+=1
    ans+=1
    if l[n]>1:
        break
    if n%2==0:
        n=n//2 
    else:
        n=3*n+1
print(ans)

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

cnt = 1
li = [s]

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

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

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

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

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

Solution (Python):
def solve(x,n,ls):
    if ls.count(ls[-1]) == 2:
        return n
    
    if x%2 == 0:
        ls.append(int(x/2))
        return solve(int(x/2),n+1,ls)
        
    else:
        ls.append(int(3*x+1))
        return solve(int(3*x+1),n+1,ls)
    
if __name__ == "__main__":
    s = int(input())
    ls = [s]    
    

print(solve(s,1,ls))

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