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:
a = []
a.append(int(input()))
i = 1
while True:
  x = a[-1]
  if x % 2 == 0:
    y = x // 2
    a.append(y)
  else:
    y = 3 * x + 1
    a.append(y)
  if a.count(y) >= 2:
    break
print(len(a))

Submission status: Accepted

Solution code:
def collatz(n):
	c = 1
	check = [n]
	while(True):
		c += 1
		if n & 1 == 0:
			n = n // 2
			if n in check:
				break
			check.append(n)
		else:
			n = (n * 3) + 1
			if n in check:
				break
			check.append(n)
	return c
n = int(input())
print(collatz(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
from collections import defaultdict
d=defaultdict(int)
def find(n,i):
    if d[n]!=0:
        return i
    d[n]=i
    if n%2==0:
        return find(n//2,i+1)
    else:
        return find(3*n +1 ,i+1)

print(find(n,1))

Submission status: Accepted

Solution code:
s = int(input())

f = [s]

for i in range(1,1000000):
    if f[i-1] % 2 == 0:
        f.append(f[i-1]//2)
    else:
        f.append(3*f[i-1] + 1)
        
    for j in range(len(f)-1):
        if f[i] == f[j]:
            print(i + 1)
            exit()

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

n = int(input())


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

a = [n]
for i in range(2, 1000001):
    n = func(n)
    if n in a:
        print(i)
        exit()
    else:
        a.append(n)

Submission status: Accepted

Solution code:
s = int(input())
an = [s]
for n in range(2, 1000):
    if an[n-2]%2 == 0:
        a = an[n-2]//2
        #print(a)
        if a in an:
            print(n)
            exit()
        else:
            an.append(a)
    else:
        a = 1 + 3*an[n-2]
        if a in an:
            print(n)
            exit()
        else:
            an.append(a)

Submission status: Accepted

Solution code:
s = int(input())

a = s
ar = [a]
for i in range(1, 100000000):
    if(a % 2 == 0):
        a = a/2
    else:
        a = 3*a + 1
    if(ar.count(a) == 1):
        # print("a", a)
        print(i+1)
        break
    # print("a", a)
    ar.append(a)

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

a = s
for i in range(2, 10**6):
    if a % 2 == 0:
        if a // 2 in l:
            print(i)
            exit()
        l.append(a // 2)
        a = a // 2
    else:
        if 3 * a + 1 in l:
            print(i)
            exit()
        l.append(3 * a + 1)
        a = 3 * a + 1

Submission status: Accepted

Solution code:
a = int(input())

A = []

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

print(len(A) + 1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
T = set()
T.add(s)
for i in range(1000001):
  if s%2:
    s = s*3 + 1
  else:
    s = s // 2
  l = len(T)
  T.add(s)
  if l == len(T):
    print(i+2)
    exit()

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	n = int(input())
	A = []
	cnt = 1
	A.append(n)

	while True:
		if n % 2 == 0:
			n = n // 2
		else:
			n = 3 * n + 1
		cnt += 1
		if n in A:
			print(cnt)
			break
		A.append(n)

Submission status: Accepted

Solution code:
import math


def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    s = int(input().rstrip())
    opened = set()
    opened.add(s)
    prev = s
    m = 1
    while True:
        m += 1
        y = int(prev / 2) if prev % 2 == 0 else (3 * prev + 1)
        if y in opened:
            print(m)
            break
        prev = y
        opened.add(y)









if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

for i in range(2,10**7+1):
  a[i] = f(a[i-1])
  if a[i] in cnt:
    print(i)
    break
  else:
    cnt.append(a[i])

Submission status: Accepted

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

A = [int(input())]
i = 1
while True:
  x = collatz(A[-1])
  if x in A:
    print(i + 1)
    break
  else:
    A.append(x)
    i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    s=ii()
    X = [s]
    seen = set([s])
    for i in range(10**6+10):
        x = X[-1]
        if x % 2 == 0:
            y = x//2
        else:
            y = 3*x+1
        
        X.append(y)
        if y in seen:
            print(i+2)
            # print(X)
            exit()

        seen.add(y)
    
    assert False




        





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    s = ni()
    d = {}
    d[s] = 1
    ans = 1
    while True:
        ans += 1
        if s % 2 == 0:
            s = s // 2
        else:
            s = 3 * s + 1
        if s in d:
            print(ans)
            return
        else:
            d[s] = 1


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = inint()

a = [s]
al = [s]


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
def f(x):
    if x%2==0:
        return x//2
    else:
        return 3*x+1
a=s
ans=[s]
for i in range(10**6+5):
    a=f(a)
    if a in ans:
        print(i+2)
        exit()
    ans.append(a)

Submission status: Accepted

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

s=int(input())
cnt=1
while s!=4 and s!=2 and s!=1:
  cnt+=1
  s=f(s)
print(cnt+3)

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

while True:
  count += 1
  if a % 2 == 0:
    a = a/2
  else:
    a = 3*a + 1
  if a in A:
    break
  A.append(a)
  
print(count+1)

Submission status: Accepted

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

while True:
  if l[-1] % 2 == 0: l.append(l[-1] // 2) # n is even
  else: l.append(3 * l[-1] + 1) # n is odd
  if l[-1] in l[:-1]: break
      
print(len(l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input());a=[]
while n not in a: a.append(n);n=[3*n+1,n//2][n%2==0]
print(len(a)+1)

Submission status: Accepted

Solution code:
n=int(input());a=[]
while n not in a:
  a.append(n);n=[3*n+1,n//2][n%2==0]
print(len(a)+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    n.append(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

a = [s]
last = s

while True:
    if last % 2 == 0:
        last //= 2
    else:
        last = last * 3 + 1

        
    if last in a:
        print(len(a) + 1)
        exit()
    else:
        a.append(last)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict


def input():
    return sys.stdin.readline().rstrip()


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

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

    ss = set()
    ss.add(s)

    for i in range(10 ** 8):
        s = f(s)
        if s in ss:
            print(i+2)
            exit()
        ss.add(s)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = int(input())
an = [s]
for i in range(1, 1000000):
    if an[i-1]%2==0:
        ins = an[i-1]//2
    else:
        ins = 3*an[i-1]+1

    if ins not in an:
        an.append(ins)
    else:
        print(i+1)
        exit()

Submission status: Accepted

Solution code:
s = int(input())

answer_list = []
answer_list.append(s)
count = 1
while True:
    count += 1
    next_s = 0
    if s % 2 == 0:
        next_s = s // 2
    else:
        next_s = s * 3 + 1
    s = next_s
    if s in answer_list:
        print(count)
        exit()
    answer_list.append(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

a = {s}
b = s 
for i in range(2,1000001):
    if b%2==0:
        b //= 2
    else:
        b = 3*b+1

    if b in a:
        print(i)
        exit()
    else:
        a.add(b)

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input())
old = s
count=1
history={s}
while 1:
  new = f(old)
  count += 1
  if new in history:
    break
  history.add(new)
  old = new

print(count)

Submission status: Accepted

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

n = int(input())
collatz_list = [n]

for i in range(10**6):
    n = collatz(n)
    if not n in collatz_list:
        collatz_list.append(n)
    else:
        print(i+2)
        break

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s=int(input())
li=[s]
for i in range(10**6):
    if s%2==1:
        s=3*s+1
        li+=[s]
    else:
        s//=2
        li+=[s]
    if len(li)!=len(set(li)):
        print(i+2)
        break

Submission status: Accepted

Solution code:
# abc116_b.py
# https://atcoder.jp/contests/abc116/tasks/abc116_b

# ★ RE:4
# 07.txt
# 08.txt
# 09.txt
# s3.txt

# B - Collatz Problem /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 数列 a={a1,a2,a3,......}は、以下のようにして定まります。
#     初項 sは入力で与えられる。
#     関数 f(n)を以下のように定める: n が偶数なら f(n)=n/2、n が奇数なら f(n)=3n+1。
#     i=1のとき ai=s、i>1 のとき ai=f(ai−1)である。
# このとき、次の条件を満たす最小の整数 mを求めてください。
#     am=an(m>n)を満たす整数 nが存在する。

# 制約
#     1≦s≦100
#     入力はすべて整数である。
#     aのすべての要素、および条件を満たす最小の m は 1000000以下となることが保証される。

# 入力
# 入力は以下の形式で標準入力から与えられます。
# s

# 出力
# 条件を満たす最小の整数 mを出力してください。

# 入力例 1
# 8

# 出力例 1
# 5

# a={8,4,2,1,4,2,1,4,2,1,......}です。a5=a2 なので、答えは 5です。

# 入力例 2
# 7

# 出力例 2
# 18

# a={7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4,2,1,......}です。

# 入力例 3
# 54

# 出力例 3
# 114


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # X = lines[0]
    s = int(lines[0])
    # values = list(map(int, lines[0].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))

    values = [s]

    for i in range(1000000):
        s = func_f(values[i])
        if s in values:
            return [i+2]
        values.append(s)


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


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['8']
        lines_export = [5]
    if pattern == 2:
        lines_input = ['7']
        lines_export = [18]
    if pattern == 3:
        lines_input = ['54']
        lines_export = [114]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    if FLAG_LOG:
        log(f'lines_input=[{lines_input}]')
        log(f'lines_export=[{lines_export}]')
        log(f'lines_result=[{lines_result}]')
        if lines_result == lines_export:
            log('OK')
        else:
            log('NG')
    finished = time.time()
    duration = finished - started
    log(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

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]
while a[-1] not in a[:len(a)-2]:
    if a[-1] % 2 == 1:
        a.append(3 * a[-1] + 1)
    else:
        a.append(a[-1] // 2)
print(len(a))

Submission status: Accepted

Solution code:
s = int(input())

seq = [s]

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

m = 1
while True:
  i = m-1
  a = f(seq[i])
  
  if a in seq:
    break
  seq.append(a)
  m += 1
print(m+1)

Submission status: Accepted

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

for _ in range(1,1000):
    if s % 2 != 0:
        a.append(int(3*s+1))
        s = int(3*s+1)
    else:
        a.append(int(s/2))
        s = int(s/2)

cnt = 0
ans = []

for i,j in zip(a,a[1:]):
    ans.append(i)
    if j in ans:
        ans.append(j)
        print(len(ans))
        break

Submission status: Accepted

Solution code:
S=int(input())
flag = True
n = 2
List=[S]
res = 0
while flag:
  if S % 2 == 0:
    S = S // 2
  else:
    S = 3* S +1
  if List.count(S) ==0:
    List.append(S)
  else:
    res = n
    flag = False
  n += 1
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

s = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
s = int(input())

ans = [s]
idx = 1
tmp = s
while True:
    if tmp % 2 == 0:
        tmp = tmp//2
    else:
        tmp = (3*tmp) + 1
    idx +=1

    if tmp in ans:
        print(idx)
        exit()
    else:
        ans.append(tmp)

Submission status: Accepted

Solution code:
s = int(input())

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

ans = [s]
count = 2
while (n:=f(ans[-1])) not in ans:
    ans.append(n)
    count += 1

print(count)

Submission status: Accepted

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

s = int(input())

A = [s]
i = 0
while A[i] not in A[:i]:
  A.append(func(A[i]))
  i += 1
print(i + 1)

Submission status: Accepted

Solution code:
s = int(input())
l = []
l.append(s)
i = 1
ans = 2

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

    if a in l:
        ans = i + 1
        break
    else:
        i += 1
        l.append(a)
        continue
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
check = 0
keep = []

def q(n, check):
    if n in keep:
        return check
    else:
        keep.append(n)
    if n % 2 == 0:
        n = n // 2
    else:
        n = 3 * n + 1
    return q(n, check+1)
print(q(n,check)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

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

x = ii()
d = defaultdict(int)
d[x] = 1
ind = 1
while True:
    ind += 1
    if d[f(x)] == 1:
        print(ind)
        exit()
    d[f(x)] += 1
    x = f(x)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    a = int(input())
    exist = [0] * (10**6 + 1)
    exist[a] = 1
    ans = 1
    while(True):
        ans += 1
        if a%2 == 0: 
            a //= 2
        else: 
            a = 3*a + 1
        if exist[a] == 1: 
            print(ans)
            return
        else: 
            exist[a] = 1
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=int(input())
n=set()
a=s
for i in range(10**7):
    if a in n:
        break
    if a%2:
        n.add(a)
        a=3*a+1
    else:
        n.add(a)
        a//=2
print(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]
B = True
i = 0
while B:
  a.append(f(a[i]))
  if a.count(f(a[i])) > 1:
    print(i+2)
    break
  i += 1

Submission status: Accepted

Solution code:
import numpy as np
s = int(input())
a = np.full(1000001,-1)
a[0] = s
for i in range(1,1000001):
    if a[i-1] % 2 == 0:
        a[i] = a[i-1] // 2
    elif a[i-1] % 2 != 0:
        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 = []
a.append(s)
def f(n):
    if n%2 ==0:
        return int(n/2)
    else:
        return 3*n+1
i = 1        
while f(a[-1]) not in a:
    a.append(f(a[-1]))
    i+=1
#print(i,a)
print(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

A = [s]
while True:
  a = f(A[-1])
  if a in A:
    ans = len(A) + 1
    break
  else:
    A.append(a)

# /print(A)
print(ans)

Submission status: Accepted

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

a = [s]

ans = 1
while(True):
  ans += 1
  if a[-1]%2 == 0:
    num = a[-1]//2
  else:
    num = a[-1]*3+1
  for i in range(len(a)):
    if a[i] ==num:
      print(ans)
      sys.exit()

  a.append(num)

Submission status: Accepted

Solution code:
import sys
s=int(input())
dp=[0]*1000001
dp[s]=1
cnt=1
for i in range(1000001):
  if s%2==1:
    s=3*s+1
  else:
    s//=2
  cnt+=1
  if dp[s]==1:
    print(cnt)
    sys.exit()
  else:
    dp[s]=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def main():
  s = int(input())
  numarray=[s]
  ans=0
  i=1
  while True:
    if s%2==1:
      s=3*s+1
    else:
      s=int(s/2)
    if s in numarray:
      break
    else:
      numarray.append(s)
      i+=1
  print(i+1)
main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input())

log = set([s])

cnt = 1

while True:
    if fnc(s) in log:
        cnt += 1
        print(cnt)
        break
    else:
        s = fnc(s)
        log.add(s)
        cnt += 1

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

s = int(input())
dic = defaultdict(int)
dic[s] += 1
cnt = 1
while True:
    if s % 2 == 0:
        s //= 2
    else:
        s = 3 * s + 1
    cnt += 1
    dic[s] += 1
    if dic[s] > 1:
        print(cnt)
        exit()

Submission status: Accepted

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

for n in range(1000000):
  if a[n]%2==0:
    if int(a[n]/2) not in a:
      a.append(int(a[n]/2))
    else:
      print(n+2)
      exit()
  else:
    if int(3*a[n]+1) not in a:
      a.append(int(3*a[n]+1))
    else:
      print(n+2)
      exit()

Submission status: Accepted

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

s = int(input())
ans = 1

while s != 4 and s != 2 and s != 1:
    s = judge(s)
    ans += 1

print(ans+3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans = 1

s = int(input())
l = {s}

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

Submission status: Accepted

Solution code:
#20
import sys
s = int(input())
a = []
i = 2

while i >0:
    if s %2 == 0:
        a.append(s)
        s = int(s/2)
    else:
        a.append(s)
        s = 3*s+1
    for j in a:
        if s == j:
            print(i)
            sys.exit()
    i+=1

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

    s = int(input())
    vals = [s]
    while True:
        new_v = fun(vals[-1])
        if new_v in vals:
            print(len(vals) + 1)
            break
        else:
            vals.append(new_v)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

cnt=0
for i in range(10**6):
  if s%2==0:
    s=s/2
    cnt+=1
    if s in a:
      break
    a.append(s)
    
  else:
    s=3*s+1
    cnt+=1 
    if s in a:
      break    
    a.append(s)

print(cnt+1)