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



Sample input:
8


Sample output:
5

Submission status: Accepted

Solution code:
# ABC116
# B
import numpy as np
s = int(input())

a = s
idx = 1
a_list = [a]
while(idx < 1000000):
    idx += 1
    if a % 2 == 0:
        a = int(a / 2)
    else:
        a = 3*a+1
    if a in a_list:
        print(idx)
        break
    else:
        a_list.append(a)

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

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

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [s] = [long(input_raw[0])]

    i = 0
    pre_a = s
    appare_set = set([pre_a])
    count = 1

    while 1:
        a = func(pre_a)
        count += 1
        if a in appare_set:
            print count
            return
        else:
            appare_set.add(a)
            pre_a = a



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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


def main():
    """Function."""
    s = int(input())

    check_dic = {}
    check = set()

    old = s
    counter = 1

    while old not in check:
        # print(old,counter)
        check.add(old)
        check_dic[old] = counter

        counter += 1
        old = fn(old)

    # print("!!!!!!!!!!!")
    print(counter)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


abc116_b()

Submission status: Accepted

Solution code:
import math
import copy




def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l

a=nCast(input())

def f(i):
    if i%2==0:
        return i/2
    return i*3+1
def func():
    s=set()
    idx=2
    pre=a
    s.add(a)
    while True:
        
        number=f(pre)
        if number in s:
            return idx
        idx+=1
        s.add(number)
        pre=number

print(func())

Submission status: Accepted

Solution code:
s = int(input())
i = 1
l = [1, 2, 4]
while True:
    if s in l:
        print(i + 3)
        break
    i += 1
    if s % 2 == 0:
        s //= 2
    else:
        s = 3 * s + 1

Submission status: Accepted

Solution code:
s = int(input())

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

result = [s]
for i in range(1, 1000000):
    s = f(s)
    if s in result:
        print(i+1)
        exit()
    result.append(s)

Submission status: Accepted

Solution code:
# %%
s = int(input())


# %%
def a_n(a_n_1):
    if a_n_1 % 2 == 0:
        return a_n_1 // 2
    else:
        return 3 * a_n_1 + 1


# %%
a = [s]
m = 1
a_n_1 = s

while (a_n_1 not in a[:m - 1]):
    a_n_1 = a_n(a_n_1)
    a.append(a_n_1)
    m += 1
else:
    print(m)

Submission status: Accepted

Solution code:

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

def main():
    number = int(input())
    hist = set()
    hist.add(str(number))
    while 1:
        number = calc_number(number)
        # print(number)
        if str(number) in hist:
            # print(hist)
            print(len(hist) + 1)
            break
        else:
            hist.add(str(number))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = int(input())
l = [a,a]
n = 1
end = 0
tmp = 0
while end == 0:
    if l[n] % 2 == 0:
        tmp = int(l[n]/2)
    else:
        tmp = int(l[n]*3 + 1)
    n = n + 1
    if tmp in (l):
        end = 1
    l.append(tmp)

print(n)

Submission status: Accepted

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

s = int(input())
aPrev = s
isFound = [False] * 10**6
isFound[aPrev] = True
for m in range(2, 10**6 + 1):
    a = f(aPrev)
    if isFound[a]:
        print(m)
        break
    aPrev = a
    isFound[a] = True

Submission status: Accepted

Solution code:
s = int(input())
flag = [0] * 1000001
flag[s] = 1
for i in range(1, 1000001):
    if s % 2:
        s = 3 * s + 1
    else:
        s = s // 2
    if flag[s]:
        print(i+1)
        break
    flag[s] = 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
a = set([s])
x = s
ans = 1
while len(a) == ans:
  if x%2 == 0:
    x = int(x/2)
    a.add(x)
    ans += 1
  else:
    x = 3*x+1
    a.add(x)
    ans += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())
ss = set()
ss.add(s)
k = 1
while True:
    if s%2 == 0:
        s = s/2
    else:
        s = 3*s + 1
    s = int(s)
    if s in ss:
#         print(s,s)
        break
    ss.add(s)
#     print(s)
    k+=1
#     print(s)
print(k+1)

Submission status: Accepted

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

x = {}
i = 1
x[s] = i
while True:
  i += 1
  k = f(s)
  if k in x:
    print(i)
    break
  x[k] = i
  s = k

Submission status: Accepted

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

  if s in nums:
    print(len(nums)+1)
    exit()
  else:
    nums.append(s)

Submission status: Accepted

Solution code:
s = int(input())
def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3*n + 1
flag = [0 for i in range(1000001)]
flag[s] = 1
a = [s]

for i in range(1000000):
    a.append(f(a[i]))
    if flag[a[i+1]] == 1:
        break
    else:
        flag[a[i+1]] = 1
print(len(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())

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

Submission status: Accepted

Solution code:
s = int(input())
a = [0]*1000010

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

Submission status: Accepted

Solution code:
s = int(input())
S = [s]
#print(S)
N = 1000000
for i in range(N):
	if s%2 == 0:
		s = s//2

		#print(s)

		if s in S:
			ans = i+2
			break
		S.append(s)
	else:
		s = 3*s+1

		#print(s)

		if s in S:
			ans = i+2
			break
		S.append(s)
#print(S)
print(ans)

Submission status: Accepted

Solution code:
s = int(input())
k = set()
k.add(s)
a = [s]
a1 = s
i = 2
while True:
    if a[-1] % 2 == 0:
        #k.add(a[-1] // 2)
        a.append(a[-1]//2)

    else:
        #k.add(3 * a[-1] + 1)
        a.append(3*a[-1] + 1)

    if a[-1] in k:
        print(i)
        exit()
    else:
        k.add(a[-1])
        i += 1

Submission status: Accepted

Solution code:
s = int(input())
lines = [s]
for line in lines:
  if(line%2 == 0):
    even = int(line / 2)
    if(even not in lines):
      lines.append(even)
    else:
      break
  else:
    odd = 3*line + 1
    if(odd not in lines):
      lines.append(odd)
    else:
      break
print(lines.index(lines[-1])+2)

Submission status: Accepted

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


def main():
    series = [int(input())]
    for i in range(1000000):
        s = f(series[-1])
        if s in series:
            print(i + 2)
            return
        else:
            series.append(s)


main()

Submission status: Accepted

Solution code:
import numpy as np

s=input()
s=int(s)
lst=[]
judge=True
count=0
while lst.count(s)==0:
    lst.append(s)
    count+=1
    if s%2==0:
        s=s/2
    else:
        s = 3*s + 1
    
print(count+1)

Submission status: Accepted

Solution code:
def main():
    S = int(input())
    a = [S]
    i = 0
    while True:
        i += 1
        if a[i - 1] % 2 == 0:
            a_ = a[i - 1] / 2
        else:
            a_ = 3 * a[i - 1] + 1
        if a_ in a:
            print(i + 1)
            return
        a.append(a_)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

s = int(input())

array = []

while s not in array:
	array.append(s)
	s = f(s)

print(len(array)+1)

Submission status: Accepted

Solution code:
S = int(input())

a = set([])

a1 = S
i = 0
while not(a1 in a):
    a.add(a1)
    i = i + 1
    if (a1 % 2 == 0):
        a1 = int(a1 / 2)
    else:
        a1 = a1 * 3 + 1

print(i+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
dic={}
dic[s]=dic.get(s,0)+1
i=1
while True:
	if s%2==0:
		s=s//2
	else:
		s=3*s+1
	dic[s]=dic.get(s,0)+1
	if dic[s]>=2:
		print(i+1)
		exit(0)
	i+=1

Submission status: Accepted

Solution code:
s = int(input())
a = [s]
for i in range(1, 11000):
    if a[i - 1] % 2 == 0:
        tmp = a[i - 1] // 2

        if a.count(tmp) == 1:
            print(i + 1)
            break
        else:
            a.append(tmp)
    else:
        tmp = 3 * a[i - 1] + 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# N = input()   # 単純な入力
# input = list(input()) # ひとかたまりの文字列をリスト化
N = int(input())  # 整数一つ
# input = input().split()   # スペース区切りを文字としてリスト化
# X,Y = map(int,input().split())  # ２個や３個の整数をそれぞれ取得
# input = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
init = int(input())
numbers = []
counter = 1
a = init
while a not in numbers:
    numbers.append(a)
    if a % 2 == 0:
        a = a // 2
    else:
        a = 3*a + 1
    counter += 1
print(counter)

Submission status: Accepted

Solution code:
s = int(input())

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

a =[]

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

Submission status: Accepted

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

print(ans +1 )

Submission status: Accepted

Solution code:
import numpy
def func(s):
	if s % 2 == 0:
		return int(s/2)
	else:
		return 3*s + 1
s = int(input())
check = numpy.zeros(1000010)
check[s] = 1
Ind = 1
while True:
	s = func(s)
	Ind += 1
	if check[s] == 1:
		print(Ind)
		exit()
	else:
		check[s] = 1

Submission status: Accepted

Solution code:
s = int(input())
def f(n):
  if n%2:
    return 3*n+1
  else:
    return n/2
L = []
for m in range(1000000):
  if sum(x == s for x in L):
    print(m+1)
    break
  else:
    L.append(s)
    s = f(s)

Submission status: Accepted

Solution code:
s = int(input())

seta = set()
seta.add(s)

p = s
c = s
i = 2
while True:
    if p%2 == 0:
        c = p//2
    else:
        c = 3*p+1

    if c in seta:
        break
    else:
        seta.add(c)

    p = c
    i += 1

print(i)

Submission status: Accepted

Solution code:
s = int(input())

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

print(cnt + 3)

Submission status: Accepted

Solution code:
#!/Users/takahiro.kida/git/atcorder/venv/bin/python

import numpy
import scipy

from collections import defaultdict
from pprint import pprint

a1 = int(input())
#a = [int(x) for x in input().split(" ")]
x = a1
cnt = 1
a = {a1: 1}
while True:
    cnt += 1
    if x % 2 == 0:
        x = int(x / 2)
    else:
        x = 3 * x + 1
    if x in a:
        break
    else:
        a[x] = 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())
count = 1
if s == 4 or s == 2 or s == 1:
    print(4)
    exit()

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 20 21:02:12 2019

@author: owner
"""

s=int(input())
dic={}
ans=0

dic[s]=1
for i in range(2,1000001):
    if s%2==0:
        s//=2
    else:
        s=3*s+1
    if dic.get(s,0)>0:
        ans=i
        break
    else:
        dic[s]=1
print(ans)

Submission status: Accepted

Solution code:
c=int(input())
s=[c]
for i in range(100000):
    if c%2!=1:
        c=c//2
    else:
        c=3*c+1
    if not c in s:
        s.append(c)
    else:
        print(i+2)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
l = []
l.append(s)
a = [0] * 100000
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
  if a[i] in l:
    print(i+1)
    break
  else:
    l.append(a[i])

Submission status: Accepted

Solution code:
s = int(input())

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

numlist = [s]
for i in range(1000000):
    if i+1 == 1:
        x = s
    else:
        x = x
    x = f(x)
    if numlist.count(x) == 1:
        print(i+2)
        break
    else:
        numlist.append(x)

Submission status: Accepted

Solution code:
s = int(input())

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

se = set()
se.add(s)

i = 2
a = s
while True:
    a = f(a)
    if a in se:
        print(i)
        break
    se.add(a)
    i += 1

Submission status: Accepted

Solution code:
s= int(input())
num_list = []

def function_tmp(n):
    if n % 2 == 0:
        return n/2
    else:
        return 3*n +1
tmp = s
cnt = 1
while not(tmp in num_list):
    num_list.append(tmp)
    tmp = function_tmp(tmp)
    #print(num_list)
    cnt += 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

s = int(input())

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


l = []
l.append(s)

for i in range(10000000000):
	# i + 2がm
	a = f_n(l[-1])

	if a in l:
		print(i + 2)
		break
	else:
		l.append(f_n(l[-1]))

Submission status: Accepted

Solution code:
s=int(input())
a=[s]
tmp=s
index=1
while True:
    if tmp%2==0:
        tmp=tmp/2
        a.append(int(tmp))
        index+=1
    else:
        tmp=tmp*3+1
        a.append(int(tmp))
        index+=1

    if len(a)!=len(list(set(a))):
        print(index)
        exit(0)

Submission status: Accepted

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

p = int(input())
t = {p}
m = 1
while True:
    m += 1
    p = f(p)
    if p in t:
        break
    t.add(p)
print(m)

Submission status: Accepted

Solution code:
s = int(input())

res = s
i = 1


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
s = set()
for i in range(1,1000002):
  if a in s:
    print(i)
    exit()
  s.add(a)
  if a%2==0:
    a=a//2
  else:
    a=a*3+1

Submission status: Accepted

Solution code:
s=int(input())

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

Submission status: Accepted

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

s = int(input())
m = s
q = set([s])
r = 1
while True:
  r += 1
  if f(m) in q:
    print(r)
    break
  else:
    q.add(f(m))
    m = f(m)

Submission status: Accepted

Solution code:
s = int(input())

li = [s]
n = 2
while 1:
    if s%2:
        s = s*3+1
    else:
        s //= 2

    if s in li:
        print(n)
        exit()
    else:
        li.append(s)
        n+=1

Submission status: Accepted

Solution code:
s = int(input())

a = s

a_list = [a]

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

print(len(a_list) + 1)

Submission status: Accepted

Solution code:
s = int(input())
count = 1
tmp = [s]
res = 0
while True:
    if s%2==1:
        s = s*3+1
    else:
        s = s//2
    count += 1
    if s in tmp:
        res = count
        break
    else:
        tmp.append(s)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

a=[]
a.append(s)
for m in range(2,1000001):
    x = f(a[m-2])
    if x in a:
        ans = m
        break
    else:
        a.append(x)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = int(input())
d = {s:1}
before = s
i = 1

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

while True:
    i += 1
    ai = f(before)
    if ai in d:
        res = i
        break
    else:
        d[ai] = i
        before = ai

# print(d)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
s = int(input())

searched = [0]*(10**6+1)

def func(x):
    if x%2 == 0:
        return x//2
    else:
        return 3*x + 1
searched[s] = 1
for i in range(2, 10**6+2):
    s = func(s)
    if searched[s]:
        print(i)
        break
    else:
        searched[s] = i

Submission status: Accepted

Solution code:
s=int(input())
a={s}
i=1
an_1=s
def f(num):
    if num%2==0:
        return num//2
    else:
        return num*3+1
while True:
    i+=1
    an=f(an_1)
    if an in a:
        print(i)
        break
    else:
        a.add(an)
        an_1=an

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()

u = set([n])
cnt = 2
while True:
    if n % 2:
        n = 3 * n + 1
    else:
        n //= 2
    if n in u:
        print(cnt)
        exit()
    u.add(n)
    cnt += 1

Submission status: Accepted

Solution code:
s = int(input())
a = set()
a.add(s)

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

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

x = ip()                              #入力整数1つ
#x,y= (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#x = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意
a = []
a.append(x)
num =1
while True:
    num+=1
    if x%2:
        x = (3*x)+1
    else: x//=2
    if x in a:
        print(num)
        exit(0)
    a.append(x)

Submission status: Accepted

Solution code:
s = int(input())
def an(n):
    if n == 1:
        return s
    else:
        return f(an(n-1))

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

se = set()
n = 1
while True:
    a = an(n)
    #print(n,a)
    if a in se:
        print(n)
        exit()
    se.add(a)
    n += 1

Submission status: Accepted

Solution code:
S = int(input())


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


collatz_list = []
collatz_set = set()
num = S
ans = 1
while True:
    if num in collatz_set:
        break
    else:
        collatz_list.append(num)
        collatz_set.add(num)
        num = collatz(num)
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
s = int(input())
a = set([s])
for i in range(2, 1000000):
  if s % 2 == 0:
    t = s // 2
  else:
    t = 3 * s + 1
  if t in a:
    print(i)
    exit()
  a.add(t)
  s = t

Submission status: Accepted

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

s = int(input())
i = 1
seta = set([s])
while True:
    s = f(s)
    if s in seta:
        break
    seta.add(s)
    i += 1
print(i + 1)

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

Solution code:
s = int(input())

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

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


print(ans)

Submission status: Accepted

Solution code:
s = int(input())
tmp = [False] * 1000001
i = 1
a = s
tmp[a] = True
while True:
    if a % 2 == 0:
        a //= 2
        i += 1
        if tmp[a]:
            print(i)
            exit()
        tmp[a] = True
    else:
        a = 3*a + 1
        i += 1
        if tmp[a]:
            print(i)
            exit()
        tmp[a] = True

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())

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

ai=s
i=1
a=[s]


while True:
	if f(ai) in a:
		print(i+1)
		break
	else:
		a.append(f(ai))
		ai=f(ai)
		i+=1

Submission status: Accepted

Solution code:
s = int(input())
f = lambda n: n//2 if n%2 == 0 else 3*n+1
a = set([s])
for m in range(2, 10**6+1):
    s = f(s)
    if s in a:
        print(m)
        break
    a.add(s)

Submission status: Accepted

Solution code:
s = int(input())

def f(n):
    if n % 2 == 0:
        return int(n / 2)

    else:
        return int(3*n + 1)

x = []

x.append(s)
y = 1
while True:
    y += 1
    s = f(s)
    if s in x:
        print(y)
        exit()
    x.append(s)

Submission status: Accepted

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


s = int(input())
i = 2
a = s
b = f(s)
d = {s: 1}
while b not in d:
    d[b] = 1
    a = b
    b = f(b)
    i += 1
print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
a = [s]
cnt = 2

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

Submission status: Accepted

Solution code:
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
s=I()
sl=[s]
i=1
while True:
    t=s
    if s%2==0:
        s=t//2
    else:
        s=3*t+1
    
    if s in sl:
        print(len(sl)+1)
        break
    else:
        sl.append(s)

Submission status: Accepted

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

s = int(input())
lst = [s]
for i in range(1, 1000001):
    x = f(lst[-1])
    if x in lst:
        break
    lst.append(x)
print(i+1)

Submission status: Accepted

Solution code:
s = int(input())

a = [s]

for i in range(1, 1000001):
    now = 0
    if a[i-1] % 2 == 0:
        a.append(a[i-1] // 2)
        now = a[i-1] // 2

    else:
        a.append(a[i-1] * 3 + 1)
        now = a[i-1] * 3 + 1

#    print(a)
    
    if now in a[:i]:
        print(i+1)
        break

Submission status: Accepted

Solution code:
s = int(input())

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

S = {s}
for i in range(10 ** 6):
    s = f(s)
    if s in S:
        print(i + 2)
        break
    else:
        S.add(s)

Submission status: Accepted

Solution code:
from sys import stdin
s = set()
cur = 1
a = int(stdin.readline())
while True:
  if a in s:
    break
  s.add(a)
  cur = cur+1
  if a%2==0:
    a= a/2
  else:
    a = 3*a+1
print cur

Submission status: Accepted

Solution code:
from collections import defaultdict
H = defaultdict(lambda: 0)
s = int(input())
ctr = 1
while True:
    if H[s]:
        break
    H[s] = ctr
    ctr += 1
    s = (s//2, 3*s+1)[s%2]
print(ctr)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
X = set()
X.add(s)


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


for ans in range(2, 10 ** 6 + 1):
    am = f(s)
    if am in X:
        print(ans)
        break
    else:
        s = am
        X.add(am)

Submission status: Accepted

Solution code:
s = int(input())

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

i = 1
pre = set()
pre.add(s)
while i < 10 ** 6 + 1:
    tmp = f(s)
    if tmp in pre:
        print(i + 1)
        exit()
    i += 1
    s = tmp
    pre.add(tmp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = int(input())


x = S
cs = set()
cs.add(x)
i = 1
while 1:
    i += 1
    if x % 2 == 0:
        x //= 2
    else:
        x = x * 3 + 1
    if x in cs:
        break
    cs.add(x)

print(i)

Submission status: Accepted

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