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())
ans = [s]
flag = True
while (flag):
    if not(ans[-1] % 2):
        ans.append(int(ans[-1] / 2))
    else:
        ans.append(3 * ans[-1] + 1)
    if ans.count(ans[-1]) == 2:
        flag = False
        print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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())
i=1
if s==1: print(4)
elif s==2: print(4)
else:
    while s!=4:
        i+=1
        if s%2==0: s=s/2
        else: s=3*s+1
    print(i+3)

Submission status: Accepted

Solution code:
#次の項を求めるための定義分
def next_number(N):
  if N%2 == 0:
    return N/2
  else:
    return 3*N + 1

#ここからメイン文
S = int(input())
i = 2
flag = True
list = [S]
while flag == True:
    S = next_number(S)
    
    #listに追加する文字が既にlist内にないか確認
    if S in list:
        print(i)
        break
    else:
        list.append(S)
        i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = LI()
    a.sort()
    print(a[0]*a[1]//2)  
    return

#B
def B():
    d = defaultdict(int)
    s = II()
    def f(n):
        if n % 2:
            return 3 * n + 1
        return n // 2
    i = 1
    while not d[s]:
        d[s] = 1
        s = f(s)
        i += 1
    print(i)
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

Solution code:
s = int(input())

f = [s]

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

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

Solution code:
s = int(input())

sets = set([s])
count = 1
a = s
while 1:
    count += 1
    if a % 2==0:
        a = a // 2
    else:
        a = a*3 + 1

    if a in sets:
        print(count)
        break
    else:
        sets.add(a)

Submission status: Accepted

Solution code:
s=int(input())

c=0
num=s
n=[num]
while c==0:
    if num%2==0:
        num=num/2
    else:
        num=3*num+1
    if num in n:
        print(len(n)+1)
        c=1
    else:
        n.append(num)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())

arr = []

for i in range(1000000):
    if num in arr:
        break
    elif num%2==0:
        arr.append(num)
        num = int(num/2)
    elif num%2==1:
        arr.append(num)
        num = num*3 + 1

print(len(arr)+1)

Submission status: Accepted

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def gcd(a, b):
    if a == 0:
        return b
    if b == 0:
        return a

    if a > b:
        return gcd(b, a % b)
    else:
        return gcd(a, b % a)


def gcd_multi(nums):
    if len(nums) == 0:
        return 0
    if len(nums) == 1:
        return nums[0]

    ret = gcd(nums.pop(), nums.pop())
    while len(nums) > 0:
        ret = gcd(ret, nums.pop())
    return ret


def solve(inputs):
    [S] = string_to_int(inputs[0])
    current = S
    appeared_set = {current}
    i = 1
    while 1:
        i += 1
        if current % 2 == 0:
            current /= 2
        else:
            current = 3 * current + 1

        if current in appeared_set:
            return i

        appeared_set.add(current)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

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

seen = set([s])
i = 2
while collatz(s) not in seen:
    s = collatz(s)
    seen.add(s)
    i += 1
print(i)

Submission status: Accepted

Solution code:
S = int(input())

A = [S]
idx = 0
while True:
  if A[idx] % 2 == 0:
    A.append(A[idx]//2)
  else:
    A.append(A[idx]*3+1)
  if A[idx+1] in A[:idx+1]:
    print(idx+2)
    break
  idx += 1

Submission status: Accepted

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

a_list = [int(input())]

count = 0
while True:
	target = f(a_list[-1])
	if target in a_list:
		a_list.append(target)
		print(len(a_list))
		break
	else:
		a_list.append(target)

Submission status: Accepted

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

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

    a = s
    cnt = 1
    memo = set()
    memo.add(a)
    while True:
        a = f(a)
        cnt += 1
        if a in memo:
            break
        memo.add(a)
    print(cnt)


main()

Submission status: Accepted

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

Submission status: Accepted

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

print(a+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


d = dict()
d[s] = 1
an = s
i = 2
while True:
    an = f(an)
    if d.get(an) is not None:
        print(i)
        break
    d[an] = i
    i += 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
s = int(input())
result = [s]
tmp = s
while True:
  if collections.Counter(result).most_common()[0][1] == 2:
    break
  elif tmp%2 == 0:
    x = tmp/2
  elif tmp%2 > 0:
    x = (3*tmp) + 1
  tmp = x
  result.append(int(x))
print(len(result))

Submission status: Accepted

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

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

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])
for i in range(1000000):
    s = f(s)
    if s in r:
        print(i+2)
        break
    r.add(s)

Submission status: Accepted

Solution code:
s = int(input())

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

    if a in memo:
        print(m)
        break
    else:
        memo.append(a)

Submission status: Accepted

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

m = 1
while True:
  if s in se:
    answer = m
    break
  se.add(s)
  m += 1
  s = 3*s+1 if s&1 else s//2

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

memo = [False]*(M+1)
ans = -1
cnt = 1
while True:
    if memo[s]:
        ans = cnt
        break
    else:
        memo[s] = True
        cnt += 1
        if s % 2 == 0:
            s //= 2
        else:
            s = s * 3 + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input())

a = [s]

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

Submission status: Accepted

Solution code:
s = int(input())

ss = []

ss.append(s)
i = 1

def has_dup(list):
    return len(list) != len(set(list))

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

print(i)

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

Solution code:
s = int(input())

def f(n):
  if n%2 == 0:
    return n/2
  else:
    return 3 * n + 1
a = s
tmp =[]
count = 0
while True:
  tmp += [a]
  a = f(a)
  count += 1
  
  if a in tmp:
    print(count+1)
    exit()

Submission status: Accepted

Solution code:
s = int(input())

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

print(i)

Submission status: Accepted

Solution code:
s = int(input())

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

ans = [s]
flag = 0
while 1:
    s = collaz(s)
    if s not in ans:
        ans.append(s)
    else:
        ans.append(s)
        break
print(len(ans))

Submission status: Accepted

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

for i in range(1000001):
    s.append(f(s[i]))
    if len(set(s)) == i + 1:
        print(i + 2)
        exit()

Submission status: Accepted

Solution code:
n = int(input())

arr = [-1] * 1000000
arr[0] = n

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

	if i >= 3 and arr[i] == arr[i-3]:
		print(i + 1) #0->1 indexed
		break

Submission status: Accepted

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


s = int(input())
a = [s]
c = 1
while True:
    c += 1
    ss = func(a[-1])
    if ss not in a:
        a.append(ss)
    elif ss in a:
        print(c)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#n, m = map(int,input().split())
s = int(input())
#ls = list(map(int,input().split()))
#ls = [list(map(int,input().split()))[1:] for i in range(n)]
#s = input()

ls = [s]

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

for i in range(1000000):
  num = f(ls[i])
  if ls.count(num) == 1:
    print(len(ls)+1)
    quit()
  ls.append(num)

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

print(i + 3)

Submission status: Accepted

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

s = int(input())

l = []
l.append(s)

c = 1

while f(s) not in l:
    s = f(s)
    l.append(s)
    c+=1

print(c+1)

Submission status: Accepted

Solution code:
s = int(input())
def func(n):
  if n % 2 == 0:
    return n // 2
  else:
    return 3 * n + 1
d = {}
i = 1
while True:
  if s in d:
    print(i)
    break
  else:
    d[s] = 1
  s = func(s)
  i += 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#数列 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 が存在する。

def f(s): #関数を定義(cntを出力？)
    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
            break

        st.add(tmp) #集合に項を追加
        s = tmp
    return cnt


s = int(input())#初項を入力
ans = f(s) #関数を出力
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def a(i):
    if i == 1:
        return s
    else:
        return f(a(i-1))

list = []
for i in range(1,1000000):
    list.append(a(i))
    if len(list) != len(set(list)):
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
f = set()
f_now = s
i = 1
while True:
    f.add(f_now)
    
    if f_now%2==0:
        f_next = int(f_now/2)
    else:
        f_next = int(f_now*3 + 1)
    
    
    f_and = f&{f_next} 
    if len(f_and)==0:
        f_now = f_next
        i+=1
    else:
        break

print(i+1)

Submission status: Accepted

Solution code:
s=int(input())

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

a=[]
a.append(s)
for i in range(1,1000000):
    p=func(a[i-1])
    if not p in a:
        a.append(p)
    else:
        print(i+1)
        break

Submission status: Accepted

Solution code:
n1 = int(input())

t3 = 0
na4 = []
na4.append(n1)
i2 = 1
r1 = 0
while True:
    if na4[i2 - 1] % 2 == 0:
        t3 = na4[i2 - 1] // 2 
    else:
        t3 = (3 *  na4[i2 - 1] ) + 1
    for i5 in range(len(na4)):
        if na4[i5] == t3:
            r1 = len(na4) + 1
    i2 += 1
    na4.append(t3)
    if r1 != 0:
        break

print(r1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
e = set([s])
a = s
for i in range(1,1000000):
    if a%2 == 0:
        a = a//2
    else:
        a = 3*a+1
    
    e |= e^set([a])
    
    if len(e) == i:
        print(i+1)
        break

Submission status: Accepted

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

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

print(len(a) + 1)

Submission status: Accepted

Solution code:
num = 1
x = True
lists =[]
lists.append(int(input()))
while x:
    if lists[num-1]%2==0:
        a = lists[num-1]//2
        if a in lists:
            print(num+1)
            x = False
        else:
            num +=1
            lists.append(a)
    else:
        a = lists[num-1]*3+1
        if a in lists:
            print(num+1)
            x = False
        else:
            num +=1
            lists.append(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
t = {s}
m = 1
while True:
  if s%2:
    s = 3*s+1
  else:
    s //= 2
  m += 1
  if s in t:
    print(m)
    break
  t.add(s)

Submission status: Accepted

Solution code:
import bisect
s = int(input())
a = []
a.append(s)
tmp = s
m = 1

while True:
	if tmp % 2 == 0:
		tmp //= 2
	else:
		tmp = 3 * tmp + 1
		
	m += 1
	i = bisect.bisect_left(a, tmp)
	
	if i < (m - 1) and tmp == a[i]:
		break
	else:
		bisect.insort_left(a, tmp)

print(m)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

S = n()
seen = set()
seen.add(S)
m = 1
while True:
    m += 1
    if S % 2 == 0:
        S //= 2
    else:
        S = 3*S + 1
    if S in seen:
        print(m)
        import sys
        sys.exit()
    seen.add(S)

Submission status: Accepted

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

s=int(input())
l=[s]
if s==2 or s==1:
    print("4")
    exit()

ans=0
while l[ans]!=4:
    l.append(f(l[ans]))
    ans+=1
print(ans+4)

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

i = 0
while(True):
    i += 1
    if(s % 2 == 0):
        s = s / 2
        List.append(s)
    else:
        s = 3 * s + 1
        List.append(s)

    a = List[-1]
    if(List.count(a) != 1):
        break

print(i+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
i = 2
while s > 1:
    s = [s//2, s*3+1][s%2]
    i+=1
print(max(i,4))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s=int(input())
a=[s]
i=1
while True:
  if s%2==1:
    s=s*3+1
    i=i+1
  else:
    s=s//2
    i=i+1
  if s in a :
    print(i)
    sys.exit()
  a.append(s)

Submission status: Accepted

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

count = 1

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

print(count)

Submission status: Accepted

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


def abc():
    s = int(input().rstrip())

    pre = 0
    ns = []
    for i in range(1, 1000001):
        if i == 1:
            a = s
        else:
            a = f(pre)
        if a in ns:
            print(i)
            return
        ns.append(a)
        pre = a


abc()

Submission status: Accepted

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

for i in range(1000000):
    if len(l) != len(set(l)):
        ans = len(l)
        break

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

print(ans)

Submission status: Accepted

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

s = int(input())

an = [s]
i = 1
while True:
  i += 1
  an_1 = col(an[-1])
  if an_1 in an:
    break
  else:
    an.append(an_1)

print(i)

Submission status: Accepted

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

m = 1
while True:
  if s in se:
    answer = m
    break
  se.add(s)
  m += 1
  s = 3*s+1 if s&1 else s//2

print(answer)

Submission status: Accepted

Solution code:
s = int(input())

a = [s]
n = 1
while True:
    if a[n-1] % 2 == 0:
        next_a = a[n-1] // 2
    else:
        next_a = 3*a[n-1] + 1 
    if next_a in a:
        print(len(a)+1)
        break
    a.append(next_a)
    n += 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=s
A=[s]
i=2
while True:
    a=f(a)
    if a in A:
        print(i)
        break
    else:
        i+=1
        A.append(a)

Submission status: Accepted

Solution code:
def next(n):
	if n%2:
		return 3*n+1
	return n/2
cnt = {}
s = int(input())
cnt[s] = 1
i = 1
while True:
	w = next(s)
	i += 1
	if w in cnt:
		print(i)
		break
	cnt[w] = 1
	s = w

Submission status: Accepted

Solution code:
s = int(input())

a = [s]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())


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

candidate = [s]  
  
for i in range(2, 1000001):
  tmp = func(candidate[-1])
  if tmp in candidate:
    print(i)
    break
  else:
    candidate.append(tmp)

Submission status: Accepted

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

s=int(input())

list=[s]
i=1
answer=0

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

	for j in range(i):
		if list[i]==list[j]:
			answer=i+1

	i+=1 


print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

    if i == 0:
        a.append(s)
    elif i > 0:
        if a[i - 1] % 2 == 0:
            a.append(a[i - 1] / 2)
        elif a[i - 1] % 2 == 1:
            a.append(3 * a[i - 1] + 1)
        if a[i] in a[:i]:
            print(i + 1)
            exit()
    i += 1

Submission status: Accepted

Solution code:
s = int(input())

a = [0]
count = 0

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

    return ans

while True:
    if count == 0:
        a[0] = s
        count += 1
    else:
        a.append(f(a[count-1]))
        if a[count] in a[:(count-1)]:
            print(count+1)
            exit()
        else:
            count += 1

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())
 
a = ['#']
i = 0
while i < 1000001:
  i += 1
  if i == 1:
    a.append(s)
  else:    
    if a[i-1]%2 == 0:
      ai = a[i-1] / 2
    else:
      ai = 3 * a[i-1] + 1
   
    if ai in a:
      print(i)
      exit()
    
    a.append(ai)
s = int(input())

a = ['#']
i = 0
while i < 1000001:
  i += 1
  if i == 1:
    a.append(s)
  else:    
    if a[i-1]%2 == 0:
      ai = a[i-1] / 2
    else:
      ai = 3 * a[i-1] + 1
   
    if ai in a:
      print(i)
      exit()
    
    a.append(ai)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque

input = sys.stdin.readline

s = int(input())
a = deque()
a.append(s)
counter = 0

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

for i in range(10000000):
    if a[i] == 4:
        break
    counter += 1
    if a[i] % 2 == 0:
        a.append(int(a[i]/2))
    else:
        a.append(3*a[i] + 1)

print(counter + 4)