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:
s = int(input())
A = [s]
while True:
    if s % 2 == 0:
        a = s//2
    else:
        a = 3*s + 1

    if a in A:
        A.append(a)
        break
    else:
        A.append(a)
        s = a
        continue
print(len(A))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(len(a) + 1)

Submission status: Accepted

Solution code:
s = int(input())
a = {s}
pre_a = s
i = 2
while True:
    if pre_a&1:
        pre_a = 3*pre_a + 1
        if pre_a in a:
            print(i)
            break
        a.add(pre_a)
    else:
        pre_a = pre_a // 2
        if pre_a in a:
            print(i)
            break
        a.add(pre_a)
    i += 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


s = int(input())
array = []
cnt = 1
array.append(s)
while True:
    s = cal(s)
    array.append(s)
    if array[cnt] in array[:cnt]:
        print(cnt +1)
        break
    cnt += 1

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())
s_ = s
counter = 0

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

Submission status: Accepted

Solution code:
s = int(input())
s_ = s
x = [s]
counter = 0
#while s != 1:

for _ in range(1000000):
  if s%2 ==0:
    s = s/2
    x.append(s)
  else:
      s = 3*s+1
      x.append(s)
#  counter +=1

if s_ == 4 or s_ == 2 or s_ == 1:
  print(4)
else:
  print(x.index(4)+4)
#print(x)

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

Solution code:
s=int(input())

list=[]
i=0
list.append(s)

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

Submission status: Accepted

Solution code:
a = int(input())
ans = {}
flag = 1
while True:
    if a in ans:
        print(flag)
        break
    else:
        ans[a] = 1
    if a % 2 == 0:
        a = a // 2
    else:
        a = 3 * a + 1
    flag += 1

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())

a = [10 ** 10]
i = 1
temp = 10 ** 10
while True:
    if i == 1:
        temp = s
    elif a[i - 1] % 2 == 0:
        temp = a[i - 1] // 2
    else:
        temp = 3 * a[i - 1] + 1

    if temp in a:
        print(i)
        exit()
    a.append(temp)
    i += 1

Submission status: Accepted

Solution code:
N = int(input())
Flag = 0
nList = []
nList.append(N)
i = 2
while Flag==0:
  Tmp = N % 2
  TmpN = N
  if Tmp == 0:
    TmpN /= 2
  else:
    TmpN = 3 * N + 1
  
  if TmpN in nList:
    Flag = 1
    break
  else:
    nList.append(TmpN)
    N = TmpN
    i += 1

print(i)

Submission status: Accepted

Solution code:
s = int(input())
hashtable = {s:1}
counter = 1
flag = True
while flag:
    if s%2 == 0:
        s /= 2
    else:
        s = 3*s + 1
    counter += 1
    
    if s in hashtable.keys():
        flag = False
    else:
        hashtable[s] = 1
    
print(counter)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,100000):
    if ans.count(ans[-1]) >= 2:
        print(len(ans))
        break
    else:
        if ans[i-1]%2 == 0:
            g = ans[i-1]/2
            ans.append(g)
        elif  ans[i-1]%2 != 0:
            g = 3*ans[i-1]+1
            ans.append(g)

Submission status: Accepted

Solution code:
import collections

s = int(input())
A = [s]
for i in range(1000000+1):
  A.append(A[i]//2 if A[i]%2==0 else 3*A[i]+1)
  c = collections.Counter(A)
  if c.most_common()[0][1] == 2:
    print(len(A))
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
ss = list()
ans = 1
while s not in ss: 
    ss.append(s)
    if s%2 == 0:
        s = s//2
    else:
        s = 3*s+1
    ans +=1
print(ans)

Submission status: Accepted

Solution code:
s = int(input())
ss = list()
ss += [s]
ans = 1
for i in range(1000000000):    
    if s%2 == 0:
        s = s//2
    else:
        s = 3*s+1
    ss += [s]
    ans +=1
    if s in ss[:-1]:
        print(ans)
        break

Submission status: Accepted

Solution code:
def solve():
    s = int(input())
    collatz = [s]
    now = s
    for _ in range(10 ** 6):
        a_i1 = 3 * now + 1 if now % 2 else now // 2
        now = a_i1
        if a_i1 in collatz:
            return len(collatz) + 1
        collatz.append(a_i1)


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = int(input())
i = 2
s_list = []
while True:
    s_list.append(s)
    if s % 2:
        s = 3*s + 1
    else:
        s /= 2
    if s in s_list:
        break
    i += 1

print(i)

Submission status: Accepted

Solution code:
s=int(input())

from collections import defaultdict
dic = defaultdict(int)

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

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=s*3+1
print(len(l)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
A = {s}
before = s
for i in range(2, 1000001):
    if before % 2:
        fn = 3 * before + 1
    else:
        fn = before // 2
    if fn in A:
        print(i)
        exit()
    else:
        A.add(fn)
        before = fn

Submission status: Accepted

Solution code:
import math
import copy

inputa = input().split()
# inputb = input().split()
# inputc = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# inputb = input().split()
# inputbList = [int(x) for x in inputb]

# x = int(inputb[0])
# y = int(inputb[1])

# inputList=[]
# for i in range(a):
#     inputNum = input().split()
#     inputNum = [int(x) for x in inputNum]
#     inputList.append(inputNum)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

numList = [-1, float(a)]

cnt = 1
flg = True
while cnt < 1000000 and flg == True:
    cnt += 1
    if numList[cnt-1] % 2 == 0:
        numList.append(float(numList[cnt -1] / 2))
    else:
        numList.append(float(3*numList[cnt-1] + 1))

    for i in range(1, cnt):
        if numList[i] == numList[cnt]:
            print(cnt)
            flg = False
            break

Submission status: Accepted

Solution code:
s = int(input())

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

print(i+3)

Submission status: Accepted

Solution code:
s=int(input())

dd={s:1}
ans=-1
m=1
while True:
  m+=1
  if s%2>0: s=3*s+1
  else: s=s//2
  #print(s," ",end="",sep="")
  ans=dd.get(s)
  if ans==None: dd[s]=m
  else: ans=m; break

#print()
print(ans)

Submission status: Accepted

Solution code:
s=int(input())

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

Submission status: Accepted

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

a.append(s)
i = 1

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

    if a.count(a[i]) > 1:
        print(i+1)
        break
    else:
        i += 1

Submission status: Accepted

Solution code:
s = int(input())

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

else:
  print ("not found")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
p = int(input())

num = [p]

count = 1

while num[-1] not in num[:-1]:
  count += 1
  
  if num[-1]%2 == 0:
  	num.append(num[-1]/2)
  else:
  	num.append(3*num[-1] + 1)
else:
  print(count)

Submission status: Accepted

Solution code:
N = int(input())

if N == 1:
	ans = 3
elif N == 2:
	ans = 3
else:
	ans = 1
	while N != 1:
		if N%2 == 0:
			N = N//2
			ans += 1
		else:
			N = 3*N+1
			ans += 1

print(ans+1)

Submission status: Accepted

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


s = int(input())
a = {s}
last = s
i = 2
while True:
    last = f(last)
    if last in a:
        print(i)
        break
    a.add(last)
    i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
def f(n):
  if n % 2 == 0:
    return n//2
  else:
    return 3*n+1
ans = []
for i in range(1,1000001):
  if i == 1:
    a = s
    ans.append(a)
  else:
    a = f(ans[-1])
    ans.append(a)
  if ans.count(ans[-1]) > 1:
    print(i)
    break

Submission status: Accepted

Solution code:
s = int(input())
s_list = []
if s != 1 or s != 2:
    while s != 1:
        if s % 2 == 0:
            s = s / 2
        else:
            s = 3 * s + 1
        s_list.append(s)
    print(max(len(s_list)+2, 4))
else:
    print(4)

Submission status: Accepted

Solution code:
s = int(input())

a = []
i = 0
a.append(s)
cnt = 1
while True:
    t = 0
    if a[i] % 2 == 0:
        t = a[i]//2
    else:
        t = 3*a[i]+1
    for j in range(len(a)):
        if a[j] == t:
            print(i+2)
            exit()
    a.append(t)
    i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())

nums=[s]

i=1

while True:
    if nums[i-1]%2==0:
        nums.append(int(nums[i-1]/2))

    else:
        nums.append(int(nums[i-1]*3+1))

    if nums.count(nums[i])==2:
        #print(nums)
        print(i+1)
        exit()

    i+=1

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

s = int(input())
ptn = []
n = 1
while True:
    ptn.append(s)

    if s % 2 == 0:
        fn = s // 2
    else:
        fn = s * 3 + 1

    if fn in ptn:
        print(n+1)
        exit()

    ptn.append(fn)
    n += 1
    s = fn

Submission status: Accepted

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

a = [0,int(input())]

for i in range(2,10**6):
    x = func(a[i-1])
    if x in a:
        print(i)
        break
    else:
        a.append(x)

Submission status: Accepted

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

a = [0]
for i in range(1,10**6):
    if i == 1:
        x = s
    else:
        x = func(a[i-1])
    if x in a:
        print(i)
        break
    else:
        a.append(x)

Submission status: Accepted

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

X = [s]
m = 1
next = s

while True:
  m += 1
  next = f(next)
  if next in X:
    break
  else:
    X.append(next)
    
print(m)

Submission status: Accepted

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

X = [s]
cont = 1
next = s

while cont < 1000:
  cont += 1
  next = f(next)
  if next in X:
    break
  else:
    X.append(next)
    
print(cont)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
se = set()

m = 1
while True:
    if s in se:
        ans = m
        break
    m +=1
    se.add(s)
    if s % 2 == 0:
        s = s//2
    else:
        s = s*3+1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys
import itertools
import queue
from fractions import gcd

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

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

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

if __name__ == "__main__":
    s = int(sys.stdin.readline())
    cnt = 0
    nums = set()
    while True:
        nums.add(s)
        cnt += 1
        s = f(s)
        if s in nums:
            #print(nums)
            print(cnt + 1)
            exit()

Submission status: Accepted

Solution code:
s = int(input())
array = []
array.append(s)
m = 1

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

while (f(s) in array) == False:
    array.append(f(s))
    s = f(s)
    m += 1

print(m+1)

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

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

mod = 1000000007

if __name__ == "__main__":
    s= int(sys.stdin.readline())
    c=1
    l=[]

    while True:
        if l.count(s)>0:
            print(c)
            exit()
        else:
            l.append(s)

        if s%2==0:
            s//=2
        else:
            s=3*s+1
        c+=1

Submission status: Accepted

Solution code:
import copy
s = int(input())
l =[s]
lold = copy.deepcopy(l)

for i in range(1000000):

    if l[-1]%2 == 0:
        l.append(l[-1]//2)
    else:
        l.append(3*l[-1] + 1)
    if l[-1] in lold:
        print(len(l))
        exit()
    lold = copy.deepcopy(l)

Submission status: Accepted

Solution code:
s = int(input())
a = s
b = set()
b.add(a)
m = 1
while m <= 10**6:
    if a%2 == 1:
        if 3*a+1 in b:
            m += 1
            print(m)
            break
        else:
            b.add(3*a+1)
            a = 3*a+1
            m += 1
    else:
        if a//2 in b:
            m += 1
            print(m)
            break
        else:
            b.add(a//2)
            a = a//2
            m += 1

Submission status: Accepted

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

while True:

    if a[i] % 2 == 0:
        a.append(a[i]/2)
    else:
        a.append(a[i]*3+1)
    if a[i] == 4:
        print(i+4)
        exit()
    elif a[i] == 2 or a[i] == 1:
        print(i+4)
        exit()

    i += 1

print(a)

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

Submission status: Accepted

Solution code:
s = int(input())
ansli = [s]
flg = True
cnt = 2
def f(n):
    if n%2 == 0:
        return int(n/2)
    else:
        return (3*n)+1
cnt = 2
cur = s
while flg:
    cur = f(cur)
    if cur in ansli:
        print(cnt)
        flg = False
    else:
        ansli.append(cur)
        cnt += 1

Submission status: Accepted

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

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

Submission status: Accepted

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

while 1:
    if s%2==0:
        s=s/2
        a.append(s)
    else:
        s=3*s+1
        a.append(s)
    if len(a)!=len(set(a)):
        print(len(a))
        exit()

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:
s=int(input())

def even(n):
    return n/2

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

flag=True
num=[s]

i=1
while flag:
    if s%2 ==0:
        s=even(s)
        if s in num:
            print(i+1)
            flag=False
        else:
            num.append(s)
            i+=1
    else:
        s=odd(s)
        if s in num:
            print(i+1)
            flag=False
        else:
            num.append(s)
            i+=1

Submission status: Accepted

Solution code:
b = int(input())

a = [b]
prev = b
idx = 1
while True:
    fa = prev // 2 if prev % 2 == 0 else 3 * prev +1 
    if fa in a:
        print(len(a) + 1)
        break
    a.append(fa)
    prev = fa

Submission status: Accepted

Solution code:
s=int(input())
l=[]
def func(a):
    if a%2==0:
        return a/2
    else:
        return 3*a+1

while (s not in l):
    l.append(s)
    s=func(s)

print(len(l)+1)

Submission status: Accepted

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

    if li[i] in li[:i]:
        break
    else:
        i += 1
print(len(li))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(t+2)

Submission status: Accepted

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


ref = [int(input())]
cnt = 1

while True:
    cnt += 1
    dup = f(ref[-1])
    if dup in ref:
        print(cnt)
        exit(0)
    else:
        ref.append(dup)

Submission status: Accepted

Solution code:
s = int(input())
a = [s]
flag = True
while flag:
    if a[-1] % 2 == 0:
        a.append(a[-1]//2)
    else:
        a.append(3*a[-1]+1)
    for i in range(len(a)-1):
        if a[i] == a[-1]:
            m = len(a)
            flag = False
            break
print(m)

Submission status: Accepted

Solution code:
ans = [False] * 200000

def collatz(n, i):
    ans[n] = True
    next_val = n//2 if n % 2 == 0 else 3*n+1
    if ans[next_val]: return i+1
    return collatz(next_val, i+1)

def solve():
    s = int(input())
    print(collatz(s, 1))
    
solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def gen(n):
    for _ in range(1000):

        if n%2==0:
            g = int(n/2)
            yield g
        else:
            g = int(n*3+1)
            yield g
        n = g


def main():
    N = int(input())
    a=gen(N)
    post = [N]
    for i,generated in enumerate(a):
        if generated in post:
            print(i+2)
            exit()
        else:
            post.append(generated)

        
    
if __name__== "__main__":
    main()

Submission status: Accepted

Solution code:
s = int(input())

List = []
c = s
while c <= 10**7:
    if c in List:
        ans = len(List)+1
        break
    else:
        List.append(c)
        if c % 2 == 0:
            c = c*0.5
        else:
            c = 3*c+1

print(ans)

Submission status: Accepted

Solution code:
#ABC 116, B - collatz problem
import itertools
def f(x):
    if x % 2 == 0:
        return x / 2
    else:
        return 3*x + 1

s = int(input())
A = []
A.append(s)
for i in itertools.count(1):
    A.append(f(A[i-1]))
    if A[i] in A[:-1]:
        print(i+1)
        break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())
m = [0]*10**7
m[s]=1
a = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

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]
while True:
    x = f(a[-1])
    if x in a:
        print(len(a) + 1)
        exit()
    a.append(x)

Submission status: Accepted

Solution code:

a=int(input())

def gen(a):
    while True:
        yield a
        a = a // 2 if a % 2 == 0 else a * 3 + 1

seen = set()

for ix, x in enumerate(gen(a)):
    if x in seen:
        print(ix+1)
        break
    seen.add(x)

Submission status: Accepted

Solution code:
s = int(input())

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

check = 0
check_list = []
i = 0

while check == 0:
    if i == 0:
        check_list.append(s)
    else:
        if f(check_list[i-1]) not in check_list:
            check_list.append(f(check_list[i-1]))
        else:
            print(i+1)
            check = 1
            break
    i += 1

Submission status: Accepted

Solution code:
s = int(input())

ai = s
a = [ai]

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

print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(map(int,input().split()))

for i in range(1,10000):
  if s[i-1]%2==0:
    s.append(int(s[i-1]/2))
  elif s[i-1]%2==1:
    s.append(3*s[i-1]+1)
  if s[i] in s[:i]:
    break
print(i+1)

Submission status: Accepted

Solution code:
# ABC 116 B

s = int(input())

a = [0]

a.append(s)

while True:
    if a[-1] % 2 == 0:
        x = int(a[-1] / 2)
    else:
        x = int(3 * a[-1] + 1)

    if x in a:
        print(len(a))
        break
    else:
        a.append(x)

Submission status: Accepted

Solution code:
def collatz(n):
    if n % 2 == 0:
        return int(n / 2)
    else:
        return 3 * n + 1
    
s = int(input())
a = [s]
pre= s
m = 2

while True:
    next = collatz(pre)
    if next not in a:
        m += 1
        a.append(next)
        pre = next
    else:
        break

print(m)

Submission status: Accepted

Solution code:
n = int(input())

def even(n):
    return n/2
def odd(n):
    return 3*n+1
a = [n]
i =0
while True:
    if n%2 ==0:
        n = even(n)
        a.append(n)
    else:
        n = odd(n)
        a.append(n)
    if a.count(n) == 2:
        break

print(len(a))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def f(x):
  if x%2:
    return 3*x+1
  else:
    return x//2
s = int(input())
result = [s]
count = 1
while True:
  can = f(result[-1])
  if can in result:
    print(count+1)
    break
  else:
    result.append(can)
    count += 1

Submission status: Accepted

Solution code:
s=int(input())

x=[]
x.append(s)

chk=0
cnt=0

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