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

input = sys.stdin.readline

def calc(n):
    if n%2 == 0:
        return n//2
    else:
        return n*3 + 1
        
def main():
    ans = 1
    s = int(input())
    l = [s]
    while True:
        temp = calc(l[ans-1])
        ans += 1
        if temp in l:
            break
        else:
            l.append(temp)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
number = int(input())
count = 2
if number in [1,2,4]:
    count = 4
else:
    while number != 1:
        count += 1
        number = number/2 if number%2==0 else number*3+1
print(count)

Submission status: Accepted

Solution code:
number = int(input())
count = 2

if number in [1,2,4]:
    count = 4
else:
    while number != 1:
        count += 1
        if number % 2 == 0:
            number = number / 2
        else:
            number = number * 3 + 1

print(count)

Submission status: Accepted

Solution code:
from itertools import product

def read():
    s = int(input())
    return s,


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


def solve(s):
    a = s
    count = [0] * 5
    i = 1
    while True:
        if a in [1, 2, 4]:
            count[a] += 1
            if count[a] == 2:
                break
        a = f(a)
        i += 1
    return i

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
f_num = []
tmp = s
m = 1

while tmp not in f_num:
    f_num.append(tmp)
    if tmp % 2 == 0:
        tmp = tmp // 2
    else:
        tmp = 3 * tmp + 1
    m += 1

print(m)

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
al = [a]
for i in range(2,1000001):
    na = f(a)
    if na in al:
        print(i)
        break
    a = na
    al.append(na)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s =int(input())
a = []
a.append(s)
memory = []
memory.append(s)
while True:
    n = a.pop()
    if n % 2 == 0:
        a.append(n//2)
        if n//2 in memory:
            memory.append(n//2)
            break
        else:
            memory.append((n//2))

    else:
        a.append(3*n+1)

        if 3*n+1 in memory:
            memory.append(3*n+1)
            break
        else:
            memory.append(3*n+1)

print(len(memory))

Submission status: Accepted

Solution code:
s = int(input())

# 今までに出てきた数字を格納
set_num = set()

set_num.add(s)
ans = 1

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())


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


num_list = [s]
i = 0
while True:
    num = f(num_list[i])
    if num in num_list:
        print(i + 2)
        exit()
    num_list.append(num)
    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

i = 1
tmp = {s}
while True:
	res = f(s)
	if res not in tmp:
		tmp.add(res)
		s = res
	else:
		print(i+1)
		break
	i += 1

Submission status: Accepted

Solution code:
from sys import exit

def f(x):
	if x%2==0:
		return x//2
	else:
		return x*3+1
		
s=int(input())
A=[]
A.append(s)

for i in range(2,10**10):
	if f(s) in A:
		print(i)
		exit()
	else:
		s=f(s)
		A.append(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math
s =int(input())
a = s
count = 0
if a <= 2:
    print(4)
    quit()
if a == 3:
    print(9)
    quit()
while a >=4:
    if a % 2 == 0:
        a /= 2
    else:
        a = 3 * a + 1
    count += 1

print(count+3)

Submission status: Accepted

Solution code:
s = int(input())

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

i = 1
num_list = [s]
while True:
    num_list.append(func(num_list[i-1]))
    if num_list[i] in num_list[:i-1]:
        print(i+1)
        break
    i += 1

Submission status: Accepted

Solution code:
s = int(input())

t = set([s])
for i in range(1,10**6+1):
  if s%2==0:
    s//=2
  else:
    s=s*3+1
  if s in t:
    print(i+1)
    break
  else:
    t.add(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=[]
a.append(s)
i=1        
while True:
    x=f(a[i-1])
    if x in a:
        print(i+1)
        exit()
    else:
        a.append(x)
        i+=1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque
import collections
#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation



'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''

#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        #sqrt(n)+1以上は考えて約数はないので却下
        if n % k == 0:
            return False
            #割り切れたらFalse
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  # [1, 0, 3]

'''

def factorial(x, mod=10**9+7):
    # x!
    # 階乗
    # ex) factorial(5) = 120
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''


########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

def main():
    #c = collections.Counter(l)
    w=1
    j=0
    k=0
    s=int(input())
    if s==1 or s==2:
        print(4)
        sys.exit()
    ans=[]
    anss=[0]*100000
    ans.append(s)
    anss[s]=anss[s]+1
    for i in range(2,10000):
        if s%2==0:
            s=s/2

            anss[int(s)]=anss[int(s)]+1
            #ans.append(s)
            #c = collections.Counter(ans)
            #if c.most_common()[0][1]>=2:
            if anss[int(s)]>=2:
            #if c['4']>=2:
                print(i)
                sys.exit()
        else:
            s=3*s+1
            #ans.append(s)
            #c = collections.Counter(ans)
            anss[int(s)]=anss[int(s)]+1
            #if c.most_common()[0][1]>=2:
            if anss[int(s)]>=2:
            #if c['4']>=2:
                print(i)
                sys.exit()

    #r=int(input())
    #dp= [[0]*3 for i in range(5)]#列　行
    #dp用の0の入ったやつ
    #dp= [[0]*(w+1) for i in range(n+1)]#0からwまでのw+1回計算するから
    #print(dp)＃初期条件が入る分計算回数+1列分必要(この場合は判断すべきものの数)
    DP = np.zeros(w+1, dtype=int)#これでも一次元リストが作れる
    exdp=np.zeros((3,4)) # ３×４の２次元配列を生成。2次元ならこう
    #dtypeは指定しないとfloatになる
    #for i in range(n):#ちょっとした入力に便利
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        #これだとintとlistをつなぐことになって不適
    #    dp[i] += [a]
    #    dp[i] += [b]
        #これはうまくいく
        #やり方はいろいろあるということ
    #print(dp)


    "1行1つの整数を入力を取得し、整数と取得する"
    #nl=list(map(int, input().split(" ")))#数字の時
    #print(number_list)
    "12 21 332 とか入力する時に使う"
    "1行に複数の整数の入力を取得し、整数として扱う"
    #brray=[list(map(int, input().split(" ")))for i in range(N)
    #print(brray)


    #s=input()
    #a=[int(i) for i in s]#int取るとstrでも行ける
    #print(a)
    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]#内包表記に慣れろ
    #print(pin_l)

    ls = ["a", "b", "c", "d", "e"]


    #print(ls[2:5])
    #スライスでの取得

    #print(ls[:-3])
    #一番左端から右から3番目より左まで取得

    #print(ls[:4:2])
    #スライスで1個飛ばしで取得
    #ないときは左端スタート
    #始点のインデックス番号 : 終点のインデックス番号 : スキップする数+1
    #print(ls[::2])
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(s: int):

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

    d = set()
    ai = s
    i = 1
    while ai not in d:
        d.add(ai)
        ai = f(ai)
        i += 1

    print(i)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = int(next(tokens))  # type: int
    solve(s)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

    res = [int(input())]
    idx = 0
    while True:
        i = func(res[idx])
        if i not in res:
            res.append(i)
        else:
            print(len(res) + 1)
            break
        idx += 1


resolve()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

s = int(input())

reached = []
def F(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1

counter = 1
a = []
a.append(s)
while True:
    counter += 1
    tmp = F(a[-1])
    if tmp in a:
        ans = counter
        break
    a.append(tmp)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

temp_set = {n}
for i in range(2, 10 ** 6 + 1):
    if n % 2 == 0:
        n //= 2
    else:
        n = 3 * n + 1
    
    if n in temp_set:
        break
    
    temp_set.add(n)
print(i)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
S=int(input())
List=[S]

i=1
while 1==1:
    i+=1
    if S%2==0:
        S=S/2
    else:
        S=(S*3)+1
    List.append(S)
    
    if len(List) != len(set(List)):
        break
    #i+=1
    
print(i)

Submission status: Accepted

Solution code:
s = int(input())

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

cnt =0
n=0

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
s = int(input())

A = [s]
n = (s/2 if s%2==0 else 3*s+1)
ans = 1

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

print(ans+1)

Submission status: Accepted

Solution code:
s = int(input())

A = [s]
n = (s/2 if s%2==0 else 3*s+1)
ans = 1

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

print(ans+1)

Submission status: Accepted

Solution code:
s = int(input())

appear = {s:0,}
i = 0
while True:
    i += 1
    if s%2 == 0:
        s //= 2
    else:
        s = 3*s + 1
    if s in appear:
        break
    else:
        appear[s] = i

print(i+1)

Submission status: Accepted

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

a = int(input())
A = set()
ans = 1
while a not in A:
  A.add(a)
  ans += 1
  a = f(a)

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

fd = {s:1}
for i in range(2,10**10) :
  s = f(s)
  if s in fd :
    print(i)
    break
  else :
    fd[s] = 1

Submission status: Accepted

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

while True:
  cnt += 1
  if s % 2 == 0:
    s = s//2
  else:
    s = 3 * s + 1
  
  if S.count(s) == 1:
    print(cnt)
    exit()
  S.append(s)

Submission status: Accepted

Solution code:
def f(s):
    cnt = 0
    st = set()

    cnt += 1
    st.add(s)

    while True:
        cnt += 1

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

        if tmp in st:
            break

        st.add(tmp)
        s = tmp
    return cnt


s = int(input())
ans = f(s)
print(ans)

Submission status: Accepted

Solution code:
s = int(input())

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

seen = [s]

while True:
	n = collatz(s)
	if n in seen:
		break
	seen.append(n)
	s = n

print(len(seen) + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
count = 1
a = s
ans = {s}
while count<1000001:
  if a%2==0:
    a/=2
  else:
    a = 3*a+1
  if a in ans:
    print(count+1)
    break
  else:
    count+= 1
    ans.add(a)

Submission status: Accepted

Solution code:
s=int(input())

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

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

Submission status: Accepted

Solution code:
S = int(input())
ans_list = []
i = 0
while S not in ans_list:
  ans_list.append(S)
  if(S % 2 == 0):
    S = S/2
  else:
    S = 3 * S + 1
  i += 1

print(i+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [str(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))
def f(n):
    #print(l)
    if n%2 == 0:
        return n//2
    else:
        return 3*n + 1
if __name__ == "__main__":
    n = i()
    c = 0
    cnt = 1
    l = [n]
    #if n != 2 or n != 1 or n != 4:l = [n]
    while c < 2:
        n = f(n)
        cnt += 1
        if n in l:
            print(cnt)
            break
        l.append(n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=int(input())
arr=[]
h={}
def calc(n):
  if n % 2 ==0:
    return n/2
  else:
    return 3*n+1

for i in range(1000000):
  if i == 0:
    a = S
  else:
    a = calc(arr[i-1])
  if a in h:
    print(i+1)
    exit(0)
  arr.append(a)
  h[a]=i+1

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]
for i in range(100000):
    x = f(a[i])
    if(x in a):
        print(i + 2)
        exit()
    a.append(x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC116-B
s = int(input())

a = [0] * 1000000

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

    if a[i] in set(a[:i-1]):
        print(i+1)
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

va=I()
if va==1:
    print(4)
    sys.exit()
if va==2:
    print(4)
    sys.exit()
if va==4:
    print(4)
    sys.exit()
else:
    for i in range(1,10**6+10):
        if va%2==0:
            va=va//2
        else:
            va=3*va+1
        if va==4:
            print(i+4)
            sys.exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

ans = 0
set1 = set()
while True:
    if s in set1:
        print(ans+1)
        exit()
    else:
        set1.add(s)
        s = f(s)
        ans += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())

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

Submission status: Accepted

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

while 1 > 0:
    a += 1
    if s % 2 == 0:
        t = s //2
    else:
        t = 3 * s + 1
    if t in ls:
        print(a)
        break
    else:
        s = t
        ls.append(s)

Submission status: Accepted

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

for i in range(len(ans)-1):
    for j in range(i+1, len(ans)):
        if ans[i] == ans[j]:
            print(j+1)
            break
    else:
        continue
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
a=set()
a.add(s)
prev=s
for m in range(2,10**6+1):
    #print(a)
    if prev%2:
        if prev*3+1 in a:
            print(m)
            exit()
        else:
            prev=prev*3+1
        a.add(prev)
    else:
        if prev//2 in a:
            print(m)
            exit()
        else:
            prev=prev//2
        a.add(prev)

Submission status: Accepted

Solution code:
s = int(input())

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

i = 1
hist = {s:i}
while 1:
  s = f(s)
  i+=1
  if s in hist:
    print(i)
    break
  else:
    hist[s]= i

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = []
a.append(int(input()))
if a[0] in {1, 2}:
    s = a[0]
else:
    s = 4
cnt_s = 0
for i in range(10**6):
    if a[i] == s:
        cnt_s += 1
    if cnt_s == 2:
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
a = int(input())
idxs = defaultdict(int)
idxs[a] = 1
i = 1
ans = None
while True:
  i += 1
  if a % 2 == 0:
    a //= 2
  else:
    a = 3 * a + 1
    
  if not idxs[a]:
    idxs[a] = i
  else:
    ans = i
    break

print(ans)

Submission status: Accepted

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