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:
""" 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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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(n)
    print(tmp+4)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s=int(input())
count=1
while s != 4 and s != 2 and s != 1:
    if s % 2 == 1:
        s = 3*s + 1
    else:
        s = s // 2
    count+=1
print(count + 3)

Submission status: Accepted

Solution code:
s = int(input())

def gusu_fanc(num):
    ans = int(num / 2)
    return ans

def kisu_fanc(num):
    ans = int(3 * num + 1)
    return ans

num_list = [s]
hantei = 0
numbers = s

while hantei == 0:
    #次の項を追加
    if numbers % 2 == 0:
        numbers = gusu_fanc(numbers)
    else:
        numbers = kisu_fanc(numbers)
    num_list.append(numbers)
    #チェック
    for i in range(len(num_list)-1):
        if num_list[i] == numbers:
            hantei = 1
print(i+2)

Submission status: Accepted

Solution code:
s = int(input())

l = [s]
count = 1

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

    count += 1

    if l[-1] in l[:-1]:
        print(count)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
s = int(stdin.readline().rstrip())
numss = [s]
while True:
    if numss[-1] % 2 == 0:
        numss.append(int(numss[-1]/2))
    else:
        numss.append(int(3*numss[-1] + 1))
    
    if numss[-1] == 1:
        numss.extend([4,2,1])
        break
for i in range(len(numss)-1):
    if numss[i+1] in numss[:i+1]:
        print(i+2)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(raw_input())

i = 1
a = s

if a in [1, 2, 4]:
    print(4)
    exit()

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

Submission status: Accepted

Solution code:
s = int(input())
if s == 1 or s == 2:
    print(4)
else:
    def f(n):
        if n % 2 == 0:
            return int(n / 2)
        else:
            return 3 * n + 1
    LIST = []
    a=s
    while a!=1:
        LIST.append(a)
        a=f(a)
    print(len(LIST)+2)

Submission status: Accepted

Solution code:
s = int(input())

count=1
judge=0
an=s

if an<3 or an==4:
    judge = 1
    cout=1
while judge==0:   
    if an%2==0:
        next_a=an/2
    else:
        next_a=3*an+1
    count+=1
    an=next_a
    if(an<3)or(an==4):
        judge = 1

print(count+3)

Submission status: Accepted

Solution code:
s = int(input())

i = 0

alist = [s]

while 1:
    i += 1

    if alist[i-1] % 2 == 0:
        atmp = alist[i-1] / 2
    
    elif alist[i-1] % 2 == 1:
        atmp = alist[i-1]*3 + 1

    alist.append(atmp)

    if len(alist) != len(set(alist)):
        print(i+1)
        break

Submission status: Accepted

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

s = int(input())

nums = [s]
n = 1
while s not in nums[0:n-1:]:
    s = f(s)
    nums.append(s)
    n += 1

print(n)

Submission status: Accepted

Solution code:
s = int(input())
list = []
if s <= 2:
    print(4)
else:
    for i in range(100000):
        if i == 0:
            list.append(s)
        else:
            if list[i-1] % 2 == 0:
                temp = int(list[i-1] / 2)
            else:
                temp = int(list[i-1]) * 3 + 1
            list.append(temp)
        if list[i] == 4:
            break
    print(len(list)+3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

s = int(input())

a = [s]
cnt1 = 0
for i in range(1, 1000000):
    n = a[i - 1]
    a.append(int(n / 2) if n % 2 == 0 else 3 * n + 1)
    if (a[-1] == 1):
        cnt1 += 1
        if (cnt1 == 2):
            break
            
m = 0
for i in range(0, len(a)):
    an = a[i]
    for j in range(i + 1, len(a)):
        if (an == a[j]):
            m = j
            break
    else:
        continue
    break

print(m + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input())

tplist = [s]
x = 1
while True:
    temp = f(tplist[-1])
    x += 1
    if temp in tplist:
        break
    tplist.append(temp)


print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
s = int(input())

a = [s]
b = [s]
def f(n):
    if(n % 2 == 0):
        return n/2
    else:
        return 3 * n + 1
n = 1
while(True):
    tmp = f(a[n-1])
    insert_index = bisect.bisect_left(b, tmp)
    if len(b) > insert_index and b[insert_index] == tmp:
        ans = n + 1
        break
    else:
        if len(b) == insert_index:
            b.append(tmp)
        else:
            b.insert(insert_index, tmp)
        a.append(tmp)
    n += 1

print(ans)

Submission status: Accepted

Solution code:
s=int(input())
cnt=[]
flag=0
cnt.append(s)
i=0

while flag==0:
  i+=1
  if s%2==0:
    s=int(s/2)
    m=len(cnt)
    cnt.append(s)
    
    n=len(set(cnt))
    if m==n:
      ans=i
      break
  else:
    s=3*s+1
    m=len(cnt)
    cnt.append(s)
    
    n=len(set(cnt))
    if m==n:
      ans=i
      break
  
print(ans+1)

Submission status: Accepted

Solution code:
a = int(input())

for i in range(1,1000001):
    #print(a)
    if a == 4 or a == 2 or a == 1:
        print(str(i+3))
        exit()
    if a % 2 == 0:
        a = a // 2
    else:
        a = 3 * a + 1

Submission status: Accepted

Solution code:
s = int(input())

r = 1
l = 0

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

i = 1
L = [s]
while (True):
    i += 1
    s = f(s)
    #print(s)
    if (s in L):
        break
    L.append(s)
print(i)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    s = int(input())

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

Submission status: Accepted

Solution code:
s = int(input())
a = []
count = 1
finish = 0

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

    a.append(s)
    
    count = count + 1

    for i in range(count -1):
        if a[i] == s:
            finish = 1

print(count)

Submission status: Accepted

Solution code:
s = int(input())

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

for i in range(1000000):
    if s % 2 == 0:
        s /= 2
    elif s % 2 == 1:
        s = 3 * s + 1

    if s == 4:
        print(i+5)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

    an = s
    lst = [an]
    tmp = 10000001

    i = 1
    while True:
        i+=1
        if an%2  == 0:
            an = an/2
            tmp = an
            if tmp in lst:
                print(i)
                exit()

            lst.append(an)

        else:
            an = an*3+1
            tmp = an
            if tmp in lst:
                print(i)
                exit()

            lst.append(an)


if __name__ == "__main__":
        main()

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

S = input()
a = []
i = 0
a.append(int(S))
while(True):
    next = func(a[i])
    if(next in a):
        break
    else:
        a.append(next)
        i+=1

print(i+2)

Submission status: Accepted

Solution code:
s=int(input())
a=[]
a.append(s)
c=0
while c==0:
    if s%2==0:
        a.append(s//2)
    elif s%2==1:
        a.append(3*s+1)
    s=a[-1]
    for i in range(len(a)-1):
            if s==a[i]:
                c=len(a)
print(c)

Submission status: Accepted

Solution code:
s = int(input())

l = [s]
i = 0
while(True):

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

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    s = int(input())
    a = list()
    a.append(s)
    i = 0

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

        i += 1

        if tmp in a:
            print(i + 1)
            exit()

        a.append(tmp)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = I()
l = [0]*10000000
l[0] = s

for i in range(1,10000000):
    if l[i-1] % 2 == 0:
        l[i] = l[i-1]//2
    else:
        l[i] = l[i-1]*3+1
    if l[i] in l[:i-1]:
        ans = i+1
        break

print(ans)

Submission status: Accepted

Solution code:
s = int(input())

a = [-1]
a.append(s)

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

print(len(a)-1)

Submission status: Accepted

Solution code:
import sys

s = int(input())

a = []
a.append(s)
i = 1

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


while True:
    val = f(a[i-1])
    if val in a:
        print(i+1)
        sys.exit()
    a.append(val)
    i += 1

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    s = int(input())
    elements = set()
    elements.add(s)

    i = 1
    val = s
    while True:
        val = f(val)
        elements.add(val)
        if len(elements) != i + 1:
            print(i + 1)
            exit()
        i += 1


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = int(input())

num_set = set()
num_set.add(s)
ans = 1
while True:
    if s % 2 == 0:
        s = int(s / 2)
    else:
        s = int((3 * s) + 1)
    ans += 1
    if s not in num_set:
        num_set.add(s)
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
s = int(input())
m = 1
ans = 0

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

if s==1 or s==2:
    ans = 4
    
else :

    while s!=1 :
        s = func(s) + 0
        m += 1

    ans = m+1

print(ans)

Submission status: Accepted

Solution code:
def a(n):
  return n//2
def b(n):
  return 3*n+1

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

n = 0
while(True):
  if num[-1] % 2 == 0:
    ans = a(num[-1])
  else:
    ans = b(num[-1])
   
    
    
  if ans in num:
    break
  else:
    num.append(ans)
  n+=1
    
print(n+2)

Submission status: Accepted

Solution code:
import numpy as np


a = int(input())

def f(a):
    count = np.zeros(1000000, dtype=int)
    loop_i = 1
    while True:
        count[a-1] += 1
        if count[a-1] == 2:
            return loop_i
        a = a // 2 if a % 2 == 0 else 3 * a + 1
        loop_i += 1

out = f(a)
print(out)

Submission status: Accepted

Solution code:
s = int(input())

a = set([s])
ai = s
for i in range(2, 10**6+1):    
    if ai % 2 == 0:
        ai = ai // 2
    else:
        ai = 3 * ai + 1
    if ai in a:
        ans = i
        break
    a.add(ai)
    
print(i)

Submission status: Accepted

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


def main():
    s = int(input())
    l = [s]
    c = s
    while True:
        c = int(f(c))
        if c in l:
            n = len(l) + 1
            break
        l.append(c)
    print(n)



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())
a = [s]
i = 1
while True:
    ai = f(a[i - 1])
    if ai in a:
        break
    a.append(ai)
    i += 1
print(i + 1)

Submission status: Accepted

Solution code:
s = int(input())


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



#%%
a = [s]
ai = 0


#%%
while True:
    # print(a)
    ai = f(a[-1])
    a.append(ai)
    if a.count(ai) == 2:
        break

#%%
print(len(a))

#%%

Submission status: Accepted

Solution code:
#coding:utf-8
s = int(input())
ls = [s]
while(1):
    n = ls[-1]
    if  n % 2 == 0:
        new = n / 2
    else:
        new = 3*n + 1
    if new in ls:
        print (len(ls)+1)
        break
    else:
        ls.append(new)

Submission status: Accepted

Solution code:
s = int(input())
l = {s}
if s % 2 == 0:
    s //= 2
else:
    s = s * 3 + 1
i = 1
while s not in l:
    l.add(s)
    if s % 2 == 0:
        s //= 2
    else:
        s = s * 3 + 1
    i += 1
else:
    i += 1
print(i)

Submission status: Accepted

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

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

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

for m in range(1, 1000001):
    a_m = f(a[m-1])

    if a_m in a:
        print(m+1)
        break
    else:
        a.append(a_m)

Submission status: Accepted

Solution code:
s = int(input())

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

a = [s]

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

Submission status: Accepted

Solution code:
s = int(input()) #整数

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

Submission status: Accepted

Solution code:
s=input()

A=set()
for i in range(10**6+10):

	if i==0:
		pass
	else:
		if s%2==0:
			s/=2
		else:
			s=3*s+1
	if s in A:
		print i+1
		quit()
	else:
		A.add(s)

Submission status: Accepted

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

a_0 = int(input())
A_n = [a_0]
m = 0
while True:
    A_n.append(func(A_n[m]))
    m += 1
    if A_n.count(A_n[m]) == 2:
        print(m+1)
        break

Submission status: Accepted

Solution code:
s=int(input())

a=s
cnt=1
dic={a:1}
while (1):
    if a % 2 == 1 :
        a=3*a+1
    else:
        a=a/2
    if a in dic :
        print(cnt+1)
        break
    dic[a]=1
    cnt+=1

Submission status: Accepted

Solution code:
s = int(input())

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


a = [s]
for i in range(10**6):
    tmp = f(a[i])
    if tmp in a:
        print(i+2)
        exit()
    a.append(f(a[i]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
s = int(input())
n_list = [s]
i = 0
while True:
    a_i = n_list[i]
    if a_i % 2 == 0:
        n_list.append(int(a_i/2))
    else:
        n_list.append(int(a_i*3+1))
    i += 1
    if i == len(set(n_list)):
        print(i+1)
        break

Submission status: Accepted

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

Submission status: Accepted

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


s = int(input())

a = []

for i in range(1, 1000000):
    if i == 1:
        a.append(s)
    else:
        ai = f(a[-1])
        if ai in a:
            print(i)
            break
        else:
            a.append(ai)

Submission status: Accepted

Solution code:
a = []
s = int(input())
a.append(s)
i = 1

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

Submission status: Accepted

Solution code:
s = int(input())
a = []
a.append(s)
b = float('inf')

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

print(ans+2)

Submission status: Accepted

Solution code:
s = int(input())
ans = []
i=1
ans.append(s)
while True:
    i += 1
    if s % 2 == 0:
        s = s / 2
        if s in ans:
            print(i)
            exit()
        else:
            ans.append(s)
    else:
        s = s * 3 + 1
        if s in ans:
            print(i)
            exit()
        else:
            ans.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

a = [0, s]

for i in range(2, 1000001):
  new_a = f(a[i - 1])
  if new_a in a:
    print(i)
    break
  a.append(new_a)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
s = int(input())

def f(x):
    if x % 2 == 0:
        return x/2
    else:
        return 3*x + 1
d = dict()
d[s] = True
i = 2
while f(s) not in d:
    i += 1
    s = f(s)
    d[s] = True
print(i)

Submission status: Accepted

Solution code:
s = int(input())
ct = 1
if s <= 2:
    print("4")
    exit()
else:
    while(s > 1):
        if s % 2 == 0:
            s //= 2
        else:
            s = 3*s + 1
        ct += 1
    print(ct+1)

Submission status: Accepted

Solution code:
now = int(input())
ans = 0
if now == 1:
    ans = 4
elif now == 2:
    ans = 4
else:
    for i in range(1000000):
        if now == 4:
            ans = i + 4
            break
        if now % 2 == 0:
            now = now // 2
        else:
            now = 3 * now + 1
print(ans)

Submission status: Accepted

Solution code:
s = int(input())

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

a = [s]
for i in range(1000000):
    a_new = f(a[i])
    if a_new in a:
        print(i+2)
        exit(0)
    a.append(a_new)

Submission status: Accepted

Solution code:
s = int(input())
#h = [int(i) for i in input().split()]

a = s
ss = []

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

print(i+1)

Submission status: Accepted

Solution code:
s=int(input())


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

m=1
L=[s]
t=s
while True:
  m+=1
  t=func(t)
  if t in L:
    print(m)
    break
  else:
    L.append(t)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    s = int(input())
    dic = {s:0}
    count = 2
    while True:
        if s%2 == 0:
            s = int(s/2)
        else:
            s = 3*s+1
        try:
            a=dic[s]
            print(count)
            exit()
        except KeyError:
            dic[s] = 0
            count+=1

Submission status: Accepted

Solution code:
iS = int(input())

def fF(n):
    if n % 2 :
        return 3*n + 1
    else:
        return n//2
dS={iS}
for i in range(2,1000001):
    iN = fF(iS)
    if iN in dS:
        print(i)
        exit()
    dS.add(iN)
    iS = iN

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

flag = 0
i = 2
a = [n]

while flag==0:


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

    i += 1

print(i-1)

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

d = defaultdict(int)
s = int(input())
d[s] = 1
index = 1
while(1):
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
    index += 1
    if d[s] == 1:
        break
    d[s] = 1
print(index)

Submission status: Accepted

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

s = int(input())
m = 1
flag = False
a = []
#a_1
a.append(s)
while(1):
    a.append(f(a[-1]))
    for i in range(len(a)-1):
        if(a[m]==a[i]):
            flag = True
            break
    m = m+1
    if(flag):
        break
print(m)

Submission status: Accepted

Solution code:
a=int(input())
if a==1:
    print(4)
elif a==2:
    print(4)
elif a==4:
    print(4)
else:
    for i in range(1000000):
        if a%2==0:
            a=a//2
        else:
            a=3*a+1
        if a==4:
            print(i+5)
            break

Submission status: Accepted

Solution code:
s = int(input())
check = {};c = s;count = 1
check['{}'.format(c)] = True
while True:
    count += 1
    if c % 2== 0:c = c//2 
    else:c = 3*c + 1
    try:
        if check['{}'.format(c)] == True:
            break
    except:pass
    check[str(c)] = True
print(count)

Submission status: Accepted

Solution code:
s = int(input())


nums = set([s])
n = 2
prev = s
while True:
    ai = None
    if prev % 2 == 0:
        ai = int(prev / 2)
    else:
        ai = 3 * prev + 1
    if ai in nums:
        break
    else:
        nums.add(ai)
        prev = ai
        n += 1

print(n)

Submission status: Accepted

Solution code:
s=int(input())
if s==1:
  print(4)
elif s==2:
  print(4)
else:
  m=1
  while (s>1):
    if s%2==0:
      s=s//2
    else:
      s=3*s+1
    m+=1
  print(m+1)

Submission status: Accepted

Solution code:
def main():
    s = int(input())
    logs = {s: 1}
    for m in range(2, 1000000):
        if s % 2 == 0:
            s //= 2
        else:
            s = 3 * s + 1
        if s in logs:
            print(m)
            exit()
        logs[s] = m


main()

Submission status: Accepted

Solution code:
s = int(input())

test = [s]

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

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  B = []
  B.append(N)
  i = 1
  while True:
    if B[i - 1] % 2 == 0:
      B.append(B[i - 1] / 2)
    else:
      B.append(B[i - 1] * 3 + 1)
    i += 1
    A = sorted(B)
    for j in range(len(A) - 1):
      if A[j] == A[j + 1]:
        print(i)
        return
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(10**5):
    if s % 2 == 0:
        s //= 2
        ans.append(s)
    else:
        s = 3*s + 1
        ans.append(s)

check = []

for i in range(len(ans)):
    if ans[i] not in check:
        check.append(ans[i])
    else:
        print(i+1)
        break

Submission status: Accepted

Solution code:
S = int(input())

i = 2
a_list = [S]
if S % 2 == 0:
	a = S/2
else:
	a = 3*S + 1

while(i>0):
	if a in a_list:
		print(i)
		break
	else:
		a_list.append(a)
		if a % 2 == 0:
			a = a/2
		else:
			a = 3*a + 1
	i += 1
	if i==1000:
		i=0
		break

Submission status: Accepted

Solution code:
s = int(input())

def func(n):
  if n%2 == 0:
    return int(n/2)
  else:
    return int(3*n+1)
  
a = []
a.append(s)
i = 0
while(True):
  a.append(func(a[i]))
  i += 1
  try:
    if a[i] in a[:i]:
      print(i+1)
      break
  except:
    continue

Submission status: Accepted

Solution code:
s = int(input())

array = []
num = s
counter = 1

while num not in array:
    array.append(num)
    counter += 1
    if num % 2 == 0:
        num //= 2
    else:
        num = num * 3 + 1

print(counter)

Submission status: Accepted

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

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]
i = 0
while True:
    g = f(l[i])
    if g in l:
        print(i+2)
        break
    l.append(g)
    i += 1

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 20 20:50:54 2019

@author: Yamazaki Kenichi
"""

s = int(input())

a = [s]

ans = -1
counta = 1
while ans ==-1:
    if a[-1]%2==0:
        a.append(a[-1]//2)
    else:
        a.append(a[-1]*3+1)
    counta +=1
    ans = counta if a.count(a[-1])>=2 else ans
       
print(ans)

Submission status: Accepted

Solution code:
s = int(input())
existed = set()
cur_s = s
i = 1

while cur_s not in existed:
    existed.add(cur_s)
    if cur_s % 2 == 0:
        cur_s //= 2
    else:
        cur_s = 3 * cur_s + 1
    i += 1
print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
def func(n):
    if n%2==0:
        return n/2
    else:
        return 3*n+1
lis=[]
lis.append(s)
flag=0
count =0
ans=0
while flag==0:
    if func(lis[count]) in lis:
        ans=count+2
        flag=1
    else:
        lis.append(func(lis[count]))
        count=count+1
        
print(ans)

Submission status: Accepted

Solution code:
s=int(input())
x=s
l=[s]
for i in range(2,1000001):
  if x%2==0:
    x=x//2
  else:
    x=3*x+1
  if l.count(x)>0:
    print(i)
    exit()
  l.append(x)