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

if s==1 or s==2 or s==4:
  cnt=0
else:
  cnt=0
  while s!=4:
    if s%2==0:
      s=s/2
      cnt+=1
    else:
      s=3*s+1
      cnt+=1 

print(cnt+4)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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


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

    s = ii()
    st = set()

    cnt = 1
    while s not in st:
        cnt += 1
        st.add(s)
        s = collatz(s)
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

print(len(A)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s = int(input())
if not ( 1 <= s <= 100 ): sys.exit()
array = [s]

for I in range(1,10 ** 6 + 1):
    if array[ I - 1 ] % 2 == 0:
        if array[I - 1]//2 in array:
            print(I + 1)
            sys.exit()
        array.append(array[(I - 1)]//2)     
    else:
        if (3 * array[I - 1]) + 1 in array:
            print(I + 1)
            sys.exit()
        array.append((3 * array[(I - 1)]) + 1)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc116


def main():
    s = int(input())
    a = [s]

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


print(main())

Submission status: Accepted

Solution code:
S = int(input())
A = [S]
if (A[0]%2) == 0:
  A.append(int(A[0]/2))
else:
  A.append(int(3*A[0]+1))
i = 1
while i >0:
  if A[i]%2 == 0:
    X = int(A[i]/2)
    if X in A:
      A.append(X)
      break
    else:
      A.append(X)
    i += 1
  else:
    X = int(3*A[i]+1)
    if X in A:
      A.append(X)
      break
    else:
      A.append(X)
    i += 1
print(len(A))

Submission status: Accepted

Solution code:
s = int(input())
set = {s}
for i in range(1000000):
  if s%2 == 0:
    s /= 2
  else:
    s = s*3+1
  if s in set:
    print(i+2)
    break
  set.add(s)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = ri()
li = [s]
cnt = 1
while True:
  if s&1 == 1:
    s = 3*s + 1
  else:
    s = s//2
  cnt += 1
  if s not in li:
    li.append(s)
  else:
    print(cnt)
    exit()

Submission status: Accepted

Solution code:
import sys
s = int(input())
A = [False] * 1_000_001
cnt = 1
A[s] = True


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


while True:
    s = f(s)
    cnt += 1
    if A[s]:
        print(cnt)
        sys.exit()
    else:
        A[s] = True

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
pos = {s}
c = 0
n = s
while True:
    n = 3*n+1 if n&1 else n//2
    c += 1
    if n in pos:
        print(c+1)
        break
    pos.add(n)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
a = list(map(int, input().split()))
a+= [0]*(10**6 +1)
i=0
while True:
   
    if a[i] %2 ==0:
        a[i+1] =a[i]//2
    else:
        a[i+1] =a[i] *3 +1
    if a[i+1] in a[:i]:
        print(i+1+1)
        break
    i +=1

Submission status: Accepted

Solution code:
s = int(input())

answer = 1
an = {1:s}
i = 2
while(True):
  if an[i-1]%2 == 0:
    if (an[i-1]//2) in an.values():
      answer = i
      break
    else :
      an[i] = an[i-1]//2
  else :
    if (3*an[i-1]+1) in an.values():
      answer = i
      break
    else :
      an[i] = 3*an[i-1]+1
  i += 1  
      
print(answer)

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    s = int(input())
    is_not_found = True
    cnt = 1
    memo = [False for _ in range(10**7+1)]

    while memo[s] == False:
        cnt += 1
        memo[s] = True
        if s % 2 == 0:
            s //= 2
        else:
            s = 3*s + 1    

    print(cnt)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

print(m)

Submission status: Accepted

Solution code:
s = int(input())

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

A = {s}
for ans in range(2, 10**6+10):
    if f(s) in A:
        print(ans)
        break
    A.add(f(s))
    s = f(s)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

s = int(input())
a = [0, s]
i = 2

while a[-2] != 2 and a[-1] != 1:
  if (a[i-1])%2 == 0:
    a.append(int(a[i-1]/2))
  elif (a[i-1])%2 == 1:
    a.append(int(1+3*a[i-1]))
  i += 1
a.append(4)
a.append(2)
a.append(1)

stuck = []
for i in range(1, len(a)):
  if (a[i]) in stuck:
    print(i)
    sys.exit()
  else:
    stuck.append(a[i])

Submission status: Accepted

Solution code:
s = int(input())

ans = 0

while s not in [1,2,4]:
    ans+=1
    if s%2:
        s = 3*s+1
    else:
        s//=2

print(ans+4)

Submission status: Accepted

Solution code:
s = int(input())

check = {}
check[s]=1
counter = 1
while 1:
    counter +=1
    s = s//2 if s%2 ==0 else 3*s+1
    if s in check:
        print(counter)
        break
    check[s]=1

Submission status: Accepted

Solution code:
s = int(input())

check = [0]*(10**6+1)
check[s]=1
counter = 1
while 1:
    counter +=1
    s = s//2 if s%2 ==0 else 3*s+1
    if check[s]==1:
        print(counter)
        break
    check[s]=1

Submission status: Accepted

Solution code:
import sys
def f(x):
  if x%2==0:
    return x//2
  else:
    return (x*3)+1
s=int(input())
S=list()
i=2
S.append(s)
while True:
  s=f(s)
  if s not in S:
    S.append(s)
  else:
    print(i)
    sys.exit()
  i+=1

Submission status: Accepted

Solution code:
s=int(input())

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

l=[s]
while s!=1:
    s=collatz(s)
    l.append(s)

if l[0]==1:
    print(4)
elif l[0]==2:
    print(4)
else:
    print(len(l)+1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# どうせすぐにみつかる
n = int(input())

def gen_sequence(seed):
    yield seed
    last = seed
    while True:
        if last&1:
            last = last*3 + 1
        else:
            last = last//2
        yield last

mem = set([])
for i,x in enumerate(gen_sequence(n), 1):
    if x in mem:
        print(i)
        exit()
    mem.add(x)

Submission status: Accepted

Solution code:
def f(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n+1
s = int(input())
A = [s]
for i in range(2, 1000001):
    A.append(f(A[-1]))
    if len(A) != len(set(A)):
        print(i)
        exit(0)

Submission status: Accepted

Solution code:
s=int(input())

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

Submission status: Accepted

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

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

b = []
for i, num in enumerate(a):
    if num in b:
        print(i+1)
        break
    b.append(num)

Submission status: Accepted

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

while True:
  n+=1
  A+=[a]
  
  if a%2==0:
    a//=2
  else:
    a=1+3*a
  
  if a in A:
    print(n)
    break

Submission status: Accepted

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

for n in range(2,10**6):
  if A[-1]%2==0:
    if A[-1]//2 in A:
      print(n)
      exit()
    else:
      A.append(A[-1]//2)
  else:
    if 1+3*A[-1] in A:
      print(n)
      exit()
    else:
      A.append(1+3*A[-1])

Submission status: Accepted

Solution code:
s = int(input())

used = set([s])
a = s
for i in range(2, 1000000):
    if a % 2 == 0:
        next = a // 2
    else:
        next = 3 * a + 1

    if next in used:
        print(i)
        break
    else:
        used.add(next)
        a = next

Submission status: Accepted

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

cnt = 1
while True:
    if int(lst[-1]) & 1 == 0:
        cnt += 1
        next_a = lst[-1]/2
        if next_a in lst:
            m = cnt
            break
        lst.append(next_a)
        
    else:
        cnt += 1
        next_aa = 3*lst[-1] +1
        if next_aa in lst:
            m = cnt
            break
        lst.append(next_aa)

print(m)

Submission status: Accepted

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

for i in range(10**6):
    if int(lst[-1]) & 1 == 0:
        next_a = lst[-1]/2
        if next_a in lst:
            m = i + 1
            break
        lst.append(next_a)
    else:
        next_aa = 3*lst[-1] +1
        if next_aa in lst:
            m = i + 1
            break
        lst.append(next_aa)

print(m+1)

Submission status: Accepted

Solution code:
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

S = int(input())


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


List_A = [S]
for i in range(10 ** 6):
    A = f(List_A[i])
    if A in List_A:
        print(i+1+1)
        break
    else:
        List_A.append(A)

Submission status: Accepted

Solution code:
s = int(input())


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


p = {s: 1}
m = 1
while True:
    s = f(s)
    m += 1
    if s in p:
        print(m)
        break
    else:
        p[s] = m

Submission status: Accepted

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


a = int(input())
i = 1
s = set([a])
while True:
    i += 1
    a = f(a)
    if a in s:
        break
    s.add(a)

print(i)

Submission status: Accepted

Solution code:
s=int(input())
se={s}
for i in range(10000000):
    if s%2==0:
        s=s//2
        if s in se:
            print(i+2)
            exit()
        else:
            se.add(s)
    else:
        s=s*3+1
        if s in se:
            print(i+2)
            exit()
        else:
            se.add(s)

Submission status: Accepted

Solution code:
s = int(input())

# 3 million should do for upper limit...
K = [0]*3000000

for i in range (0, 10000000):
	if K[s] == 0:
		K[s]=1
		if s%2 == 0:
			s = int(s/2)
		else:
			s = 3*s+1
	else:
		print(i+1)
		exit()

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input())
res = [s]
idx = 0
for i in range(2, 10 ** 6 + 1):
    s = func(s)
    if s in res:
        idx = i
        break
    res.append(s)
print(idx)

Submission status: Accepted

Solution code:
S = int(input())

A = [S]

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

print(len(A)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
def f(n):
  if n%2==0:
    return n/2
  else:
    return 3*n+1
  
seq=[0 for i in range(1000000)]
seq[0]=s
seq[1]=f(seq[0])
count =1
set={s,seq[1]}
while 1-(f(seq[count]) in set):
  seq[count+1]=f(seq[count])
  set.add(f(seq[count]))
  count=count+1

print(count+2)

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

Submission status: Accepted

Solution code:
def main():
    s = int(input())
    e = set([s])
    i = 1
    while True:
        i += 1
        s = f(s)
        if s in e:
            print(i)
            return
        e.add(s)
    
def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3*n + 1
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve():
    s = int(input())
    n = s
    a = {s}
    for i in range(2, 10 ** 6 + 1):
        if n % 2 == 0:
            n = n // 2
        else:
            n = 3 * n + 1
        if n in a:
            print(i)
            exit()
        else:
            a.add(n)







if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
s = int(input())
ans_list = [0] * (10 ** 6 + 1)
ans_list[0] = s
now = s

i = 1
T = True
while T:
  if now % 2 == 0:
    now = int(now / 2)
  else:
    now = 3 * now + 1
  i += 1
  if now in ans_list:
    print(i)
    T = False
  ans_list[i - 1] = now
  #print(now)
  #print(ans_list)

Submission status: Accepted

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

Submission status: Accepted

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

  if s in A:
    print(i)
    exit()

  i += 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = int(input())

a =S
A =[]
i = 1

while True:
  i +=1
  A += [a]
  a = int(a/2 if a%2==0 else 3*a+1)
  if a in A:
    break

print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
if 1==s or 2==s or 4==s:
  print(4)
  exit()
x=0
for i in range(1,10**9):
  if 1==i:
    x=s
  if 1<i:
    if x%2!=0:
      x=3*x+1
    else:
      x/=2
  if 4==x:
    print(i+3)
    exit()

Submission status: Accepted

Solution code:
s = int(input())

def f(n):
    if n%2 == 0:
        return int(n/2)
    else:
        return 3*n+1
    
memo = {i: 0 for i in range(1, 999999)}

a = s
i = 1
memo[a] = 1

while(True):
    i += 1
    a = f(a)

    if memo[a]:
        break

    memo[a] = 1
    
        
print(i)

Submission status: Accepted

Solution code:
s = int(input())

l = [s]
temp = s
for i in range(2, 10**7):

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

    if temp in l:
        print(i)
        exit()
    else:
        l.append(temp)

Submission status: Accepted

Solution code:
s = int(input())
a = s
lis = list()

while True:
    if (s % 2) == 0:
        s = s / 2
        if s in lis:
            break
        lis.append(int(s))
    else:
        s = 3*s + 1
        if s in lis:
            break
        lis.append(int(s))
if (a ==1) or (a == 2) or (a == 4):
    print(4)
else:
    print(len(lis)+2)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    a = set([N])
    i = 1
    l = 1
    while True:
        i += 1
        if N % 2 == 0:
            N = N // 2
        else:
            N = 3 * N + 1
        a.add(N)
        if l == len(a):
            print(i)
            break
        else:
            l += 1


resolve()

Submission status: Accepted

Solution code:
import sys
s = int(input())
cop = []
cop.append(s)
if s%2 == 0:
	s //= 2
else:
	s = 3*s + 1

for i in range(1,1000):
	if s in cop:
		print(i+1)
		sys.exit()
	else:
		cop.append(s)
		if s%2 == 0:
			s //= 2
		else:
			s = 3*s + 1

Submission status: Accepted

Solution code:
import sys
s = int(input())
m = 1000000
D={} #これで辞書を作る
D[s] = 1
for i in range(2,m):
    if s%2 == 0:
        s = s//2
    else:
        s = 3*s+1
    if s in D.keys(): #sが辞書Dにあるのかチェック(これはある場合)
        D[s] += 1 #D[s] += 1 ->{'s':今までに出てきた回数+1}となる
    else:  #sが辞書Dにない場合
        D[s] = 1 #D[s] = 1 ->{'s':1}となる
    if D[s] ==2:
        print(i)
        sys.exit()

Submission status: Accepted

Solution code:
N = int(input())

d = {N}
temp = N
for i in range(2, 10**7):
    if temp%2 == 0:
        temp //= 2
    else:
        temp = 3*temp + 1
    if {temp} & d:
        print(i)
        break
    else:
        d.add(temp)

Submission status: Accepted

Solution code:
def f(n):
    if n%2==0:
        return n/2
    else:
        return 3*n+1
def has_duplicates(seq):
    return len(seq) != len(set(seq))
s=int(input())
a=list()
a.append(s)
i=0
while True:
    a.append(f(a[i]))
    double=has_duplicates(a)
    if double==True:
        print(i+2)
        break
    i+=1

Submission status: Accepted

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

i=1
while len(set(l))==i:
    if n%2==0:
        n=n/2
    else:
        n=3*n+1
    l.append(n)
    i+=1
print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

i = 1
while True:
    if s == 4 or s == 2 or s == 1:
        print(i+3)
        exit(0)
    if s % 2 == 0:
        s /= 2
    else:
        s = 3 * s + 1
    i += 1

Submission status: Accepted

Solution code:
s = int(input())
d = set()
i = 1
while s not in d:
    d.add(s)
    s = 3 * s + 1 if s & 1 else s // 2
    i += 1
print(i)

Submission status: Accepted

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

    if len(set(a)) != len(a):
        print(i + 2)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = [0]*1000000
a[0] = int(input())

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