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):
e = [int(input())]

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


for i in range(10000):
    e.append(f(e[i]))
    for j in range(0, len(e) - 1):
        if e[-1] == e[j] :
            print(len(e))
            break
    else:
        continue
    break

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

suuretu = set()
ans = 1
while True:
    if s in suuretu:
        break
    
    suuretu.add(s)
    s = colazt(s)
    ans = ans + 1

print(ans)

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

Solution (Python):
s = int(input())
fuga = []
class B:
    def __init__(self):
        self.m = 1

    def hoge(self, n):
        fix = [_n for _n in fuga if n == _n]
        if fix:
            print(int(self.m))
            exit()
        if n >= 1000000:
            exit()
        fuga.append(n)
        self.m = self.m+1
        if n%2 == 0:
            self.hoge(n / 2)
        if n%2 == 1:
            self.hoge(3*n + 1)
b = B()
b.hoge(s)

Solution (Python):
import sys
S = int(input())
s = set()
ans = 1
while(not S in s):
    s.add(S)
    if(S%2 == 0):
        S /= 2
    else:
        S *= 3
        S += 1
    ans+=1
print(ans)

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


s = int(input())
a = [s]
ans = 0
for i in range(1,1000000):
    ai = f(a[i -1])
    if a.count(ai) == 1:
        ans = i + 1
        break
    a.append(ai)
print(ans)

Solution (Python):
s=int(input())
a=[s]
i=0
while True:
    if a[i]%2==0:
        a.append(int(a[i]/2))
        i+=1
    else:
        a.append(int(3*a[i]+1))
        i+=1
    if [j for j in set(a) if a.count(j)>1]:
        a_duplicate=sorted([j for j in set(a) if a.count(j)>1],key=a.index)
        break
a[a.index(a_duplicate[0])]=0
print(a.index((a_duplicate[0]))+1)

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

s = int(input())

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

Solution (Python):
s=int(input())
a=[s]
for i in range(1000000):
    if a[i]%2==0:
        a.append(int(a[i]/2))
    else:
        a.append(int(3*a[i]+1))
a_duplicate=sorted([j for j in set(a) if a.count(j)>1],key=a.index)
a[a.index(a_duplicate[0])]=0
print(a.index((a_duplicate[0]))+1)

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

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

s = int(input())
a = [s]
i = 1
while True:
    n = collatz(a[i-1])
    try:
        index = a.index(n)
        print(len(a)+1)
        break
    except ValueError:
        a.append(n)
        i += 1

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

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

s = int(input())
a = [s]
ans = 0
for i in range(1, 1000000):
  ai = f(a[i - 1])
  if a.count(ai) == 1:
    ans = i + 1
    break
  a.append(ai)
print(ans)

Solution (Python):

s = int(input())

def is_unique(seq):
    return len(seq) == len(set(seq))

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

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

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

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


for i in range(1000000):
    
    a.append(s)
    s = f(s)
    if len(set(a)) != c:
        break
    else:
        c += 1
print(c)

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

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

print(ans+1)

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

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

i = 1
flag = True

while flag:
    i += 1
    ins = f(a[-1])
    for j in range(len(a)):
        if a[j] == ins:
            flag = False
            break
    a.append(ins)

print( i )

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

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

def main(s):
	a = [0]*10000000
	a[s] = 1
	i = 1
	while True:
		s = f(s)
		i+=1
		if a[s] == 1:
			print(i)
			break
		a[s] = 1
	return

main(int(input()))

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

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

print(len(a) + 1)

Solution (Python):
import collections
s=int(input())
count=[]
count.append(s)
def is_even(num):
	return num % 2 == 0
def calc(a):
	if is_even(int(a)):
		return (int((a)/2))
	else:
		return (int((a)*3+1))

check=(s) not in [1,2,4]
while (s) not in [1,2,4]:
	calc(s)
	s=calc(s)
	count.append(s)
	continue
else:
	print (len(count)+3)

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

Solution (Python):
a = int(input())
k = 1
if a == 4 or a == 2 or a == 1:
  print(4)
  exit()
for i in range(1000000):
  if a % 2 == 0:
    a = a // 2
    k = k + 1
  else:
    a = 3 * a + 1
    k = k + 1
  if a == 4:
    print(k + 3)
    break

Solution (Python):
def find_min_m(s):
        a = s
        m = 1
        hist = set()
        while a not in hist:
                hist.add(a)
                a = a // 2 if a & 1 == 0 else 3 * a + 1
                m += 1
        return m


print(find_min_m(int(input())))

Solution (Python):
s = int(input())
an = []
an.append(s)
n = s
while an.count(4) != 2:
    if n % 2 == 0:
        n /= 2
        an.append(int(n))
    else:
        n = 3 * n + 1
        an.append(int(n))
if an.index(1) == 0 or an.index(2) == 0:
    print(4)
else:
    print(an.index(4) + 4)

Solution (Python):
s = int(input())
an = []
an.append(s)
n = s
while an.count(4) != 2:
    if n % 2 == 0:
        n /= 2
        an.append(int(n))
    else:
        n = 3 * n + 1
        an.append(int(n))
if an.index(1) == 0:
            print(4)
elif an.index(2) == 0:
            print(4)
else:
    print(an.index(4) + 4)

Solution (Python):


s = int(input())
c = {}

c[s] = 1

prev = s
i = 2
while True:
    prev = int(prev/2) if prev % 2 == 0 else 3 * prev + 1
    if prev in c:
        print(i)
        exit()
    
    c[prev] = i
    i += 1

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

n_dict = {n:1}
cont = 1
while n_dict[n]<=1:
	if n%2==0:
		n = n/2
	else:
		n = 3*n+1
	n_dict[n] = n_dict.get(n,0)+1
	cont += 1
print(cont)

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

cnt = 1

while(n!=4 and n != 2  and n!=1):
    if (n%2==0):
        n //=2
    else:
        n = 3*n + 1
    cnt += 1
print(cnt + 3)

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

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

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

n = s
i = 0
p = []
while True:
    i = i+1
    if i == 1:
        n = s
    elif n % 2 == 0:
        n = n/2
    else:
        n = n*3 + 1

    p.append(n)
    if len(set(p)) != len(p):
        print(i)
        break

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

Solution (Python):
s = int(input())
def f(n):
    if n%2==0:
        return(int(n/2))
    if n%2!=0:
        return(3*n+1)
a = []
a.append(s)
while(1):
    a_next = f(a[-1])
    a.append(a_next)
    for i in a[:-1]:
        if(a[-1]==i):
            break
    if(a[-1]==i):
        break
print(len(a))

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

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

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

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

while len(value) == len(set(value)):
    if s % 2 == 0:
        s = int(s/2)
        value.append(s)
    elif s % 2 == 1:
        s = s*3 + 1
        value.append(s)
    
print(len(value))

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

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

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

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

    a.append(s)

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

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

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

print(i + 1)

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

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

for i in range(1000001):
    if f(a[i]) in a:
        print(i+2)
        break
    a.append(f(a[i]))

Solution (Python):


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

s = int(input())


memo = set()
memo.add(s)
for i in range(2, 1000000):
    tmp = f(s)
    if tmp in memo:
        print(i)
        break
    memo.add(tmp)
    s = tmp

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

Solution (Python):




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

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


if __name__ == '__main__':
    main()

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

a_set = set([s])

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

for i in range(2, 1000001):
    a[i] = func(a[i - 1])
    a_set.add(a[i])
    if len(a_set) < i:
        print(i)
        exit()

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):
def func_odd(n):
    return int(3 * n + 1)


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


def is_finished(array):
    before_len = len(array)
    after_len = len(list(set(array)))
    return before_len != after_len


def main(s):
    array = [s]
    index = 0
    while True:
        if array[index] % 2 == 0:
            array.append(func_even(array[index]))
        else:
            array.append(func_odd(array[index]))
        if is_finished(array):
            break
        index += 1
    print(index + 2)


if __name__ == '__main__':
    main(int(input()))

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

def func_1(x):
    return x//2

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

dp = [0] * 1000000

c = 1
dp[a] = 1
while True:
    c += 1
    if a % 2 == 0:
        a = func_1(a)
    else:
        a = func_2(a)

    if dp[a] > 0:
        print(c)
        break
    else:
        dp[a] = 1

Solution (Python):



def main():
    s1 = input()
    ret = solve(s1)
    print(ret)


def solve(s1):
    s = int(s1)
    a = []
    m = 0
    for i in range(1000000):
        if (i == 0):
            w = s
        elif (a[i-1] % 2 == 1):
            w = 3 * a[i-1] + 1
        else:
            w = a[i-1] / 2
        if (w in a):
            return i+1
        a.append(w)


main()

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

Solution (Python):


s =int(input())
i=0
ans=[]
while i==0:
    
    if s in ans:
        i +=1
    ans.append(s) 
    if s%2 ==0:
        s = s/2
    elif s%2 ==1:
        s =3*s+1
  
print(len(ans))

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

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

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

numbers = [s]
old_num = s
while True:
    new_num = f(old_num)
    old_num = new_num
    if new_num in numbers:
        numbers.append(new_num)
        break
    numbers.append(new_num)

min_m = max(numbers)
for n in range(len(numbers)):
    for m in range(n+1, len(numbers)):
        if numbers[m] == numbers[n]:
            min_m = min(min_m, m)


print(min_m+1)

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

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

if x == 1 or x == 2:
    i = 4
else:
    while(x != 1):
        i += 1
        x = collatz(x)
    
print(i)

Solution (Python):
a = int(input())
cnt = 1
if a == 1 or a == 2:
  print('4')
else:
  while a >=3:
    if a % 2 == 0 and a != 4:
      a = a//2 
      cnt += 1
    elif a % 2 != 0:
      a = 3*a + 1
      cnt += 1
    elif a == 4:
      break
  print(cnt+3)

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

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

Solution (Python):
import math
num = int(input())

def function(a):
    if a%2 == 0:
        return math.floor(a/2)
    else:
        return 3*a + 1

list = [num]
while True:
    if function(list[-1]) in list:
        print(len(list)+1)
        break
    else:
        list.append(function(list[-1]))

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

a = s
i = 1
aa=[s]
while i < 100000:
    i+=1
    if a%2 ==0:
        a = int(a / 2)
    else:
        a = int(a * 3 + 1)
    if aa.count(a)>0:
        print(i)
        break
    else:
        aa.append(a)

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

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

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

def f(x):
    if x%2==0:
        return x/2
    else:
        return 3*x+1
list_a=[s,f(s)]
i=1
while i>0:
    if f(list_a[-1]) in list_a:
        print(len(list_a)+1)
        i=-1
    else:
        list_a.append(f(list_a[-1]))

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

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

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

Solution (Python):


s = int(input())

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

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

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

c = [False for i in range(1000001)]

n = 1
an = s
while True:
    if c[an]:
        print(n)
        break
    c[an] = True

    if an & 1 == 0:
        an >>= 1
    else:
        an = 3 * an + 1
    n += 1

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

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

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

Solution (Python):

s = int(input())

dp = [s]

i=2
a_1=s
while(True):
    if a_1 % 2==0:
        index = a_1 /2
    else:
        index = 3 * a_1 + 1
    if int(index) in dp:
        break
    else:
        dp.append(int(index))
        a_1 = int(index)
        i+=1

print(i)

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

m = 1000000


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


ls = [init]
s = init
flag = 1
while 1:
    ls.append(f(s))
    s = f(s)
    
    if s == 1 and flag == 1:
        flag = 0
    elif s == 1 and flag == 0:
        break

if init == 2:
    print(4)
elif init == 1:
    print(4)
else:
    
    print(len(ls)-2)

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

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

Solution (Python):
def f(n):
    if n%2==0:
        return n/2
    else:
        return 3*n+1
s = int(input())
a=[0]*1000001
get_ans = False
ans = 0
for i in range(2,1000001):
    
    if i==2:
        a[1] = s
        a[2] = f(s)
        if a[1]==a[2]:
            ans = 2
            break
    else:
        a[i]=f(a[i-1])
        for j in range(1,i):
            if a[i]==a[j]:
                ans = i
                get_ans = True
                break
    if get_ans:
        break
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):
s = int(input())
vals = []
vals += [s]
n=1
while True:
    if vals[n-1]%2==0:
        val = vals[n-1]/2
    else:
        val = vals[n-1]*3+1
        
    if val in vals:
        print(len(vals)+1)
        break
    else:
        vals += [val]
        n += 1

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



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



def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

    s = set()
    s.add(a)
    for ans in count(2):
        if a % 2 == 0:
            a //= 2
        else:
            a = 3 * a + 1
        if a in s:
            print(ans)
            break

        s.add(a)


if __name__ == '__main__':
    main()

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

Solution (Python):
a = []
a.append(int(input()))
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):
def func(n):
  if n % 2 == 0:
    return (int(n / 2))
  else:
    return (3*n + 1)

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

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

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

dict = {}
dict[s] = 1

last_a = s
f = 0
n = 2
ans = 0
while True:
    if last_a % 2 == 0:
        last_a = last_a // 2
    else:
        last_a = 3 * last_a + 1

    if last_a not in dict.keys():
        dict[last_a] = n
    else:
        ans = n
        break
    n += 1

print(ans)

Solution (Python):

mlist = list(map(int,input().split()))

i=0
while(True):
    if mlist[i] % 2 == 0:
        mlist.append(mlist[i]/2)
    else:
        mlist.append(3*mlist[i]+1)
    
    breakFlg = False
    for num in range(0,i):
        if int(mlist[num])==int(mlist[i]):
            if num!=i:
                breakFlg = True
    i=i+1
    if(breakFlg):
        break
print(i)

Solution (Python):
s = int(input())
m = 1000000
a = set()
a.add(s)
ans = 0
for i in range(1,m+5):
    tmp = 0
    if s%2==0:
        tmp = s//2
    else:
        tmp = 3*s+1
    if tmp in a:
        ans = i+1
        break
    s = tmp
    a.add(s)
print(ans)

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

s = int(input())

an = set()
an.add(s)

c = 1
ai = s
while True:
    c += 1
    ai = f(ai)
    let = an.isdisjoint({ai})
    if let:
        an.add(ai)
    else:
        break
print(c)

Solution (Python):



def is_unique(seq):
    return len(seq) == len(set(seq))


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


def main():
    s = int(input())
    li = [s]

    while (len(li) <= 1000000):
        li.append(func_f(s))
        s = li[-1]
        if not is_unique(li):
            print(len(li))
            break


if __name__ == '__main__':
    main()

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

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

print(i)

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

print(len(s_l)+1)

Solution (Python):
import sys
input = sys.stdin.readline
s=int(input())
cnt = 1
while not(s==4 or s==2 or s==1):
    cnt += 1
    if s%2==1:
        s = 3*s+1
    else:
        s=s/2
print(cnt+3)

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

chk = set([s])
def f(a):
  if a%2 == 0:
    return a/2
  else:
    return 3*a+1

for i in range(2,1000000):
  s = f(s)
  if s in chk:
    print(i)
    break
  chk.add(s)

Solution (Python):

from sys import stdin


s_in = lambda: stdin.readline()[:-1]  
d_in = lambda: int(stdin.readline())  
ds_in = lambda: list(map(int, stdin.readline().split()))  


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


s = d_in()
searched = [s]
idx = 1
while True:
    s = func(s)
    idx += 1
    if s in searched:
        print(idx)
        exit()
    else:
        searched.append(s)

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

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

Solution (Python):
def is_unique(seq):
    return len(seq) == len(set(seq))
  
s = int(input())
lists=[]
lists.append(s)
for x in range(1,1000000):
  if lists[x-1] % 2 == 0:
    lists.append(int(lists[x-1]/2))
  else:
    lists.append(int(lists[x-1]*3+1))
  if not is_unique(lists):
    print(x+1)
    break

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

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

Solution (Python):
import sys

S = int(input())

a = list()
a.append(0)
a.append(S)

i = 2
while True:
    if a[i-1] % 2 == 0:
        n = a[i-1] / 2
    else:
        n = 3 * a[i-1] + 1
    n = int(n)
    for l in range(len(a)-1):
        if a[l] == n:
            print(i)
            sys.exit()
    
    a.append(n)
    i += 1

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

def myfnc(input):

    if input % 2 == 0:
        return input // 2
    else:
        return (3 * input) + 1

answer = list()
answer.append(s)
for i in range(2, 1000000):
    ret = myfnc(answer[-1])

    if ret in answer:
        print(i)
        exit(0)
    else:
        answer.append(ret)

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

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

cache = []
def calc(s):
    cache.append(s)
    if cache.count(s) > 1:
        print(len(cache))
        return
    calc(ehu(s))

calc(s)

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

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

Solution (Python):
a1=int(input())
L=[a1,]
ans=0

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


print(ans)

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

Solution (Python):
dict_ = {}
def collatz(s):
    if s in dict_.keys():
        dict_[s] += 1
        return sum(dict_.values())
    else:
        dict_[s] = 1
        return collatz(s/2) if s%2==0 else collatz(3*s+1)

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

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

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

Solution (Python):


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

for i in range(1000000):
    a.append(s)
    s = f(s)
    if len(a)!=len(set(a)):
        print(i+1)
        break

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

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

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

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

tmp_a = s
next_a = s
ans = 0
for i in range(100000):
    next_a = collatz(tmp_a)
    if next_a in outputs:
        ans = i + 2
        break
    else:
        outputs.add(next_a)
        tmp_a = next_a

print(ans)

Solution (Python):



from sys import stdin




import numpy as np

n = stdin.readline().split()
a = int(n[0])

out = np.zeros(1000000)
out[0] = int(a)

for i,x in enumerate(out[:-1]):
    
    if a%2 == 0:
        a/=2
    else:
        a=a*3+1
    
    if a in out:
        answer = i+2
        break
    out[i+1]=int(a)
    
print(int(answer))

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



s = int(input())
stack = [s]
index = 1
while True:
    s = collatz(s)
    index += 1
    if s in stack:
        print(index)
        break
    stack.append(s)

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