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:
import sys
s = int(input())
flg=0
A = []
A.append(s)

index = 0
if s==4 or s==2 or s==1:
    print(index+4)
    sys.exit()
while flg!=1:
    if A[index]%2==0:
        f = (A[index]//2)
    else:
        f = 3*A[index]+1

    A.append(f)
    index = index + 1

    if f==4 or f==2 or f==1:
        flg=1
        break

#1,4,2,1,4

print(index+4)

Submission status: Accepted

Solution code:
s = int(input())
a = [s]
flg = False


def even(n):
    return n / 2


def odd(n):
    return 3 * n + 1


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

for i in range(len(a)):
    for j in range(i + 1, len(a)):
        if a[i] == a[j]:
            print(j + 1)
            flg = True
            break
    if flg == True:
        break

Submission status: Accepted

Solution code:
N = int(input())

i = 1
f = lambda x : (x//2) if x%2 == 0 else x*3+1
l = [N]
val = N

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

Submission status: Accepted

Solution code:
s = int(input())

A = [s]

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

Submission status: Accepted

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


s = int(input())
li = [0 for i in range(10**7)]
li[s] = 1

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

Submission status: Accepted

Solution code:
n=int(input())
a=[]
a.append(n)
i=0
flg=0
while True:
  i+=1
  if n%2==0:
    n=n//2
  else:
    n=3*n+1
  a.append(n)
  for j in range(len(a)):
    if i!=j and a[j]==n:
      print(i+1)
      flg=1
      break
  if flg==1:
    break

Submission status: Accepted

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

for i in range(1,1000001):

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

    if lst.count(lst[i])==2:
        break

print(i+1)

Submission status: Accepted

Solution code:
s = int(input())
cnt = {s}

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

Submission status: Accepted

Solution code:
list = []
list.append(int(input()))

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

i = 0
while True:
    next = f(list[i])
    if list.count(next) == 1:
        print(i + 2)
        break
    else:
        list.append(next)
        i+=1

Submission status: Accepted

Solution code:
A = []

s = int(input())
A.append(s)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
S = int(input())
li = [S]
count = 0
while True:
    count += 1
    if S%2 == 0:
        S //=2
    else:
        S = 3*S + 1

    if S in li:
        print(count+1)
        break
    else:
        li.append(S)

Submission status: Accepted

Solution code:
n = int(input())

l = []
l.append(n)

ans = 2
while True :

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

    ans += 1

print(ans)

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

if s == 1 or s == 2:
    print(4)
    exit()
ans = 2
while s > 1:
    s = f(s)
    ans += 1

print(ans)

Submission status: Accepted

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

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

while s not in a:
    a.append(s)
    s = f(s)
    i += 1
else:
    ans = i

print(ans)

Submission status: Accepted

Solution code:
def solve():
    s = int(input())
    
    ans, an = 1, s
    while 1:
        if an == 4 or an == 2 or an == 1:
            ans += 3
            break
        if an % 2 == 0:
            an //= 2
        else:
            an = 3 * an + 1
        ans += 1
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

s = [int(input())]
#print(s)

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

print(len(s))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

ans = [s]

for i in range(1000001):
    if ans[i] %2 == 0:
        ans.append(int((ans[i])/2))
    elif ans[i] %2 != 0:
        ans.append(int(3*(ans[i])) +1)
    
    if ans.count(ans[i]) == 2:
        print(i+1)
        break

Submission status: Accepted

Solution code:
list_a = [int(input())]
while list_a[-1] < 1000001:
  if list_a[-1] % 2 == 0:
    temp = int(list_a[-1] / 2)
  else:
    temp = 3 * list_a[-1] + 1
  if temp in list_a:
    print(len(list_a) + 1)
    exit()
  else:
    list_a.append(temp)

Submission status: Accepted

Solution code:
s=int(input())

l=[]
ans=1
a=s
while a not in [4,2,1]:
    if a % 2 == 0:
        a=a//2
    else:
        a=3*a+1
    ans+=1
    l.append(a)

print(ans+3)

Submission status: Accepted

Solution code:
s = int(input())

values = set()

values.add(s)
ans = 1
while True:
    if s % 2 == 0:
        s = s //2
    else:
        s = 3*s + 1
    ans += 1

    if s in values:
        break
    else:
        values.add(s)

print(ans)

Submission status: Accepted

Solution code:
s = int(input())

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

    ans += 1

    if s in sequence:
        break

    sequence.append(s)

print(ans)

Submission status: Accepted

Solution code:
s = int(input())
alist = [s]
aset=set()
for i in range(1000000):
  n = alist[-1]
  if n in aset:
    print(len(alist))
    break
  aset.add(n)
  if n%2 ==0:
    x = n//2
  else:
    x = 3*n+1
  alist.append(x)

Submission status: Accepted

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

Submission status: Accepted

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

ans.add(s)
j = 1
while 1:
        if j  > 1000000:
                break
        if s % 2 == 0:
                s = s // 2
        else:
                s = 3 * s + 1
        j += 1
        for i in ans:
                if s == i:
                        print(j)
                        exit()
        ans.add(s)

Submission status: Accepted

Solution code:
s = int(input())
n = s

ans = [0] * 1000
ans[0] = s

j = 1
while 1:
        if j  > 1000000:
                break
        if ans[j-1] % 2 == 0:
                ans[j] = ans[j-1] // 2
        else:
                ans[j] = 3 * ans[j-1] + 1
        for i in range(len(ans)):
                if i == j:
                        break
                if ans[i] == ans[j]:
                        print(j+1)
                        exit()
        j += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
h=int(input())
def feb(s):
    i=0
    A=[0]*2000
    A[0]=s
    while(1):
        if A[i]%2==0:
            
            A[i+1]=(A[i]//2)
        elif A[i]%2==1:
            A[i+1]= 3*A[i]+1
        for j in range(i):
            if A[j]==A[i]:
               return i+1
        i+=1
print(feb(h))

Submission status: Accepted

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

count = 4
while (s != 4):
    s = f(s)
    count += 1
print(count)

Submission status: Accepted

Solution code:
s = int(input())

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

v = [s]
for i in range(2, 1000001):
    v.append(collatz(v[-1]))
    d = set(v)
    if len(v) != len(d):
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

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

count=0
exist=[s]
while True:
	count+=1
	#print(s,count,exist)
	tmp = f(s)
	if tmp in exist:
		print(count+1)
		sys.exit(0)
	
	exist.append(tmp)
	s=tmp

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]
m=0
before=s
while True:
  new=f(before)
  m+=1
  if new in l:
    break
  l.append(new)
  before=new

print(m+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
s = int(input())
L = set()
L.add(s)
n = 1
while True:
    n += 1
    if s % 2 == 0:
        s //= 2
        if s in L:
            print(n)
            sys.exit()
        L.add(s)
    else:
        s = 3 * s + 1
        if s in L:
            print(n)
            sys.exit()
        L.add(s)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
s = int(input())
L = [s]
n = 1
while True:
    n += 1
    if s % 2 == 0:
        s //= 2
        if s in L:
            print(n)
            sys.exit()
        L.append(s)
    else:
        s = 3 * s + 1
        if s in L:
            print(n)
            sys.exit()
        L.append(s)

Submission status: Accepted

Solution code:
s=int(input())
t=set()
count=1

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

Submission status: Accepted

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

print(ans + 3)

Submission status: Accepted

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

print(ans+3)

Submission status: Accepted

Solution code:
s = int(input())

visited = set()
visited.add(s)
m = 2
if s % 2 == 0:
    s = s / 2
else:
    s = 3 * s + 1

while s not in visited:
    visited.add(int(s))

    m += 1
    if s % 2 == 0:
        s = s / 2
    else:
        s = 3 * s + 1
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
i=int(input())
s={i}

n=1
while 1:
    pre_s=s
    if i%2==0:
        i=i//2
    else:
        i=3*i+1
    
    n+=1
    if {i}<=s:
        break
    s.add(i)
    
print(n)

Submission status: Accepted

Solution code:
s=int(input())
def f(a):
    if a%2:
        return 3*a+1
    else:
        return a//2
value=(s,)
a=s
for i in range(2,1000000):
    a=f(a)
    if a in value:
        print(i)
        break
    value += (a,)

Submission status: Accepted

Solution code:

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

s = int(input())
ai = []
ai.append(s)
for i in range(1000000):
    x = f(ai[i])
    if x in ai:
        print(i+2)
        break
    ai.append(x)

Submission status: Accepted

Solution code:
s=int(input())

l=[s]*(10**6)
for i in range(10**6):
    if l[i]%2==0:
        l[i+1]=l[i]//2
    else:
        l[i+1]=3*l[i]+1
    if l[i]==4:
        print(i+4)
        exit()
    if l[i]==1:
        print(i+4)
        exit()
    if l[i]==2:
        print(i+4)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

S = []
ans = 1

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
a = s
i = 1
s_ = set()
s_.add(a)
while True:
  i += 1
  if a%2 == 0:
    a = a//2
  else:
    a = 3*a+1
  if a in s_:
    print(i)
    exit()
  else:
    s_.add(a)

Submission status: Accepted

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


s = int(input())

a = [0] * 1000000
a[0] = s
for i in range(1, 1000000):
    a[i] = f(a[i - 1])

t = set()
for i in range(1000000):
    if a[i] in t:
        print(i + 1)
        break
    t.add(a[i])

Submission status: Accepted

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

# 繰り返してゆく
for n in range(2,1000001):
    if A[-1]%2==0: # 偶数のとき
        f=A[-1]//2
    else: # 奇数のとき
        f=3*A[-1]+1

    if f in A: # 重複したら出力して終了
        print(n)
        break

    A.append(f) # 追加

Submission status: Accepted

Solution code:
s = int(input())

l = []
l.append(s)

ans = 0

i = 1

while ans == 0:
	if l[i-1]%2 == 0:
		l.append(int(l[i-1]/2))
	else:
		l.append(int(3*l[i-1]+1))
	
	if len(l)!=len(set(l)):
		ans = i
	else:
		i = i + 1

print(i+1)

Submission status: Accepted

Solution code:
s = int(input())

def find_the_same(itter, number, answer_list):
    if itter == 1:
        answer_list.append(number)
    if number%2 == 0:
        answer = number // 2
    else:
        answer = (number * 3) + 1
    if answer in answer_list:
        itter += 1
        return itter
    else:
        itter += 1
        answer_list.append(answer)
        return find_the_same(itter, answer, answer_list)
answer_list = []
print(find_the_same(1, s, answer_list))

Submission status: Accepted

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

n = int(input())
past_values = []
iter = 1
while n not in past_values:
    past_values.append(n)
    n = f(n)
    iter += 1

print(iter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

ls_a = [s]

for i in range(10**5):
    if ls_a[i] % 2 == 0:
        ls_a.append(ls_a[i] / 2)
    elif ls_a[i] % 2 == 1:
        ls_a.append(3 * ls_a[i] + 1)

    if ls_a[i+1] in ls_a[:i]:
        print(i+2)
        break

Submission status: Accepted

Solution code:
s = int(input())

ls_a = [0]
ls_a[0] = s

for i in range(10**5):
    if ls_a[i] % 2 == 0:
        ls_a.append(ls_a[i] / 2)
    elif ls_a[i] % 2 == 1:
        ls_a.append(3 * ls_a[i] + 1)

    if ls_a[i+1] in ls_a[:i]:
        print(i+2)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
tmp = [s]
for i in range(2, 10**6+1):

    if tmp[-1] % 2 == 0:
        j = tmp[-1] / 2
    else:
        j = 3 * tmp[-1] + 1

    if j in tmp:
        print(i)
        exit()
    tmp.append(j)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def has_duplicates(seq):
    return len(seq) != len(set(seq))

while True:
    if s%2==0:
        s=s/2
    else :
        s=3*s+1
    a.append(s)
    if has_duplicates(a):
        break;

print(len(a))

Submission status: Accepted

Solution code:
s = int(input())

list_aaa = []

for i in range(1,100000+1):
    if i ==1:
        list_aaa.append(s)
    elif s%2 ==0:
        s= s//2
        list_aaa.append(s)
    elif s%2 ==1:
        s= (3*s)+1
        list_aaa.append(s)
#print(list_aaa)

for i in list_aaa:
    index_num = [n for n, v in enumerate(list_aaa) if v == i]
    if len(index_num) >=2:
        print(index_num[1]+1)
        break

Submission status: Accepted

Solution code:
s = int(input())
seq = [s]
next_a = 0

for i in range(1, 100000000):
    if seq[i-1] % 2 == 0:
        next_a = int(seq[i-1] / 2)
    else:
        next_a = int(3 * seq[i-1] + 1)

    seq.append(next_a)
    if seq[i] in seq[:-1]:
        print(i+1)
        break

Submission status: Accepted

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

s = int(input())
nextn = d(s)
nums = set()
nums.add(nextn)
res = 3

while(1):
    nextn = d(nextn)
    if(nextn in nums):break
    else: 
        res += 1
        nums.add(nextn)
if(s in [1, 2, 4]): print(4)
else: print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

if s == 1 or s == 2 or s == 4:
  print(4)
else:
  count = 1
  while s != 4:
    s = calc(s)
    count += 1
  print(count + 3)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = int(input())
dp = [0] * (10 ** 6 + 1)
dp[0] = s
x = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

    m = 1000000
    array = []
    array.append(s)
    count = 0
    for i in range(1,m):
        if array[i-1] == 1:
            count += 1
        if count == 2:
            break
        if array[i-1]%2 == 0:
            array.append(array[i-1]/2)
        else:
            array.append(array[i-1]*3+1)
    ans = m
    for i in range(len(array)):
        for j in range(i+1, len(array)):
            if array[i] == array [j]:
                ans = min(ans, max(i+1,j+1))
        if m == 3:
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = int(input())

a = s
l = set()
l.add(int(a))
cnt = 1
for i in range(1, 1000000):
  if a%2 == 0:
    a = a//2
  else:
    a = 3*a + 1
  cnt += 1
  if a in l:
    break
  l.add(int(a))
  i += 1

print(int(cnt))

Submission status: Accepted

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

  i += 1
 
print(int(cnt))

Submission status: Accepted

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

print(int(nun))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

a = [s]
for i in range(10000):
  ai = fun(a[i])
  a.append(ai)

b = 0
for i in range(10000):
  if b ==1:
    break
  for j in range(i + 1,9999):
    if a[j] == a[i]:
      b += 1
      print(j + 1)
      break

Submission status: Accepted

Solution code:
s=int(input())
li=[]
cnt=1

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

Submission status: Accepted

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

Submission status: Accepted

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

print(i+1)

Submission status: Accepted

Solution code:
s = int(input())

def even(n):
    return n // 2

def odd(n):
    return 3 * n + 1

l = [0 for _ in range(100000+10)]
a = s
ans = 1
l[a] += 1
while True:
    if a % 2 == 0:
        a = even(a)
    else:
        a = odd(a)
    l[a] += 1
    ans += 1
    if l[a] >= 2:
        break
print(ans)

Submission status: Accepted

Solution code:
# ABC 116: B – Collatz Problem
s = int(input())
the_sequence = []
m = 1

while s not in the_sequence:
    the_sequence.append(s)

    if s % 2 == 0:
        s //= 2
    else:
        s = 3 * s + 1
    
    m += 1
    
print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
flag=False
d=[s]
count=1
while flag!=True:
  if s%2:
    s=3*s+1
    if s in d:
      flag=True
    d.append(s)
    count+=1
  else:
    s/=2
    if s in d:
      flag=True
    d.append(s)
    count+=1
print(count)

Submission status: Accepted

Solution code:
import os, sys, re, math

s = int(input())
nums = [-1,s]
M = 1000001

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

for i in range(2,M):
    tmp = doit(nums[i-1])
    if tmp in nums:
        break
    else:
        nums.append(tmp)

print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os, sys, re, math

s = int(input())

a = s
ans = [a]

for n in range(2, 1000001):
    a = a // 2 if a % 2 == 0 else 3 * a + 1
    if a in ans:
        print (n)
        break
    ans.append(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
cs = {0: n}  # old, current
used = {n: True}
for i in range(1, 10000000):
  cs[i] = cs[i-1] // 2 if cs[i-1] % 2 == 0 else cs[i-1]*3 +1
  if cs[i] in used:
      break
  used[cs[i]] = True
print(i + 1)

Submission status: Accepted

Solution code:
s = int(input())
e = set()
m = 1
while s not in e:
    e.add(s)
    s = s // 2 if s % 2 == 0 else s * 3 + 1
    m += 1
print(m)

Submission status: Accepted

Solution code:
a = [int(input())]
seen = {a[0]}
f = lambda n: 3 * n + 1 if n & 1 else n // 2
for i in range(2, 1000001):
    next = f(a[-1])
    if next in seen:
        print(i)
        exit()
    a.append(next)
    seen.add(next)
raise Exception('Something went wrong...')

Submission status: Accepted

Solution code:
import sys

s = int(input())

ans = 1
al = [s]
while True:
    ans += 1
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
    if s not in al:
        al.append(s)
    else:
        print(ans)
        sys.exit()

Submission status: Accepted

Solution code:
n=int(input())
cnt=1
nl=[n]
for i in range(1000000):
    if n%2==0:
        n=int(n/2)
        cnt+=1
    elif n%2==1:
        n=3*n+1
        cnt+=1
    if n in nl:
        print(cnt)
        exit()
    nl.append(n)

Submission status: Accepted

Solution code:
s = int(input())
lis = set()
lis.add(s)
jud = True
cnt = 1
while jud:
    if s%2:
        s = 3*s+1
    else:
        s = s//2
    if s in lis:
        jud = False
    lis.add(s)
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# 2019-11-12 01:01:32(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

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


def main():
    s = int(sys.stdin.readline().rstrip())

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(1000000):
  if i == 0:
    l.append(s)
  else:
    s = calc(l[i-1])
    if s in l:
      break
    else:
      l.append(s)
      
print(len(l)+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

dict = defaultdict(int)
an = s
dict[an] += 1

for i in range(2, 1000000):
    if an % 2 == 0:
        an /= 2
    else:
        an = 3*an + 1

    dict[an] += 1
    if dict[an] == 2:
        print(i)
        exit()

Submission status: Accepted

Solution code:
a = int(input())
ai = a
a_set = set()
flag_1 = 0
flag_2 = 1
while(flag_1 == 0):
  if ai in a_set:
    flag_1 += 1
    print(flag_2)
  else:
    a_set.add(ai)
    flag_2 += 1 
    if ai % 2 == 0:
      ai //= 2
    else:
      ai = 3 * ai + 1

Submission status: Accepted

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

Submission status: Accepted

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