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:
# coding: utf-8

n = int(input())

i = 1
while n > 0:
    if n == 4 or n == 2 or n == 1:
        break
    i += 1
    if n % 2 == 0:
        n = n / 2
    else:
        n = n*3+1

print(i+3)

Submission status: Accepted

Solution code:
def f(a, n, i):
    if n % 2 == 0:
        x = n//2
    else:
        x = 3*n+1

    if x in a:
        print(i)
        return
    else:
        a.append(x)
        return f(a, x, i+1)


s = int(input())
a = [s]
f(a, s, 2)

Submission status: Accepted

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

s = int(input())
l = []
l.append(s)
L = 1
for i in range(1000000):

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

    l.append(s)

    if L == len(set(l)):
        print(i+2)
        exit()
    else:
        L = len(set(l))

Submission status: Accepted

Solution code:
def calc_a(i, s):
    if i == 1:
        return s
    else:
        return f(calc_a(i-1, s))


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


if __name__ == '__main__':
    S = int(input())

    an_list = []

    for m in range(1, 1000001):
        am = calc_a(m, S)
        if am in an_list:
            break
        else:
            an_list.append(am)

    answer = m
    print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

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

p = set()
p.add(s)

count = 1
n = s
while True:
  count += 1
  n = f(n)
  if n in p:
    print(count)
    break
  p.add(n)

Submission status: Accepted

Solution code:
S=int(input())
count=1
for i in range(1000000):
    if S==8:
        print(count+4)
        break
    elif S==4:
        print(count+3)
        break
    elif S==2:
        print(count+3)
        break
    elif S==1:
        print(count+3)
        break
    elif S%2==0:
        S//=2
        count+=1
    else:
        S=S*3+1
        count+=1

Submission status: Accepted

Solution code:
s = int(input())

a = [s]
for n in range(2, 1000001):
    if a[-1] % 2 == 0:
        a.append(int(a[-1]/2))
    else:
        a.append(3*a[-1]+1)

    try:
        a.index(a[-1], 0, -1)
        print(n)
        break
    except ValueError:
        continue

Submission status: Accepted

Solution code:
s = int(input())


a = [s]
for n in range(2, 1000001):
    if a[-1] % 2 == 0:
        a.append(int(a[-1]/2))
    else:
        a.append(3*a[-1]+1)

    try:
        a.index(a[-1], 0, -1)
        print(n)
        break
    except ValueError:
        continue

Submission status: Accepted

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

Submission status: Accepted

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

print(i + 1)

Submission status: Accepted

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

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

while(1):
    a.append(collatz(a[-1]))
    if a[-1] in a[:-1]:
        break
    n+=1

print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
if n <= 2:
    print(4)
    exit()

ls = [n]
m = 0

for i in range(1, 120):
    n = int(n/2) if int(n%2) == 0 else 3*n+1
    ls.append(n)
    if n == 4:
        break

print(ls.index(4)+4)

Submission status: Accepted

Solution code:
n = int(input())
ls = [n]
m = 0

for i in range(1, 1000001):
    if int(n%2) == 0:
        n = int(n/2)
    else:
        n = 3*n+1

    if n in ls:
        m = i+1  # 答えは次のインデックス
        break
    ls.append(n)

print(m)

Submission status: Accepted

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

num_list = [s]
unique_set = set(num_list)
record_list = []
n = 0

for m in range(1000000):
    n += 1
    before = num_list[m]
    if before % 2 == 0:
        after = int(before / 2)
        num_list.append(after)
    else:
        after = int(3 * before + 1)
        num_list.append(after)
    if after in unique_set:
        print(n + 1)
        break
    unique_set.add(after)

Submission status: Accepted

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

Submission status: Accepted

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


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

while True:
    a.append(fn(a[len(a) - 1]))
    if len(a) != len(set(a)):
        print(len(a))
        break

Submission status: Accepted

Solution code:
def is_unique(list):
    return len(list) == len(set(list))


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


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

while True:
    a.append(fn(a[len(a) - 1]))
    if not is_unique(a):
        print(len(a))
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

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

Submission status: Accepted

Solution code:
s = int(input())
A = [s]
m = 100000
i = 0
while i <= m:

    if A[i] % 2 == 0:
        s = s/2
    else:
        s = 3*s+1
    
    i += 1
    s = int(s)
    if s in A:
        print(i+1)
        exit()
    else:
        A.append(s)

Submission status: Accepted

Solution code:
s = int(input())

i = 1
m = 1000000
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:
s = int(input())
l = [s]
num = s
while True:
    if num % 2 == 0:
        res = num / 2
    else:
        res = num * 3 +1
    l.append(res)
    if len(l) != len(set(l)):
        break
    else:
        num = res
print(len(l))

Submission status: Accepted

Solution code:
s = int(input())
count = 1
M = [0]*s
M[s-1] = 1
while max(M) < 2:
    if s % 2 == 0:
        s = int(s / 2)
        M[s-1] = M[s-1]+1
    else:
        s = 3 * s + 1
        M.extend([0]*s)
        M[s-1] = M[s-1] + 1
    count = count + 1
print(count)

Submission status: Accepted

Solution code:
s = int(input())

tmp = {}

tmp[s] = 1
i = 1
while True:
    i += 1
    if s % 2 == 0:
        s = int(s/2)
    else:
        s = int(3*s+1)
    if s in tmp:
        print(i)
        exit()
    tmp[s] = 1

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A.append(s)
a = s
for i in range(10000):
    if a % 2 == 0:
        a = int(a/2)
        A.append(a)
    else:
        a = 3*a+1
        A.append(a)
    if A.count(a) == 2:
        print(len(A))
        break

Submission status: Accepted

Solution code:
s = int(input())

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

history = {s}
a = s
i = 1
while True:
    i += 1
    a = f(a)
    if a in history:
        print(i)
        break
    history.add(a)

Submission status: Accepted

Solution code:
s = int(input())

a = []
a.append(s)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

while True:
    s = f1(s)
    if s in a:
        print(len(a)+1)
        break
    else:
        a.append(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

alist = []
alist.append(s)
for i in range(1000000):
    if s % 2 == 0:
        a = int(s / 2)
    else:
        a = 3 * s + 1
    s = a
    alist.append(a)
for num in alist:
    if alist.count(num) > 1:
        index = alist.index(num)
        alist.pop(index)
        find = alist.index(num)
        print(find + 2)
        break
    else:
        continue

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

for i in range(1000000):
    an = f(a[i])
    if an in a:
        m = i + 2
        break
    else:
        a.append(an)

print(m)

Submission status: Accepted

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

ans = 1

while True:
    if s == 1 or s == 2 or s == 4:
        ans += 3
        print (ans)
        sys.exit()
    else:
        if s%2 == 0: #偶数
            s = s//2
        else:
            s = 3 * s + 1
        ans += 1

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
s = int(input())
d = defaultdict(int)
d[s] = 1
index = 1
while(1):
  if s % 2 == 0:
    s = s // 2
  else:
    s = 3 * s + 1
  index += 1
  if d[s] == 1:
    break
  d[s] = 1
print(index)

Submission status: Accepted

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

s = int(input())
a = [0] * 1
a[0] = s
ans = 1

for i in a:
    b = f(i)
    ans += 1
    if b in a:
        break
    a.append(b)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())


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


i, tmp = 1, set()
while s not in tmp:
    tmp.add(s)
    s = f(s)
    i += 1
print(i)

Submission status: Accepted

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

sum = 0
flag = 0
for i in range(100000):
    if a[i] % 2 == 0:
        a[i+1] = a[i] // 2
    else:
        a[i+1] = 3 * a[i] + 1
    sum += 1
    if a[i] in a[:i]:
        print(sum)
        exit()

Submission status: Accepted

Solution code:
s=int(input())
a=[]
a.append(s)
cnt=2
t=0

while cnt<1000000:
    if a[cnt-2]%2==0:
        a.append(int(a[cnt-2]/2))
    else:
        a.append(int(3*a[cnt-2]+1))
    cnt+=1
    
    if a[cnt-2]==4:
        t+=1
        if t==2:
            b=len(a)
            break


for i in range(len(a)):
    if 2<=a.count(a[i]):
        Key=a[i]
        break
    
a.remove(Key)

print(min(a.index(Key)+2,b))

Submission status: Accepted

Solution code:
s = int(input())

a = []
a.append(s)

i = 0
while True:
    if a[i] % 2 == 0:
        tmp = a[i]/2
    else:
        tmp = a[i]*3+1

    if tmp in a:
        print(i+2)
        break
    else:
        a.append(tmp)
        i += 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]=3*a[i-1]+1
for i in range(1000000):
  if a[i] in a[:i]:
    print(i+1)
    break

Submission status: Accepted

Solution code:
s = int(input())

def func(x):
    if x % 2 == 0:
        return int(x/2)

    return 3*x + 1

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

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

print(len(a)+1)

Submission status: Accepted

Solution code:
from collections import defaultdict
s = int(input())
mem = defaultdict(int)

def f(n):
    if n % 2 == 0:
        return n//2
    else:
        return 3*n + 1
m = 1
while 1:
    if mem[s] == 1:
        print(m)
        exit()
    else:
        mem[s] = 1
        s = f(s)
        m += 1

Submission status: Accepted

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

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

print(len(l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(s: int):
    res = [0] * 1000001
    a = s
    i = 1
    while True:
        if res[a] == 1:
            break
        res[a] = 1
        if a % 2 == 0:
            a = a // 2
        else:
            a = 3 * a + 1
        i += 1
    return i


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
    result = solve(s)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

if s == 1:
    print(4)
elif s == 2:
    print(4)
else:
    while True:

        if s == 4:
            break
        else: 
            s = f(s)
            count += 1

    print(count + 3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = int(input())
counter = 0
ans = 1
if S <= 2 or S == 4:
    print('4')
    exit()
else:
    while True:
        if S % 2 == 0:
            S = S // 2
            ans += 1
            if S == 4:
                counter += 1
                if counter == 2:
                    print(ans)
                    exit()
        else:
            S = 3 * S + 1
            ans += 1
            if S == 4:
                counter += 1
                if counter == 2:
                    print(ans)
                    exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = [0 for i in range(3 * 1000000 + 1)]

s = int(input().rstrip())

a[s] = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

s = int(input())
ansFlg = True

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

ans = 1
while ansFlg:
    if s == 4:
        ans += 3
        break
    s = kansu(s)
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
s = int(input())


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

print(len(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
fx = lambda x: int(x/2) if x%2==0 else 3*x + 1
ans = [int(input())]
counter = 1

while True:
    new_x = fx(ans[-1])
    counter += 1
    if (new_x in ans) :
        break
    ans.append(new_x)

print(counter)

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)
a = int(input())
d[a] += 1

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = int(input())

a = S
indx = 1

nums = set()
nums.add(a)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

def Collatz(a):
    if a % 2:
        return 3 * a + 1
    else:
        return a // 2

x = set()
while s not in x:
    x.add(s)
    s = Collatz(s)

print(len(x)+1)

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
a = [n]
ans = 1
while True: 
    n = ( n//2 if n % 2 == 0 else 3 * n + 1)
    if n in a:
        break
    a.append(n)
    ans+=1
print(ans+1)

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
a = [n]
ans = 1
while True: 
    if n%2 == 0:
        n = n // 2
    else:
        n = 3 * n + 1
    if n in a:
        break
    a.append(n)
    ans+=1
print(ans+1)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
s = int(input())
X = [s]
m = 1
while True:
    m += 1
    if s % 2 == 0:
        s = s / 2
    else:
        s = 3 * s + 1
    
    Y = [s]
    if len(set(X) & set(Y)) == 1:
        break
    X.append(s)

print(m)

Submission status: Accepted

Solution code:
s = int(input())

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

    if a.count(s) == 1:
        print(ans)
        exit()
    else:
        a.append(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

if s == 1 or s == 2:
    print(4)
else:
    for i in range(1000000):
        if s == 4:
            print(i + 4)
            break

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

Submission status: Accepted

Solution code:
import sys

s = int(input())
a = [s]
ans = 0
for i in range(1,10**6+10):
    if a[i-1] % 2 == 0:
        a.append(int(a[i-1]/2))
    else:
        a.append(3*a[i-1]+1)
    for j in range(len(a)):
        if a.count(a[i]) == 2:
            ans = i+1
            print(ans)
            sys.exit()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

while True:
    i += 1
    if a % 2 == 0:
        a //= 2
    else:
        a = 3*a + 1
    
    if flag[a] == 1:
        break
    else:
        flag[a] = 1

print (i)

Submission status: Accepted

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

while True:
	v = L[-1]
	nv = [v // 2, 3 * v + 1][not (0 == v % 2)]
	if nv in L:
		print(len(L) + 1)
		break
	L.append(nv)

Submission status: Accepted

Solution code:
# ABC116B - Collatz Problem
s = int(input())
lst = []
count = 1

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

print(count)

Submission status: Accepted

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

        for j in range(len(a)-1):
            if a[-1] == a[j]:
                ans = len(a)
                break
    else:
        print(ans)
        break

Submission status: Accepted

Solution code:
s = int(input())


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


def insert(sslist, x):
    if not sslist:
        sslist.append(x)
        return False

    start = 0
    end = len(sslist)

    while start < end - 1:
        y = sslist[(start + end) // 2]
        if x == y:
            return True
        if x < y:
            end = (start + end) // 2
        if x > y:
            start = (start + end) // 2

    if sslist[start] == x:
        return True
    if sslist[start] < x:
        sslist.insert(start + 1, x)
        return False
    if sslist[start] > x:
        sslist.insert(start, x)
        return False


slist = []
ss = s
for i in range(1, 2**32):
    ret = insert(slist, ss)
    ss = f(ss)
    if ret:
        print(i)
        break

Submission status: Accepted

Solution code:
s = int(input())


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


sset = {s}
ss = s
for i in range(2, 2**32):
    prev_len = len(sset)
    ss = f(ss)
    sset.add(ss)
    next_len = len(sset)
    if prev_len == next_len:
        print(i)
        break

Submission status: Accepted

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

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

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

    if s not in a:
        a.add(s)

    else:
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input())
st = set([s])

ans = -1
for i in range(2, 1000001):
    s = int(f(s))
    if s in st:
        ans = i
        break
    st.add(s)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
dic=set()
dic|={n}
i=1
while True:
  if n%2==0:
    n=n//2
  else:
    n=3*n+1
  if n in dic:
    print(i+1)
    break
  else:
    dic|={n}
    i+=1

Submission status: Accepted

Solution code:
s = int(input())

used = set()
used |= {s}
count = 1

while True:
    if s % 2 == 0: s//=2
    else:s=3*s+1
    if s in used:
        print(count+1)
        break
    else:
        used |= {s}
        count += 1

Submission status: Accepted

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

if s%2==0:
  a.append(int(s/2))
else:
  a.append(3*s+1)

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

print(len(a))

Submission status: Accepted

Solution code:
s = int(input())

used = set()
used |= {s}
count = 1

while True:
    if s % 2 == 0: s//=2
    else:s=3*s+1
    if s in used:
        print(count+1)
        break
    else:
        used |= {s}
        count += 1

Submission status: Accepted

Solution code:
s = int(input())
def f(n):
  if n % 2 == 0:
    return n / 2
  else:
    return 3 * n + 1
count = 0
i = 0
j = 0
a = 0
list1 = [1, 2, 4]
while True:
  i += 1
  if i == 1:
    a = s
  else:
  	a = f(a)
  if a in list1:
    j = a
    list1 = []
  if a == j:
    count += 1
  if count == 2:
    print(i)
    break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())

def f(n):
    if n % 2 == 0:
        return n/2
    else:
        return 3 * n + 1
i = 0
li = [a]
while True:
    tmp = f(li[i])
    i += 1
    if tmp in li:
        print(i + 1)
        break
    else:
        li.append(tmp)

Submission status: Accepted

Solution code:
s = int(input())

setNum = set()
n = s
for i in range(1000000+1):
	if n in setNum:
		print(i+1)
		exit()
	
	#print(i,n)
	setNum.add(n)
	if n % 2 == 0:
		n = int(n/2)
	else:
		n =3*n+1

Submission status: Accepted

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