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())

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

if s in [1,2,4]:
    print(4)
else:
    count = 1
    while s != 4:
        s = f(s)
        count += 1
    print(count+3)

Solution (Python):

import sys

s = int(input())

a = [0 for _ in range(1000000)]

a[0] = s

def getN(wk) :
    for _ in range(1, len(wk)) :
        if wk[_ - 1] % 2 == 0 :
            wk[_] = wk[_ - 1] // 2
        else :
            wk[_] = wk[_ - 1] * 3 + 1
        for i in range(_):
            if wk[i] == wk[_] and i < _ :
                return _ + 1

print(getN(a))

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

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

m = 2
a = [s]
ai = f(s)
while 1:
    if ai in a:
        print(m)
        break
    a.append(ai)
    ai = f(ai)
    m += 1

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

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

Solution (Python):



n = int(input())
r = set([n])
if n%2==0:
    s_next = n/2
else:
    s_next = n*3+1
i=2
while s_next not in r:
    r.add(s_next)
    if s_next%2==0:
        s_next = s_next/2
    else:
        s_next = s_next*3+1
    i+=1

print(i)

Solution (Python):


s = int(input())

list = [s]

for i in range(1000000):
  n = list[i]
  if n%2 == 0:
    f = int(n/2)
  else:
    f = int(3*n+1)

  if f in list:
    print(i+2)
    break
  else:
    list.append(f)

Solution (Python):
s = int(input())
s = max(min(s, 100), 1)

f = lambda x: x * 0.5 if x % 2 == 0 else 3*x + 1
array = [s]
while s != 1:
    s = f(int(s))
    array.append(int(s))
array += [4, 2, 1]
freq = len(array)
idx = 0
for n, i in enumerate(array):
    for m, j in enumerate(array[n + 1:]):
        if i == j:
            idx = m + n + 2
            break
    if idx != 0:
        break
print(idx)

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

line=[]
count=1

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

print(count)

Solution (Python):
a = []
i = 0

d = 0

s = int(input())

a.append(s)

while d != 1:
    if(a[i] % 2 == 0):
        if(a[i] / 2 != 0):
        	ans = int(a[i] / 2)
        else:
            ans = 0
        if ans in a:
            print(i + 2)
            d = 1
       	a.append(ans)
    else:
        anss = int(a[i] * 3 + 1)
        if anss in a:
            print(i + 2)
            d = 1
        a.append(anss)

    i += 1

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

Solution (Python):

def f(prev):

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




def collatz(s):
    nset = set()
    a_n = s
    for n in range(1,1000000):
        if a_n in nset:
            return n
        else:
            nset.add( a_n )

        a_n = f(a_n)



s = int( input())

n = collatz(s)

print(n)

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

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

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

print(ans)

Solution (Python):
from sys import stdin

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

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

    if S in (1, 2, 4):
        print(4)
    else:
        prev = S
        i = 2
        while 1:
            n = func(prev)
            if n == 4:
                print(i + 3)
                break
            prev = n
            i += 1

input = lambda: stdin.readline()
main()

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

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

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

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

Solution (Python):
s=int(input())
a=[s]
cnt=1
t=False
    
while True:
    cnt+=1
    if s%2==0:
        seven=int(s/2)
        s=seven
        for i,ai in enumerate(a):
            if ai==s:
                t=True
                break
        if t==False:
            s=seven
            a.append(seven)
        else:
            break
    else:
        sodd=int(s*3+1)
        s=sodd
        for i,ai in enumerate(a):
            if ai==s:
                t=True
                break
        if t==False:
            s=sodd
            a.append(sodd)
        else:
            break

print(cnt)

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

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

Solution (Python):
import numpy as np
import sys

s = input()

tempNum = int(s)

np1_array = np.array([int(s)])

count = 1
while(True):

    checkNum = tempNum % 2

    
    if checkNum == 0:
        tempNum = tempNum / 2
        np1_array = np.append(np1_array,tempNum)
    else:
        tempNum = 3 * tempNum + 1
        np1_array = np.append(np1_array,tempNum)

    count = count + 1

    checkNum2 = np.count_nonzero(np1_array == tempNum)
    if checkNum2 == 2:
        print(count)
        sys.exit()

Solution (Python):
flag = False
a = []
s = input()
a.append(int(s))

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

i = 0
while(flag == False):
    a.append(func(a[i]))
    for j in range(i - 1, -1, -1):
        if a[j] == a[i]:
            flag = True
            ans = i
            break
    i += 1

print(i)

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

Solution (Python):
s = input()

tag = 0
i = 1
num = []

while tag == 0:
    if i > 1000000:
        break
    num.append(int(s))
    if int(s)%2 == 0:
        s = int(s)/2
    else:
        s = 3*int(s) + 1
    i += 1
    for j in range(int(i)-1):
        if int(s) == int(num[j]):
            tag = 1
            print (i)
            break
        else:
            continue

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

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

s = int(input())
lst = []
i = 1
while True:
    if i == 1:
        a = s
        bef = s
    else:
        a = func(bef)
    if a in lst:
        break
    else:
        lst.append(a)
        bef = a
    i += 1
print(i)

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

Solution (Python):

def B():
    def odd(x):
        return int(3 * x + 1)
    
    def even(x):
        return int(x / 2)

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

    s = int(input())

    a_list = []
    a_list.append(s)
    
    for i in range(1000000):
        ai = a_list[i]

        if ai % 2 == 0:
            a_list.append(even(ai))
        else:
            a_list.append(odd(ai))

        if is_unique(a_list) is not  True:
            
            print(i + 1 + 1)
            break
    

if __name__== '__main__':
    B()

Solution (Python):
import sys
M = 10 ** 7
s = input()

a = {}
a_i1 = s
a[a_i1] = True
for i in range(1, M + 1):
    if a_i1 % 2 == 0:
        a_i2 = a_i1 / 2
    else:
        a_i2 = 3 * a_i1 + 1
    if a_i2 in a:
        print i + 1
        sys.exit()
    a_i1 = a_i2
    a[a_i1] = True

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


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

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


def add(x):
    y=int(x/2)
    return y

def even(x):
    y=3*x+1
    return y

cnt=0
flag=0
for i in range(1000000):
    if flag==0:
        if s%2==0:
            s=add(s)
            cnt+=1
            if s==4:
                flag=1
        else:
            s=even(s)
            cnt+=1
            if s==4:
                flag=1

if ss==1 or ss==2 or ss==4:
  print(4)
else:
  print(cnt+4)

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

for i in range(1,1000):
    if i == 1:
        A.append(s)
    else:
        if A[i-2]%2 == 0:
            G = int(A[i-2]/2)
            A.append(G)
        else:
            G = int(A[i-2]*3+1)
            A.append(G)
        if A.count(G) == 2:
            print(i)
            break

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

while True:
    li.append(s)

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

    i += 1

    if s in li:
        break

print(i)

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

aa = [s]
i = 1

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

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

input = list(map(int,input().split()))
start = int(input[0])

list = []

for i in range(1,1000000):
  if i == 1:
    list.append(start)
  else:
    temp = func(list[i-2])
    if temp in list:
      print(i)
      break
    else:
      list.append(temp)

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

Solution (Python):
def main():
    s = int(input())
    arr = [s]
    while True:
        tmp = 0
        if arr[-1] % 2 == 0:
            tmp = arr[-1] // 2
        else:
            tmp = arr[-1] * 3 + 1

        if tmp in arr:
            break
        arr.append(tmp)
    print(len(arr)+1)


main()

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

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

def a(n):
	if n==0:
		return 0
	if n==1:
		return s
	return f(a(n-1))

m=2
n=1
while a(m) != a(n): 
	if n + 1 < m :
		n += 1
	else:
		m += 1
		n  = 1

print(m)

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

Solution (Python):
s=int(input())
dic={str(s):1}
count=0
while True:
        if s%2==0:
                if str(s//2) not in dic:
                        dic[str(s//2)]=1
                        count+=1
                        s=s//2
                else:
                        break
        else:
                if str(s*3+1) not in dic:
                        dic[str(s*3+1)]=1
                        count+=1
                        s=s*3+1
                else:
                        break
print(count+2)

Solution (Python):
s = int(input())
f = lambda n: n/2 if n%2==0 else 3*n+1
se = [s]
while True:
  a = int(f(se[-1]))
  se.append(a)
  if a in se[:-1]:
    le = len(se[:se.index(a)+1])
    print(le+se[le:].index(a)+1)
    break

Solution (Python):


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

sList=[]
S = int(input())
sList.append(S)
num=nextNum(S)

while( num not in sList):
  sList.append(num)
  num=nextNum(num)
  
print(len(sList)+1)

Solution (Python):
import numpy as np
def func1(n):
    if n%2==0 :
        return int(n/2)
    else :
        return int(3*n+1)

def func2(r,s):
    m = 1
    while True:
        tmp = func1(s)
        m+=1
        if r.ndim == 0:
            if r == tmp:
                return m
        else:
            for tmp1 in r:
                if tmp == tmp1:
                    return m
        r = np.append(r,tmp)
        s=tmp


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

s = a[0]
r = np.array(s)
print(func2(r,s))

Solution (Python):
s = int(input())
 
memo = {}
memo[s] = 1

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

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

slist= [s]
ans = 2

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

    if s in slist:
        print(ans)
        break
    else:
        slist.append(s)
        ans += 1

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

cnt = 0
a_n = 0
a_m = 0
score = list()

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

Solution (Python):
s = []
s.append(int(input()))
A = set()
i = 0
A.add(s[0])

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

Solution (Python):
from sys import stdin
N=int(stdin.readline().rstrip())
a=[N]+[0]*10000
for i in range(10000):
    if i !=0:
        if a[i-1]%2==0:
            a[i]=int((a[i-1]/2))
        else:
            a[i]=int((3*a[i-1]+1))
cnt=1
tmp=[]
for j in a:
    if str(j) in tmp:
        break
    else:
        tmp.append(str(j))
        cnt+=1
print(cnt)

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

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

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

print(ans)

Solution (Python):
last = int(input())
m = set([last])
for i in range(2, int(1e7) + 2):
    if last & 1:
        a = last * 3 + 1
    else:
        a = last // 2
    if a in m:
        print(i)
        break
    m.add(a)
    last = a

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

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

end_flg = False
i = 1
suuretsu = [0,s]

while end_flg == False:
    i += 1
    if suuretsu[i-1] % 2 == 0:
        elem = suuretsu[i-1] / 2
    else:
        elem = 3*suuretsu[i-1]+1
    if elem in suuretsu:
        print(i)
        end_flg = True
    else:
        suuretsu.append(elem)

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

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

ans = -1
for i in range(1, 10 ** 6 + 1):
    if s in d:
        ans = i
        break
    else:
        d.add(s)
        if s % 2 == 0:
            s //= 2
        else:
            s = 3 * s + 1

print(ans)

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

num_list = [a]
init_flag = True
result = 1
while True:
	result += 1
	num = num_list[-1]
	if num%2 == 0:
		new_num = int(num/2)
	else:
		new_num = int(3*num+1)

	if not init_flag and new_num in num_list:
		
		print(result)
		break
	num_list.append(new_num)
	init_flag = False

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

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

print(i+1)

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

for i in range(1000):
    for j in range(i+1,1000):
        if a[i]==a[j]:
            print(j+1)
            sys.exit(0)

Solution (Python):



a = int(input())

list = [a]

n=1
k=0

while k == 0:
    if a % 2 == 0:
        b = a/2
        if b in list:
            break
    else:
        b = 3*a + 1
        if b in list:
            break
    list = list + [b]
    a = b
    n = n +1
    

print(n+1)

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

Solution (Python):
x=int(input())
a=[0]
a.append(x)
i=x
j=1

while True:
  k=int((i/2)*(i%2==0)+(3*i+1)*(i%2==1))
  
  if k in a:
    print(j+1)
    exit()
  else:
    a.append(k)
    i=k
    j=j+1
    continue

Solution (Python):
n = int(input())
nums = [n]
count = 1
flag = True

while flag :
    count += 1
    if (nums[-1] % 2):
        num = 3 * n + 1
        nums.append(num)
        if (nums.count(num) == 2):
            flag = False
    else :
        num = n / 2
        nums.append(num)
        if(nums.count(num) == 2):
            flag = False
    n = num

print(count)

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

Solution (Python):
s = int(input())
def foo(N, s):
  ls = [s]
  for i in range(N):
    a = ls[i]//2 if ls[i]%2==0 else (ls[i]*3+1)
    if a in ls:
      return i + 2
    else:
      ls.append(a)
  return False
print(foo(1000000, s))

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

s = int(input())
a=[0,s]
i=1
while True:
  newS = funcF(a[i])
  if newS in a:
    print(i+1)
    break
  a.append(newS)
  i += 1

Solution (Python):
def A():
    ab, bc, ca = map(int, input().split())
    print(int(bc * ab / 2))


def B():
    s = int(input())
    f_data = [s]
    i = 0
    tmp = [0 for i in range(1000001)]
    def f(n):
        if n % 2 == 0:
            return n // 2
        else:
            return 3 * n + 1
    ans = 0
    while True:
        if i == 0:
            f_data.append(s)
            tmp[s] = 1
        else:
            key = f(f_data[-1])
            f_data.append(key)
            if tmp[key] == 1:
                ans = i + 1
                break
            tmp[key] = 1
            
        if ans != 0:
            break
        i += 1
    
    print(ans)
B()

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

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

def main():

    s = int(input())
    
    count = 1
    
    a = [s]
    b = set(a)
    while len(a) == len(b):
        a.append(f(a[-1]))
        b = set(a)
        count += 1
        
    print(count)
    
main()

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

s = int(raw_input())
i = 1
while s != 4 and s != 2 and s != 1:
  s = f(s)
  i += 1
print i+3

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

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

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

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

for i in range(2, 1000000):
    if a_list[-1] % 2 != 0:
        tmp = 3 * a_list[-1] + 1
        if tmp in a_list:
            print(i)
            exit()
        else:
            a_list.append(tmp)
    else:
        tmp = a_list[-1] / 2
        if tmp in a_list:
            print(i)
            exit()
        else:
            a_list.append(tmp)

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

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

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

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

def collatz(n):
    c = 0
    while not n in (4, 2, 1):
        if n % 2 == 0:
            n = n/2
        else:
            n = n * 3 + 1
        c += 1
        
    return c

print(collatz(n) + 4)

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

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

done = [s]
for i in range(10000000):
    tmp = calc(done[i])
    if tmp in done:
        print(i + 2)
        exit()
    else:
        done.append(tmp)

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

num = int(input())

a = []
a.append(num)
while True:
    an = function(a[-1])
    for i in range(len(a)):

        if a[i] == an:
            a.append(an)
            print('{}'.format(len(a)))
            exit()

    a.append(an)

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

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

d = []
i = 0


def e(i):
    return int(i / 2)
def f(i):
    return int(3 * i + 1)

    
while(len(d) == len(set(d))):
    if i == 0:
        d = [s]
        o = s
    elif o % 2 != 0:
        o = f(o)
        d.append(o)
    else:
        o = e(o)
        d.append(o)
    i += 1

print(i)

Solution (Python):
A = [0, 4, 4, 9, 4, 7, 10, 18, 5, 21, 8, 16, 11, 11, 19, 19, 6, 14, 22, 22, 9, 9, 17, 17, 12,25, 12, 113, 20, 20, 20, 108, 7, 28, 15, 15, 23, 23, 23, 36, 10, 111, 10, 31, 18, 18, 18,106, 13, 26, 26, 26, 13, 13, 114, 114, 21, 34, 21, 34, 21, 21, 109, 109, 8, 29, 29, 29, 16, 16, 16, 104, 24, 117, 24, 16, 24, 24, 37, 37, 11, 24, 112, 112, 11, 11, 32, 32, 19, 32,19, 94, 19, 19, 107, 107, 14, 120, 27, 27, 27]

print(A[int(input())])

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

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

c = [0 for _ in range(1000001)]
c[s] = 1
for m in range(2, 1000001):
    s = s // 2 if s % 2 == 0 else 3 * s + 1
    if c[s] == 1:
        print(m)
        break
    else:
        c[s] = 1

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

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

s = int(input())

cnt=1
l = []
j=False
while j==False:
    if s in l:
        print(cnt)
        j=True
    l.append(s)
    s = f(s)
    cnt+=1

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

s = int(input())
a = [s]
i = 1
while f(a[i-1]) not in a:
    a.append(f(a[i-1]))
    i += 1
print(i+1)

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

Solution (Python):

s = int(input())
n_list = []
n_list.append(s)
end_flag = False
while not end_flag:
    if n_list[-1]%2 == 0:
        if (n_list[-1]/2) in n_list:
            print(len(n_list)+1)
            end_flag = True
        else:
            n_list.append(n_list[-1]/2)
    else:
        if (3*(n_list[-1])+1) in n_list:
            print(len(n_list)+1)
            end_flag = True
        else:
            n_list.append(3*(n_list[-1])+1)

Solution (Python):

"""
Created on Sun Jan 20 20:51:59 2019

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy


def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*M
Y = [0]*M
for m in range(M):
    P[m], Y[m] = map(int, input().split())
    
all(nstr.count(c) for c in '753')
"""

s = int(input())

a = []

a.append(s)

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

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

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

def solver(v):
    ary = []
    for i in range(10**6):
        if i == 0:
            ary.append(v)
        else:
            v = f(ary[-1])
            if v in ary:
                return i+1
            else:
                ary.append(v)

s = int(input())
print(solver(s))

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_int_list():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


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


def main():
    s = get_int()
    a_set = {s}
    a = f(s)
    for i in itertools.count(2):
        if a in a_set:
            print(i)
            return
        a_set.add(a)
        a = f(a)


if __name__ == '__main__':
    main()

Solution (Python):

import itertools
s = int(input())
used = set()
for i in itertools.count():
    used.add(s)
    if s % 2 == 0:
        s /= 2
    else:
        s = s * 3 + 1
    if s in used:
        break
print(i + 2)

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

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

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

Solution (Python):
s = int(input())
count=0
flag=0
n = s
fourflag=0
if n == 2:
    fourflag=1
if n == 1:
    fourflag=1
while flag<2:
    if n ==4:
        flag+=1
    count+=1
    if n%2 ==0:
        n/=2
    else:
        n=3*n+1


    if flag==2:
        break
        
    
    
if fourflag==0:
    print(count)
else:
    print(4)

Solution (Python):
""" AtCoder """

import sys
input = sys.stdin.readline

s = int(input())

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

ans_list = []
ans_list.append(s)

i = 1

while True:
    if f(ans_list[i-1]) in ans_list:
        print(i+1)
        break
    ans_list.append(f(ans_list[i-1]))
    i += 1

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

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

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

for i in range(1,10**9):
    if a[-1]%2 ==0:
        tmp = a[-1]//2
    else:
        tmp = a[-1]*3+1
    
    if tmp in a:
        print(i+1)
        exit()
    else:
        a.append(tmp)