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 = int(input())
alist = set()
count = 1
def f(a):
    if a%2==1:
        return 3*a+1
    else:
        return a//2

def check(a,alist):
    if a in alist:
        return False
    else:
        return True
while check(a,alist):
    count += 1
    alist.add(a)
    a = f(a)

print(count)

Submission status: Accepted

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

print(len(k)+1)

Submission status: Accepted

Solution code:
def next(n):
    if n & 1:
        return 3 * n + 1
    else:
        return int(n / 2)

s = int(input())

a = [0] * 1000000
a[0] = s

f = True
i = 1
ans = 0
while f:
    a[i] = next(a[i - 1])
    for j in range(i):
        if a[j] == a[i]:
            ans = i + 1
            f = False
            break
    i += 1

print(ans)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(10000000):

    if s%2 == 0:
        s //= 2

    else:
        s = s*3+1 

    if s in l:
        print(i+2)
        break

    l.append(s)

Submission status: Accepted

Solution code:
s = int(input())

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

a = s
a_set = set([s])
for i in range(2, 10000):
    a = f(a)
    if a in a_set:
        print(i)
        exit()

    # print(a)
    a_set.add(a)

Submission status: Accepted

Solution code:
# Problem B - Collatz Problem

# input process
s = int(input())
min_m = 1
number_queue = []
number_queue.append(s)

# search process
while True:
    min_m += 1
    if s%2==0:
        s = s / 2
    else:
        s = 3 * s + 1

    if s in number_queue:
        break

    number_queue.append(s)

# output process
print(min_m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
a = [s]
count = 0
if s == 4 or s == 2 or s == 1:
    print(4)
else:
    for _ in range(1000):
        if s % 2 == 0:
            s = s // 2
        else:
            s = 3*s+1
        count += 1
        a.append(s)
        if s == 4:
            break
    print(count+4)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())

a=[s]+[0]*1000000

if s%2==0:
    a[1]=s//2
else:
    a[1]=3*s+1
#print(a)
i=1
while a[i] not in a[:i]:
    if a[i]%2==1:
        a[i+1]=3*a[i]+1
    else:
        a[i+1]=a[i]//2
    i+=1

print(i+1)

Submission status: Accepted

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

for i in range(1, 1000001):
    if arr[i-1] % 2 == 0:
        fi = arr[i-1]//2
    else:
        fi = 3 * arr[i-1] + 1
    if fi in arr:
        print(i+1)
        exit()
    else:
        arr.append(fi)

Submission status: Accepted

Solution code:
s=int(input())

a=[s]+[0]*1000000

if s%2==0:
    a[1]=s//2
else:
    a[1]=3*s+1
#print(a)
i=1
while a[i] not in a[:i]:
    if a[i]%2==1:
        a[i+1]=3*a[i]+1
    else:
        a[i+1]=a[i]//2
    i+=1

print(i+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

from collections import defaultdict as dic
s = int(input())

flag = dic(int)
flag[s - 1] = 1
def f(n, i):
    if flag[n - 1] == 1:
        print(i)
        exit()
    else:
        flag[n - 1] = 1
        if n % 2 == 1:
            f(3 * n + 1, i + 1)
        else:
            f(int(n / 2), i + 1)
        

if s % 2 == 1:
    f(3 * s + 1, 2)
else:
    f(int(s / 2), 2)

Submission status: Accepted

Solution code:

k=int(input())
ans=0
s=set()
while(1):
    ans+=1
    if(k in s):
        print(ans)
        break
    s.add(k)
    if(k%2==0):k=k/2
    else: k=3*k+1

Submission status: Accepted

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

Submission status: Accepted

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

u = set()
for i in range(1000000):
    if s in u:
        print(i+1)
        exit()
    u.add(s)
    s = f(s)

Submission status: Accepted

Solution code:
import bisect

s = int(input())

a = [s]
n = s
for i in range(1000000):
    
    o = n
    n = 3 * o + 1
    if o % 2 == 0:
        n = o // 2
    # print(bisect.bisect_left(a,n),bisect.bisect_right(a,n),n)
    if bisect.bisect_left(a,n) == bisect.bisect_right(a,n):
        bisect.insort(a,n)
        # print(s)
    else:
        # print(i,n)
        print(i+2)
        exit()

Submission status: Accepted

Solution code:
S=int(input())
count=1
if S==1:
	print(4)
elif S==2:
	print(4)
else:
	while(1):
		if S==4:
			print(count+3)
			exit()
		elif S%2==0:
			count+=1
			S=S//2
		elif S%2==1:
			count+=1
			S=3*S+1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

a = [s]
cnt = 1
ans = -1
while True:
  a.append(f(a[cnt - 1]))
  if a.count(a[cnt]) > 1:
    ans = cnt + 1
    break
  cnt += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
    s = int(input())
    i = 1
    save_num = [s]
    while True:
        i += 1

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

        if s not in save_num:
            save_num.append(s)
        else:
            ans = i
            break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

n = int(input())

m = 2
a = [n, ]

while fun(n) not in a:
    n = fun(n)
    a.append(n)
    m += 1
print(m)

Submission status: Accepted

Solution code:
#abc116 b
n=int(input())
a=[]
a.append(n)
i=0
while True:
    if a[i]%2==0:
        x=int(a[i]/2)
        if x in a:
            ans=i+1
            break
        else:
            a.append(x)
    else:
        x=a[i]*3+1
        if x in a:
            ans=i+1
            break
        else:
            a.append(x)
    i+=1
print(ans+1)

Submission status: Accepted

Solution code:
s = int(input())

a = [s]
idx = 1
while True:
    idx += 1

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

print(idx)

Submission status: Accepted

Solution code:
S = int(input())
list = [S]
cnt = 2

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

while True:
	n = solve(S)
	if not (n in list):
		list.append(n)
		S = n
		cnt += 1
	else:
		print(cnt)
		exit()

Submission status: Accepted

Solution code:
s = int(input())

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

#print(A)
print(m)

Submission status: Accepted

Solution code:
def main(s: int):
    t = set([s])
    n = s
    i = 1

    while True:
        i += 1

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

        if n in t:
            print(i)
            return
        else:
            t.add(n)


if __name__ == "__main__":
    s = int(input())

    main(s)

Submission status: Accepted

Solution code:
s = int(input())

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

# パリティがあるのかな？
a = [s]
while(not f(a[-1]) in a):
    a.append(f(a[-1]))
else:
    print(len(a)+1)

Submission status: Accepted

Solution code:
def f(s):
	cnt = 0
	st = set()
	cnt += 1
	st.add(s)
  
	while True:
		cnt += 1
		if s % 2 == 0:
			tmp = s / 2
		else:
			tmp = 3 * s + 1
		if tmp in st:
			break
    
		st.add(tmp)
		s = tmp
	return cnt
  
s = int(input())
ans = f(s)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

a = set()
a.add(s)
index = 1
  
while True:
  index += 1
  s = f(s)
  if s not in a:
    a.add(s)
  else:
    break
    
print(index)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

lis = []

flag = True
while flag:
    lis.append(s)
    if s%2==0:
        s /= 2
    else:
        s = s*3 + 1
    s = int(s)

    if s in lis:
        print(len(lis)+1)
        flag = False

Submission status: Accepted

Solution code:
def f(n):
  if(n % 2 == 0):
    return n // 2
  else:
    return (3 * n) + 1
N = int(input())
 
test = set([N])
before = N
for i in range(1, 10**6 + 1):
  current = f(before)
  if(current in test):
    print(i+1)
    exit()
  before = current
  test.add(before)

Submission status: Accepted

Solution code:
#ABC116

s = int(input())

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

Submission status: Accepted

Solution code:
def func1(N):
    if N%2==0:
        return N//2
    else:
        return 3*N+1
s = int(input())
a_n = {}
for i in range(1, 1000001):
    if s in a_n:
        break
    else:
        a_n[s] = 1
    s = func1(s)
print(i)

Submission status: Accepted

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


s = int(input())
a = [s]

i=1
while i<100000:
    ai = calc_a(a[i-1])
    if ai in a:
        # print(a.index(ai))
        print(i+1)
        a.append(ai)
        break
    else:
        a.append(ai)
    i+=1
# print(a)

Submission status: Accepted

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

Submission status: Accepted

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

    S = int(input())
    collatz_set = {S}
    num = S
    ans = 1
    while True:
        num = collatz(num)
        ans += 1
        if num in collatz_set:
            return ans
        collatz_set.add(num)

print(b_collatz_problem())

Submission status: Accepted

Solution code:
from collections import defaultdict

s = int(input())

A = defaultdict(int)

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

print(ans)

Submission status: Accepted

Solution code:
s=int(input())
if s<3:
    print(4)
    exit()
for i in range(10**7+1):
    if s==4:
        print(i+4)
        exit()
    if s%2:
        s=3*s+1
    else:
        s//=2

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
i = 1

if s == 4:
    ans = 4
elif s == 2:
    ans = 4
elif s == 1:
    ans = 4
else:
    while s != 4:
        if s % 2 == 0:
            s = s // 2
        else:
            s = 3 * s + 1
        i += 1
    ans = i + 3

print(ans)

Submission status: Accepted

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


s = int(input())
sequences = [s]
while True:
    s = f(s)
    if s in sequences:
        print(len(sequences) + 1)
        break
    else:
        sequences.append(s)

Submission status: Accepted

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

a = list()
a.append(int(input()))
while True:
    x = F(a[-1])
    if x in a:
        print(len(a)+1)
        exit(0)
    a.append(x)

Submission status: Accepted

Solution code:
n=int(input())
st=set([n])
for i in range(2,10**7):
    if n%2==0:
        n//=2
    else:
        n=3*n+1
    if n in st:
        print(i)
        break
    st.add(n)

Submission status: Accepted

Solution code:
s = int(input())

def f(n):
  if n%2==0:
    return n//2
  else:
    return 3*n+1
  
r = [s]
n = s
c = 1
while True:
  n = f(n)
  c += 1
  if n in r:
    break
  r.append(n)
print(c)

Submission status: Accepted

Solution code:
s = int(input())

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

    if d.get(a[i]) is None:
        d[a[i]] = 1
    else:
        print(i+1)
        exit()

    i += 1

Submission status: Accepted

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

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
dp = [a]
li = [0 for i in range(10**6)]
li[a] +=1
for i in range(1,10**6):
    a = f(dp[i-1])
    dp.append(a)
    li[a]+=1
    if li[a]>=2:
        break
print(len(dp))

Submission status: Accepted

Solution code:
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


s = int(input())


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


S = {s}
# print(S)
for i in range(10**6):
    s = func(s)
    # print(s)
    if s in S:
        print(i+2)
        break
    else:
        S.add(s)
        # print(S)

Submission status: Accepted

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

s = int(input())

cap = ["no"] * 1000000
for i in range(1000000):

    if cap[s] == ["yes"]:
        print(i+1)
        break
    cap[s] = ["yes"]
    s = next(s)

Submission status: Accepted

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

Submission status: Accepted

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

    if x[s]==1:
        print(i+1)
        exit()
    else:
        x[s]=1

Submission status: Accepted

Solution code:
S=int(input())

kizon=[]
#print(kizon)
cnt=1

while (S not in kizon):
    kizon.append(S)
    if S%2==0:
        S=S//2
        #print(kizon)
        cnt+=1
    else:
        S=3*S+1
        cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
S=int(input())

kizon=[S]
#print(kizon)
cnt=1

while True:
    if kizon[-1]%2==0:
        kizon.append(kizon[-1]//2)
        #print(kizon)
        cnt+=1
    else:
        kizon.append(3*kizon[-1]+1)
        cnt+=1
    if len(kizon)!=len(set(kizon)):
        print(cnt)
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())


l =[s]

for i in range(1000):
  if l[i] % 2==0:
    l.append(int(l[i] /2))
  else:
    l.append(int(3* l[i] +1))
    
ans =0

for i in range(len(l)):
  if l[i] in l[:i]:
    ans = i
    break
print(ans + 1)

Submission status: Accepted

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

s = int(input())

li = [s]
i = 1
while True :
    a_i = f(li[i - 1])
    if a_i in li :
        print(i + 1)
        exit()
    li.append(a_i)
    i += 1

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

s=int(input())
seen=set()
a=s
seen.add(a)
idx=1

while True:
    if a%2==0:
        a//=2
    else:
        a=3*a+1
    idx+=1
    if a in seen:
        print(idx)
        exit()
    seen.add(a)

Submission status: Accepted

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

s_int = int(input().strip())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

pre = [s]

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

Submission status: Accepted

Solution code:
n=int(input())

memo = []

for i in range(1,1000000*3+1):
    if i == 1:
        memo.append(n)

    if memo[-1]%2 == 0:
        a = memo[-1]//2
    else:
        a = (memo[-1]*3)+1

    if a in memo:
        print(i+1)
        exit()
    else:
        memo.append(a)

Submission status: Accepted

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

Submission status: Accepted

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

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

make_a(1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())

from collections import defaultdict
d = defaultdict(int)
d[a] += 1


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

Submission status: Accepted

Solution code:
S = int(input())

_set = set()
_set.add(S)

_ = 10**7
cnt = 1
before_num = S

for n in range(_):
  cnt += 1
  _ = before_num
  
  if _%2==0:
    this_num = _/2
  else:
    this_num = 3*_+1
  _set.add(this_num)
  
  if len(_set) < cnt:
    ans = cnt
    break
  
  before_num = this_num
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

cnt = 1
while(True):
  if s == 1 or s == 2 or s == 4:
    ans = cnt+3
    break
  s = f(s)
  cnt += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(i+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#116_B
def f(n):
    if n%2==0:
        return n//2
    else:
        return 3*n+1
    
s=int(input())
A=[0,s]
for i in range(2,10**7+1):
    x=f(A[i-1])
    if x in A:
        print(i)
        exit()
    A.append(x)

Submission status: Accepted

Solution code:
a = int(input())

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

S = set()
S.add(a)
c = 2
while True:
  a = f(a)
  if a in S:
    break
  else:
    S.add(a)  
  c += 1

print(c)

Submission status: Accepted

Solution code:
import sys

s = int(input())

sequence = [s] * 1000000

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

    for j in range(i):
        if sequence[i] == sequence[j]:
            print(i + 1)
            sys.exit()
    i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

if s==1:
    print(4)
elif s==2:
    print(4)
else:
    no=1
    cnt=0
    if s==4:
        cnt+=1
    for i in range(1000000):
        no+=1
        if s%2==0:
            s=int(s/2)
        else:
            s=3*s+1
        if s==4:
            cnt+=1
        if cnt==2:
            break
    print(no)

Submission status: Accepted

Solution code:
s = int(input())

def f(A):
    if A%2 == 0:
        return A//2
    else:
        return 3*A+1
    
a = []
a.append(s)
for i in range(1, 10000001):
    a.append(f(a[i-1]))
    if a.count(a[i]) == 2:
        print(i+1)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

d = dict()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
#S=[-1]*200
#S[0]=s
S=[];A=[];f=-1
if s==1:
  print(4)
elif s==2:
  print(4)
elif s==3:
  print(9)
elif s==4:
  print(4)
else:
  S.append(s)
  i=1;p=-1
  while p!=4:
    if S[i-1]%2==0:
      S.append(S[i-1]//2)
      #print(S[i])
    else:
      S.append(S[i-1]*3+1)
      #print(S[i])
    p=S[-1]
    i=i+1
  #print(i,S)
  for i in range(len(S)-1):
    for j in range(i+1,len(S)):
      if S[i]==S[j]:
        f=1
        print(j)
        break
  if f==-1:
    print(len(S)+3)

Submission status: Accepted

Solution code:
s = int(input())


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


a = [0, s]
cnt = 1
while True:
    res = func(a[cnt])
    cnt += 1

    if res in a:
        break

    a.append(res)

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
record = [s]
count = 1

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

Submission status: Accepted

Solution code:
s=int(input())
a=[s]
i=0
b=0
while b not in a:
    if a[i]%2==0:
        b=a[i]//2
    else:
        b=3*a[i]+1
    a.append(b)
    i+=1
    if a[i]%2==0:
        b=a[i]//2
    else:
        b=3*a[i]+1
print(len(a)+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 = []
for i in range(1000000):
    if s in a:
        print(i+1)
        break
    else:
        a.append(s)
        s = f(s)

Submission status: Accepted

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

for i in range(1000000):
    if a[i-3]==a[i]:
        print(i+1)
        break

Submission status: Accepted

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

Submission status: Accepted

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

s=int(input())
a=[s]
for i in range(2,10**10):
    s=f(s)
    if s in a:
        print(i)
        exit()
    a.append(s)

Submission status: Accepted

Solution code:
s = int(input())
nums = {s}
leng= 1
count = 1
while True:
    count += 1
    if s%2 == 0:
        s /= 2
    else:
        s = s*3+1
    nums.add(s)
    if len(nums) == leng:
        print(count)
        quit()
    else:
        leng = len(nums)

Submission status: Accepted

Solution code:
def f(n):
    if n %2 == 0:return n//2
    else: return 3*n+1
s = int(input())
nums = [s] + [0]*10**6
for i in range(1000000):
    if f(nums[i]) in nums:
        print(i+2)
        break
    else:
        nums[i+1] = f(nums[i])

Submission status: Accepted

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