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

dic = {}
for i in range(1000000):
    if s in dic:
        print(i+1)
        break
    dic[s] = 1
    if s % 2:
        s = 3 * s + 1
    else:
        s //= 2

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

s = int(sys.stdin.readline())
hist = {s}
i = 2
while True:
    if s % 2 == 0:
        s //= 2
    else:
        s = s * 3 + 1
    if s in hist:
        print(i)
        break
    hist.add(s)
    i += 1

Submission status: Accepted

Solution code:
s = int(input())

st = []
x = s

while st.count(x) == 0:
    st.append(x)
    if x % 2 == 0:
        x = x // 2
    else:
        x = 3*x + 1

print(len(st) + 1)

Submission status: Accepted

Solution code:
s = int(input())

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

a = [-1] * 1000000
a[0] = s
ans = 0

for i in range(1,1000000) :
    val = f(a[i-1])
    if val in a :
        ans = i + 1
        break
    a[i] = val

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=int(input())

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

ans=1
l=[a]
t=a
while True:
    ans+=1
    t=f(t)
    if t in l:
        print(ans)
        exit()
    l+=[t]

Submission status: Accepted

Solution code:
s = int(input())
memo = [-1]
memo.append(s)
def a(n):
    if memo[n-1] % 2 == 0:
        pre = memo[n-1]/2
        for i in memo:
            if i == pre:
                return n
        memo.append(pre)
        return a(n+1)
    else:
        pre = 3 * memo[n-1] + 1
        for i in memo:
            if i == pre:
                return n
        memo.append(pre)
        return a(n+1)

print(a(2))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

count = 0
while True:
    a.append(f(a[count]))
    if f(a[count+1])in(a):
        break
    count += 1

print(count+3)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def p(a):
    print(a)

s=int(input())

list=[s]

while True:
    if list[len(list)-1]%2==0:
        a=list[len(list)-1]/2
    else:
        a=3*list[len(list)-1]+1
    if a in list:
        p(len(list)+1)
        break
    else:
        list.append(a)
        # p(list)

Submission status: Accepted

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

while True:
    if s%2 == 0 :
        s = int(s/2)
    else:
        s = 3*s + 1
    ans += 1
    for t in S:
        if s == t:
            print(ans)
            break
    else:
        S.append(s)
        continue
    break

Submission status: Accepted

Solution code:
def solve(string):
    s = int(string)
    limit = 1000000
    i = 2
 
    d = {s: 1}
    m = s
    while i < limit:
        if m % 2 == 0:
            m = m // 2
        else:
            m = m*3 + 1
 
        if m in d:
            break
        else:
            d[m] = 1
 
        i += 1
 
    return i
 
 
if __name__ == "__main__":
    print(solve(input()))

Submission status: Accepted

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

# 整数の入力
s = int(input())

#初項 sは入力で与えられる。
#関数 f(n)を以下のように定める: n が偶数なら f(n)=n/2、n が奇数なら f(n)=3n+1
#i=1のとき ai=s、i>1 のとき ai=f(ai−1)
#    am=an(m>n)

a_list=[]
a_list.append(s)
i=0
flag=0
while(flag==0):
  i+=1
  before_a = a_list.pop(-1)
  a_list.append(before_a)
  
  if before_a%2==0:
    after_a = before_a/2
  else:
    after_a = (3 * before_a) + 1
  
  #print(after_a)
  
  for j in range(i):
    if a_list[j]==after_a:
      flag = 1
      break
  else:
    a_list.append(after_a)
    
print(i+1)

Submission status: Accepted

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

Submission status: Accepted

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

    print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = [n]
number = 2

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

Submission status: Accepted

Solution code:
s = int(input())
prev = s
v = {s}

for i in range(10**6):
    if prev%2==0:
        next = prev//2
    else:
        next = prev*3+1
    if next in v:
        print(i+2)
        break        
    v.add(next)
    prev = next

Submission status: Accepted

Solution code:
n=int(input())
l=[0]*100000
ans=0
while True:
    l[n]+=1
    ans+=1
    if l[n]>1:
        break
    if n%2==0:
        n=n//2 
    else:
        n=3*n+1
print(ans)

Submission status: Accepted

Solution code:
s = int(input())

cnt = 1
li = [s]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
i=1
L=[N]
M=N
while i< 1000000:
  i+=1
  if M%2==0:
    M=M/2
    L.append(int(M))
  else:
    M=3*M+1
    L.append(int(M))
  if L.count(M) ==2:
    print(i)
    break

Submission status: Accepted

Solution code:
def solve(x,n,ls):
    if ls.count(ls[-1]) == 2:
        return n
    
    if x%2 == 0:
        ls.append(int(x/2))
        return solve(int(x/2),n+1,ls)
        
    else:
        ls.append(int(3*x+1))
        return solve(int(3*x+1),n+1,ls)
    
if __name__ == "__main__":
    s = int(input())
    ls = [s]    
    

print(solve(s,1,ls))

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(1000000):
	ans += 1
	s = f(s)
	if s in a:
		break

	a.append(s)


print(ans)

Submission status: Accepted

Solution code:

def solve(s):
    preds = {s}
    i = 1
    while True:
        if s % 2 == 0:
            s /= 2
        else:
            s = 3 * s + 1
        i += 1
        if s in preds:
            return i
        preds.add(s)
s = int(input())
print(solve(s))

Submission status: Accepted

Solution code:
s = int(input())

a = []

a.append(s)
cont = True

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

print(i+2)

Submission status: Accepted

Solution code:
from sys import stdin
s = int(stdin.readline().rstrip())
A = []
while True:
    if s not in A:
        A.append(s)
    else:
        break
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
print(len(A) + 1)

Submission status: Accepted

Solution code:
import collections
import copy
s = int(input())
same = 0
List = []
List.append(s)
while same == 0:
    if s % 2 == 0:
        s = s / 2
        List.append(s)
        unique = set(copy.copy(List))
        _List = collections.Counter(List)
        for v in unique:
            if _List[v] == 2:
                same += 1
    else :
        s = 3 * s + 1
        List.append(s)
        _List = collections.Counter(List)
        unique = set(copy.copy(List))
        for v in unique:
            if _List[v] == 2:
                same += 1
print(len(List))

Submission status: Accepted

Solution code:
s = int(input())
arr = []
set_num = {s}

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
v_to_i = {}
cnt = 1
while not s in v_to_i:
    v_to_i[s] = cnt
    s = (s // 2) if s % 2 == 0 else (s*3+1)
    cnt += 1



print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
stop = 0
num_list = []
while stop == 0:
	if n in num_list:
		stop = 1
		print(num_list.index(n)+4)
	else:
		num_list.append(n)
		if n % 2 == 0:
			n //= 2
		else:
			n = 3 * n + 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

s = int(input())

lst_A = []

lst_A.append(s)

flg = "false"

while 1:

    if s % 2 == 0:
        s = int(s / 2)

    else:
        s = s * 3 + 1

    for i in range(len(lst_A)):

        if lst_A[i] == s:
            flg = "true"
            break

    if flg == "true":
        break

    lst_A.append(s)

print(len(lst_A) + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
n = 1
tmp = s
if s == 1 or s == 2:
    print(4)
else:
    for i in range(1, 1000000):
        if tmp == 4:
            n = i
            break
        elif tmp % 2 == 0:
            tmp = tmp//2
        else:
            tmp = 3*tmp + 1
    print(n+3)

Submission status: Accepted

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

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

def solve(s: int):
    a = [s]
    a_prev = s
    for i in range(100000):
        a_i = f(a_prev)
        a_prev = a_i
        if a_i in a:
            break
        else:
            a.append(a_i)
        
    print(i+2)
        
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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())

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

l = [s]
a = s

for i in range(2, 10000):
  a = calc(a)
  if a in l:
    print(i)
    exit()
  else:
    l.append(a)

Submission status: Accepted

Solution code:
s = int(input())

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

l = [s]
a = s
cnt = 2
while True:
  tmp = calc(a)
  if tmp in l:
    print(cnt)
    exit()
  else:
    l.append(tmp)
    a = tmp
    cnt = cnt + 1

Submission status: Accepted

Solution code:
s = int(input())
f = lambda n: (n/2) if n%2==0 else (3*n + 1)
prevval = s
history = [s]
c = 2
while True:
    newval = f(prevval)
    if newval in history:
        break
    history.append(newval)
    c += 1
    prevval = newval
print(c)

Submission status: Accepted

Solution code:
S = int(input())

num_list = [S]

while True:
    if S % 2 == 0:
        S = int(S / 2)
    else:
        S = int(S * 3 + 1)

    if S in num_list:
        break;  
    num_list.append(S)

print(len(num_list)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8

s = int(input())
li = []
li.append(s)
fl = True

while fl:
    # 要素の追加
    if li[-1] % 2 == 0:
        n = int(li[-1] / 2)
        li.append(n)
    elif li[-1] % 2 == 1:
        n = li[-1]*3 + 1
        li.append(n)

    # 一致を調べる
    for j in range(0,len(li)-1):
        if li[j] == n:
            fl = False

print(len(li))

Submission status: Accepted

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

for i in range(2, 1000000):
  if s%2 == 0:
    fn = int(s/2)
  else:
    fn = int(3*s+1)
  if fn in list:
    break
  list.append(fn)
  s = fn

print(i)

Submission status: Accepted

Solution code:
s = int(input())
M = 1000000

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

Submission status: Accepted

Solution code:
s = int(input())

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

a=[s]

for i in range(1000000):
	s = f(s)
	
	if s in a:
		print(len(a)+1)
		exit()
	a.append(s)

Submission status: Accepted

Solution code:
s = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = len(a)
print(ans)

Submission status: Accepted

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

s = int(input())
r = set([s])
m = 1

while True:
    m += 1
    s = f(s)
    if s in r:
        break
    else:
        r.add(s)

print(m)

Submission status: Accepted

Solution code:
s=int(input())  

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

a=[]  

while len(a)==len(set(a)):
  a.append(s)
  s=func(s)
  

print(len(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

a = [0 for _ in range(10 ** 5)]

ans = 1

while not a[s-1]:
    a[s-1] += 1
    if not s % 2:
        s = s // 2
    else:
        s = 3 * s + 1
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
s = int(input())
D = {}
for i in range(1000001):
    if s in D:
        print(i + 1)
        exit()
    else:
        D[s] = 1
        if s % 2 == 0:
            s //= 2
        else:
            s = 3 * s + 1

Submission status: Accepted

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

Submission status: Accepted

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

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


def solve(s: int):
    
    m_set = set()
    pn = s
    m_set.add(s)
    for m in range(1,100000000):
        nn = f(pn)
        if nn in m_set:
            print(m+1)
            return
        else:
            m_set.add(nn)
            pn = nn


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
n = int(input())
count = 1
ls = [n]
 
while True:
    if n % 2 == 0:
        n = n / 2
    else:
        n = 3 * n + 1
    count+=1
    if n in ls:
        break
    else:
        ls.append(n)
print(count)

Submission status: Accepted

Solution code:
n = int(input())
count = 1
ls = [n]

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

Submission status: Accepted

Solution code:
s = int(input())

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

memo = [False]*(10**6+1)
memo[s] = True
prev = s
for m in range(2,10**6+1):
    now = f(prev)
    if memo[now] == True:
        print(m)
        break
    else:
        memo[now] = True
    prev = now

Submission status: Accepted

Solution code:
s = int(input())


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


owned = {s}
n = 2
a = f(s)
while a not in owned:
    owned.add(a)
    a = f(a)
    n += 1
print(n)

Submission status: Accepted

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

s = int(input())
  
al = []
al.append(s)
cnum = s
for i in range(2,1000000):
  cnum = fn(cnum)
  if cnum in al[:-1]:
    print(i)
    exit()
  else:
    al.append(cnum)

Submission status: Accepted

Solution code:
n = int(input())
a = []
a.append(n)
sw = 0
count = 1

while True:
    count += 1 
    if n % 2 == 0:
        n = n / 2
    else :
        n = 3*n + 1
    
    for value in a:
        if value == n:
            print(count)
            sw = 1
            break

    if sw == 1:
        break
    a.append(n)

Submission status: Accepted

Solution code:
s = int(input())

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

cn = 0
seq = [s]
while True:
    ai = f(seq[cn])
    if ai in seq:
        print(cn+2)
        break
    seq.append(ai)
    cn += 1

Submission status: Accepted

Solution code:
def odd(a):
    return a/2

def even(b):
    return 3*b+1

num = int(input())
box = [num]
cnt = 0
answer = 0
while(True):
    if(num%2 == 0):
        num = odd(num)
    else:
        num = even(num)
    for i in range(len(box)-1):
        if(box[i] == num):
            answer = 1
    box.append(num)
    if(answer == 1):
        print(len(box))
        break

Submission status: Accepted

Solution code:
s = int(input())
n = 0
if s==1 or s == 2:
  print("4")
elif s==3:
  print("9")
if s >=4:
  s = 2*s
  while s % 2 == 0:
    s = s/2
    n += 1
    if s!=1 and s%2 == 1:
      s = 3*s+1
      n+=1
    if s == 1:
      print(n+1)
      break

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
# b = list(map(lambda x: math.ceil(x/10)*10, a))


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

Submission status: Accepted

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
intlist = list()
intlist.append(s)
i = 0
end = True
while end:
    s2 = 0
    if intlist[i] % 2 == 0:
        s2 = intlist[i] / 2
    else:
        s2 = 3 * intlist[i] + 1
    i += 1
    for j in intlist:
        if s2 == j:
            print(i + 1)
            end = False
            break
    intlist.append(s2)

Submission status: Accepted

Solution code:
s = int(input())
min = 1000000
arr = [s]
count = 0
count_No1 = 0
n = 0
flg_exit = 0

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

while (not flg_exit) or (min == 1000000):
    temp = func(arr[count])
    if temp == 1:
        count_No1 = count_No1 + 1
        flg_exit = 1 if count_No1 == 2 else flg_exit
    if (temp in arr) and (count_No1 != 1):
        min = count if count < min else min
    else:
        arr.append(int(temp))
        count = count + 1

count = 4 if s == 1 else count
count = 4 if s == 2 else count

print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Collatz Problem
https://atcoder.jp/contests/abc116/tasks/abc116_b

"""
import sys


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


def main(args):
    s = int(input())
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
s = int(input())

l = [1,2,4]
if s in l:
    print(4)
else:
    cnt = 1
    while s != 4:
        cnt += 1
        if s%2 == 0:
            s = s//2
        else:
            s = 3*s+1
    print(cnt+3)

Submission status: Accepted

Solution code:
S = int(input())

def main():
    a = [S]
    curr = S
    while a.count(curr) <= 1:
        curr = curr // 2 if curr % 2 == 0 else 3 * curr + 1
        a.append(curr)
    print(len(a))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import bisect
input = sys.stdin.readline

N = int(input())

p = N
s = set()
s.add(p)
c = 1

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

Submission status: Accepted

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

s = int(input())
appeared = set()

target = s
c = 1
while target not in appeared:
  appeared.add(target)
  target = collatz(target)
  c += 1
  
print(c)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

s = int(input())
ed = defaultdict(int)
cnt = 1
ed[s] = 1
while True:
    cnt += 1
    if s%2 == 0:
        s //= 2
    else:
        s = 3*s + 1
    if ed[s]:
        break
    else:
        ed[s] = 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC 116 B
s = int(input())
count = 1
num_set = {s}
def f(a):
    if a%2 == 0:
        return a/2
    else:
        return 3*a + 1
while (1):
    s = f(s)
    count += 1
    if s in num_set:
        print(count)
        break
    else:
        num_set.add(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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