Problem:
 Score : 200 points    Problem Statement A sequence a=\{a_1,a_2,a_3,......\} is determined as follows:    The first term s is given as input.    Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.    a_i = s when i = 1 , and a_i = f(a_{i-1}) when i > 1 .    Find the minimum integer m that satisfies the following condition:   There exists an integer n such that a_m = a_n (m > n) .       Constraints  1 \leq s \leq 100  All values in input are integers.  It is guaranteed that all elements in a and the minimum m that satisfies the condition are at most 1000000 .         Input Input is given from Standard Input in the following format:  s       Output Print the minimum integer m that satisfies the condition.        Sample Input 1 8      Sample Output 1 5  a=\{8,4,2,1,4,2,1,4,2,1,......\} . As a_5=a_2 , the answer is 5 .       Sample Input 2 7      Sample Output 2 18  a=\{7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4,2,1,......\} .       Sample Input 3 54      Sample Output 3 114

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

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

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


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


i, tmp = 1, set()
while s not in tmp:
    tmp.add(s)
    s = f(s)
    i += 1
print(i)

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

sum = 0
flag = 0
for i in range(100000):
    if a[i] % 2 == 0:
        a[i+1] = a[i] // 2
    else:
        a[i+1] = 3 * a[i] + 1
    sum += 1
    if a[i] in a[:i]:
        print(sum)
        exit()

Solution (Python):
s=int(input())
a=[]
a.append(s)
cnt=2
t=0

while cnt<1000000:
    if a[cnt-2]%2==0:
        a.append(int(a[cnt-2]/2))
    else:
        a.append(int(3*a[cnt-2]+1))
    cnt+=1
    
    if a[cnt-2]==4:
        t+=1
        if t==2:
            b=len(a)
            break


for i in range(len(a)):
    if 2<=a.count(a[i]):
        Key=a[i]
        break
    
a.remove(Key)

print(min(a.index(Key)+2,b))

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

a = []
a.append(s)

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

    if tmp in a:
        print(i+2)
        break
    else:
        a.append(tmp)
        i += 1

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

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

def func(x):
    if x % 2 == 0:
        return int(x/2)

    return 3*x + 1

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

Solution (Python):
from sys import stdin
import numpy as np

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

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

print(cnt)

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

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

print(len(a)+1)

Solution (Python):
from collections import defaultdict
s = int(input())
mem = defaultdict(int)

def f(n):
    if n % 2 == 0:
        return n//2
    else:
        return 3*n + 1
m = 1
while 1:
    if mem[s] == 1:
        print(m)
        exit()
    else:
        mem[s] = 1
        s = f(s)
        m += 1

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

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

print(len(l))

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

Solution (Python):

import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(s: int):
    res = [0] * 1000001
    a = s
    i = 1
    while True:
        if res[a] == 1:
            break
        res[a] = 1
        if a % 2 == 0:
            a = a // 2
        else:
            a = 3 * a + 1
        i += 1
    return 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))  
    result = solve(s)
    print(result)

if __name__ == '__main__':
    main()

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

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

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


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

if s == 1:
    print(4)
elif s == 2:
    print(4)
else:
    while True:

        if s == 4:
            break
        else: 
            s = f(s)
            count += 1

    print(count + 3)

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

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

Solution (Python):
S = int(input())
counter = 0
ans = 1
if S <= 2 or S == 4:
    print('4')
    exit()
else:
    while True:
        if S % 2 == 0:
            S = S // 2
            ans += 1
            if S == 4:
                counter += 1
                if counter == 2:
                    print(ans)
                    exit()
        else:
            S = 3 * S + 1
            ans += 1
            if S == 4:
                counter += 1
                if counter == 2:
                    print(ans)
                    exit()

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

Solution (Python):
a = [0 for i in range(3 * 1000000 + 1)]

s = int(input().rstrip())

a[s] = 1

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

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

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

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

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

s = int(input())
ansFlg = True

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

ans = 1
while ansFlg:
    if s == 4:
        ans += 3
        break
    s = kansu(s)
    ans += 1
print(ans)

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


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

print(len(a))

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

Solution (Python):
fx = lambda x: int(x/2) if x%2==0 else 3*x + 1
ans = [int(input())]
counter = 1

while True:
    new_x = fx(ans[-1])
    counter += 1
    if (new_x in ans) :
        break
    ans.append(new_x)

print(counter)

Solution (Python):
from collections import defaultdict
d = defaultdict(int)
a = int(input())
d[a] += 1

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

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

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

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

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

a = S
indx = 1

nums = set()
nums.add(a)

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

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

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

def Collatz(a):
    if a % 2:
        return 3 * a + 1
    else:
        return a // 2

x = set()
while s not in x:
    x.add(s)
    s = Collatz(s)

print(len(x)+1)

Solution (Python):

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

Solution (Python):

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

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

print(cnt)

Solution (Python):
s = int(input())
X = [s]
m = 1
while True:
    m += 1
    if s % 2 == 0:
        s = s / 2
    else:
        s = 3 * s + 1
    
    Y = [s]
    if len(set(X) & set(Y)) == 1:
        break
    X.append(s)

print(m)

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 a.count(s) == 1:
        print(ans)
        exit()
    else:
        a.append(s)

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

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

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

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

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

Solution (Python):
import sys

s = int(input())
a = [s]
ans = 0
for i in range(1,10**6+10):
    if a[i-1] % 2 == 0:
        a.append(int(a[i-1]/2))
    else:
        a.append(3*a[i-1]+1)
    for j in range(len(a)):
        if a.count(a[i]) == 2:
            ans = i+1
            print(ans)
            sys.exit()

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

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

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

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

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

Solution (Python):
s = int(input())
flag = [0] * 1000000
flag[s] = 1
a = s
i = 1

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

print (i)

Solution (Python):
S = int(input())
L = [S]

while True:
	v = L[-1]
	nv = [v // 2, 3 * v + 1][not (0 == v % 2)]
	if nv in L:
		print(len(L) + 1)
		break
	L.append(nv)

Solution (Python):

s = int(input())
lst = []
count = 1

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

print(count)

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

        for j in range(len(a)-1):
            if a[-1] == a[j]:
                ans = len(a)
                break
    else:
        print(ans)
        break

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


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


def insert(sslist, x):
    if not sslist:
        sslist.append(x)
        return False

    start = 0
    end = len(sslist)

    while start < end - 1:
        y = sslist[(start + end) // 2]
        if x == y:
            return True
        if x < y:
            end = (start + end) // 2
        if x > y:
            start = (start + end) // 2

    if sslist[start] == x:
        return True
    if sslist[start] < x:
        sslist.insert(start + 1, x)
        return False
    if sslist[start] > x:
        sslist.insert(start, x)
        return False


slist = []
ss = s
for i in range(1, 2**32):
    ret = insert(slist, ss)
    ss = f(ss)
    if ret:
        print(i)
        break

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


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


def insert(sslist, x):
    if not sslist:
        sslist.append(x)
        return False

    start = 0
    end = len(sslist)

    while start < end - 1:
        y = sslist[(start + end) // 2]
        if x == y:
            return True
        if x < y:
            end = (start + end) // 2
        if x > y:
            start = (start + end) // 2

    if sslist[start] == x:
        return True
    if sslist[start] < x:
        sslist.insert(start + 1, x)
        return False
    if sslist[start] > x:
        sslist.insert(start, x)
        return False


slist = []
ss = s
for i in range(1, 2**32):
    ret = insert(slist, ss)
    ss = f(ss)
    if ret:
        print(i)
        break

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


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


sset = {s}
ss = s
for i in range(2, 2**32):
    prev_len = len(sset)
    ss = f(ss)
    sset.add(ss)
    next_len = len(sset)
    if prev_len == next_len:
        print(i)
        break

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

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

while True:
    s = f(s)
    i += 1

    if s not in a:
        a.add(s)

    else:
        print(i)
        break

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

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

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

Solution (Python):

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

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

s = int(input())
st = set([s])

ans = -1
for i in range(2, 1000001):
    s = int(f(s))
    if s in st:
        ans = i
        break
    st.add(s)

print(ans)

Solution (Python):
n=int(input())
dic=set()
dic|={n}
i=1
while True:
  if n%2==0:
    n=n//2
  else:
    n=3*n+1
  if n in dic:
    print(i+1)
    break
  else:
    dic|={n}
    i+=1

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

used = set()
used |= {s}
count = 1

while True:
    if s % 2 == 0: s//=2
    else:s=3*s+1
    if s in used:
        print(count+1)
        break
    else:
        used |= {s}
        count += 1

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

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

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

print(len(a))

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

used = set()
used |= {s}
count = 1

while True:
    if s % 2 == 0: s//=2
    else:s=3*s+1
    if s in used:
        print(count+1)
        break
    else:
        used |= {s}
        count += 1

Solution (Python):
s = int(input())
def f(n):
  if n % 2 == 0:
    return n / 2
  else:
    return 3 * n + 1
count = 0
i = 0
j = 0
a = 0
list1 = [1, 2, 4]
while True:
  i += 1
  if i == 1:
    a = s
  else:
  	a = f(a)
  if a in list1:
    j = a
    list1 = []
  if a == j:
    count += 1
  if count == 2:
    print(i)
    break

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

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

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

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

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

setNum = set()
n = s
for i in range(1000000+1):
	if n in setNum:
		print(i+1)
		exit()
	
	
	setNum.add(n)
	if n % 2 == 0:
		n = int(n/2)
	else:
		n =3*n+1

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

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

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

temp = s
a = []
i = 0
flg = True
while flg == True:
    if i == 0:
        a.append(temp)
        i += 1
        continue
    temp = myfunction(temp)
    a.append(temp)
    if a[i] in a[:(i-1)]:
        print(i+1)
        break
    i += 1

Solution (Python):

import sys
INF = float("inf")


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


def solve(s: int):
    a = [s]
    for i in range(10**7):
        s = f(s)
        
        for av in a:
            if av == s:
                print(i+2)
                return
        a.append(s)
    return


def main():

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


if __name__ == '__main__':
    main()

Solution (Python):







n = int(input())
a = set()
count = 0

a.add(n)

for i in range(2, 100000):

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

    if n in a:
        count = i
        break

    a.add(n)

print(count)

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

tab = [False]*1000001
now = int(input())
ind = 1
while not tab[now]:
    tab[now] = True
    now = func(now)
    ind += 1

print(ind)

Solution (Python):
s = int(input())
covered = set([s / 1])

while 1:
    s = s / 2 if s % 2 == 0 else s * 3 + 1
    
    if s in covered:
        print(len(covered) + 1)
        exit()

    else:
        covered.add(s)

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

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

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

Solution (Python):




s = int(input())


sl = list()
lflg = True
sl.append(s)
cnt = 1


while(lflg):
    cnt += 1
    if s % 2 == 0:
        s = int(s / 2)
    else:
        s = 3 * s + 1

    for i in range(len(sl)):
        if s == sl[i]:
            print(cnt)
            lflg = False
            break
        
    sl.append(s)

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

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

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

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

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

numset = {s}
for i in range(2, 1000001, 1):
  
  if s % 2 == 0:
    s = s / 2
  else:
    s = (s * 3) + 1
  
  if {s} <= numset:
    print(i)
    break
  else:
    numset.add(s)

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

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

    if n in progression:
        break
    else:
        progression.append(n)

print(count)

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

Solution (Python):
s = int(input())
a = s
already = set()
already.add(a)
for i in range(10000000):
    if a % 2:
        a = 3 * a + 1
        if {a} <= already:
            print(i + 2)
            exit(0)
        already.add(a)
    else:
        a //= 2
        if {a} <= already:
            print(i + 2)
            exit(0)
        already.add(a)

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

s = int(input())
l = [s]
m = 1

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

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

s=int(input())
List=[s]
s=COL(s)
while s not in List:
  List.append(s)
  s=COL(s)
print(len(List)+1)

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

s = int(input())
hist = [s, ]
m = 1
while True:
    elem = f(hist[m-1])
    if elem not in hist:
        hist.append(elem)
        m += 1
    else:
        print(m+1)
        break

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

i = 0
flag = 0
while(True):
    if a[i] % 2 == 0:
        new_a = int(a[i] / 2)
    else:
        new_a = int(3 * a[i] + 1)
    i += 1
    for ai in a:
        if new_a == ai:
            flag = 1
            break
    if flag == 1:
        break
    else:
        a.append(new_a)

print(i + 1)

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

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

    a_unique = list(set(a))
    if len(a) != len(a_unique):
        break


print(i)

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

S = []
ans = 1

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

print(ans)

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

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

hist=set([s])

while True:
	s = f(s)
	if s in hist:
		break
	hist.add(s)

print(1+len(hist))

Solution (Python):
def collatz(n):
	if n%2 == 0: return n/2
	else: return 3*n+1
s = int(raw_input())
lst = []
tmp = s
while(True):
	if tmp in lst:
		print len(lst)+1
		break
	else:
		lst.append(tmp)
		tmp = collatz(tmp)

Solution (Python):
import sys

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

n = 0
while True:
    if a[n] % 2 == 0:
        a_nn = int(a[n]/2)
        if a_nn in a:
            print(n+2)
            sys.exit()
        else:
            a.append(a_nn)
    else:
        a_nn = int(3*a[n]+1)
        if a_nn in a:
            print(n+2)
            sys.exit()
        else:
            a.append(a_nn)
    n += 1

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

print(i+2)

Solution (Python):
S = int(input())
i = 1
ans = [S]
while True:
    if S%2 == 0:
        S = S//2
        i += 1
        ans.append(S)
    else:
        S = 3*S+1
        i += 1
        ans.append(S)
    if len(set(ans[:-2]) & set([S]))!=0:
        break
print(i)

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

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

print(len(A)+1)

Solution (Python):
s = int(input())
memo = [0]*1000000
memo[0] = s
dic = {s:1}

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

for i in range(1, 1000002):
    memo[i] = f(memo[i-1])
    if dic.get(memo[i]):
        print(i+1)
        exit()
    else:
        dic[memo[i]] = 1

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

s = int(input())

n = 1
b4 = 0
b2 = 0
while s!=1:
    if s == 4:
        b4 = 1
    elif s==2:
        b2 = 1
    s = f(s)
    n += 1
k = 3
if b4 == 1:
    k = 1
elif b2 == 1:
    k = 2
print(n+k)

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

a = int(input())
A = [a]
m = 1
while True:
  m += 1
  a = f(a)
  A.append(a)
  if len(A) > len(set(A)):
    break
print(m)

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

mp = dict()
mp[s] = 1
cnt = 1
while True:
    if s % 2 == 0:
        s = s//2
    else:
        s = 3*s + 1

    cnt += 1

    if s in mp:
        break
    else:
        mp[s] = 1

print(cnt)

Solution (Python):
import sys
a = [int(raw_input())]
for i in range(1000000):
	a.append(a[i]/2 if a[i]%2==0 else 3*a[i]+1)
	if a.count(a[i+1]) > 1:
		print i + 2
		sys.exit()

Solution (Python):







n = int(input())
a = set()
count = 0

a.add(n)

for i in range(2, 100000):

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

    if n in a:
        count = i
        break

    a.add(n)

print(count)

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

for i in range(10**6+1):
    count += 1
    if a[i] % 2 == 0:
        if a[i]/2 in a:
            break
        a.append(a[i]/2)
    else:
        if 3*a[i] + 1 in a:
            break
        a.append(3*a[i] + 1)

print(count)

Solution (Python):



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

A = [s]
for i in range(1,1000000):
    A.append(f(A[i-1]))
    if len(list(set(A))) != i+1:
        print(i+1)
        break

Solution (Python):
s = int(input())
a_list = [s]
prev_num = 1
for i in range(1,1000001):
    n = a_list[i-1]
    if n%2 == 0:
        a_list.append(n//2)
    else:
        a_list.append(3*n+1)
    if prev_num == len(set(a_list)):
        print(i+1)
        break
    else:
        prev_num = len(set(a_list))

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


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


memo = [0, S]
result = -1

for m in range(2, 1000000):

    a = f(memo[m - 1])
    memo.append(a)

    

    if a in memo[1:m - 1]:
        result = m
        break

print(result)

Solution (Python):


s = int(input().strip())

ai = [s]
for i in range(2, 10**9):
	if ai[-1] % 2 == 0:
		am = int(ai[-1]/2)
	else:
		am = int(3*ai[-1]+1)
	
	if am in ai:
		print(i)
		break
	else:
		ai.append(am)

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

if a in [1, 2, 4]:
    print(4)
    exit(0)
ans = 1 + 3

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

print(ans)

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

Solution (Python):
from collections import defaultdict

def main():
	s = int(input())
	f = defaultdict(bool)
	i = 1
	f[s] = True
	while True:
		s = s//2 if s%2==0 else 3*s+1
		i += 1
		if f[s]:
			print(i)
			break
		f[s] = True


if __name__ == '__main__':
    main()

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

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

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