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

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

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

print(i + 1)

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

Submission status: Accepted

Solution code:


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

s = int(input())


memo = set()
memo.add(s)
for i in range(2, 1000000):
    tmp = f(s)
    if tmp in memo:
        print(i)
        break
    memo.add(tmp)
    s = tmp

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    a = int(input())
    s = set()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a_set = set([s])

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

for i in range(2, 1000001):
    a[i] = func(a[i - 1])
    a_set.add(a[i])
    if len(a_set) < i:
        print(i)
        exit()

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:
def func_odd(n):
    return int(3 * n + 1)


def func_even(n):
    return int(n / 2)


def is_finished(array):
    before_len = len(array)
    after_len = len(list(set(array)))
    return before_len != after_len


def main(s):
    array = [s]
    index = 0
    while True:
        if array[index] % 2 == 0:
            array.append(func_even(array[index]))
        else:
            array.append(func_odd(array[index]))
        if is_finished(array):
            break
        index += 1
    print(index + 2)


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

Submission status: Accepted

Solution code:
a = int(input())

def func_1(x):
    return x//2

def func_2(x):
    return 3*x+1

dp = [0] * 1000000

c = 1
dp[a] = 1
while True:
    c += 1
    if a % 2 == 0:
        a = func_1(a)
    else:
        a = func_2(a)

    if dp[a] > 0:
        print(c)
        break
    else:
        dp[a] = 1

Submission status: Accepted

Solution code:
# B - Collatz Problem


def main():
    s1 = input()
    ret = solve(s1)
    print(ret)


def solve(s1):
    s = int(s1)
    a = []
    m = 0
    for i in range(1000000):
        if (i == 0):
            w = s
        elif (a[i-1] % 2 == 1):
            w = 3 * a[i-1] + 1
        else:
            w = a[i-1] / 2
        if (w in a):
            return i+1
        a.append(w)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
s =int(input())
i=0
ans=[]
while i==0:
    
    if s in ans:
        i +=1
    ans.append(s) 
    if s%2 ==0:
        s = s/2
    elif s%2 ==1:
        s =3*s+1
  
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

numbers = [s]
old_num = s
while True:
    new_num = f(old_num)
    old_num = new_num
    if new_num in numbers:
        numbers.append(new_num)
        break
    numbers.append(new_num)

min_m = max(numbers)
for n in range(len(numbers)):
    for m in range(n+1, len(numbers)):
        if numbers[m] == numbers[n]:
            min_m = min(min_m, m)

#print(numbers)
print(min_m+1)

Submission status: Accepted

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

Submission status: Accepted

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

if x == 1 or x == 2:
    i = 4
else:
    while(x != 1):
        i += 1
        x = collatz(x)
    
print(i)

Submission status: Accepted

Solution code:
a = int(input())
cnt = 1
if a == 1 or a == 2:
  print('4')
else:
  while a >=3:
    if a % 2 == 0 and a != 4:
      a = a//2 
      cnt += 1
    elif a % 2 != 0:
      a = 3*a + 1
      cnt += 1
    elif a == 4:
      break
  print(cnt+3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
num = int(input())

def function(a):
    if a%2 == 0:
        return math.floor(a/2)
    else:
        return 3*a + 1

list = [num]
while True:
    if function(list[-1]) in list:
        print(len(list)+1)
        break
    else:
        list.append(function(list[-1]))

Submission status: Accepted

Solution code:
s = int(input())

a = s
i = 1
aa=[s]
while i < 100000:
    i+=1
    if a%2 ==0:
        a = int(a / 2)
    else:
        a = int(a * 3 + 1)
    if aa.count(a)>0:
        print(i)
        break
    else:
        aa.append(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())

def f(x):
    if x%2==0:
        return x/2
    else:
        return 3*x+1
list_a=[s,f(s)]
i=1
while i>0:
    if f(list_a[-1]) in list_a:
        print(len(list_a)+1)
        i=-1
    else:
        list_a.append(f(list_a[-1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

s = int(input())

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

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

Submission status: Accepted

Solution code:
s = int(input())

c = [False for i in range(1000001)]

n = 1
an = s
while True:
    if c[an]:
        print(n)
        break
    c[an] = True

    if an & 1 == 0:
        an >>= 1
    else:
        an = 3 * an + 1
    n += 1

Submission status: Accepted

Solution code:
a= int(input())
cand = [a]
index = 0
while True:
    if cand[index] % 2 ==0:
        last= int(cand[index]/2)
    else:
        last= int(cand[index]*3+1)
        
    if last in cand:
        cand.append(last)
        print(index+2) #リストの最後はindex+1番目で、そこに新たに一つ加えるため
        break
    else:
        cand.append(last)
        index +=1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = int(input())

dp = [s]

i=2
a_1=s
while(True):
    if a_1 % 2==0:
        index = a_1 /2
    else:
        index = 3 * a_1 + 1
    if int(index) in dp:
        break
    else:
        dp.append(int(index))
        a_1 = int(index)
        i+=1

print(i)

Submission status: Accepted

Solution code:
init = int(input())

m = 1000000


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


ls = [init]
s = init
flag = 1
while 1:
    ls.append(f(s))
    s = f(s)
    # print(s)
    if s == 1 and flag == 1:
        flag = 0
    elif s == 1 and flag == 0:
        break

if init == 2:
    print(4)
elif init == 1:
    print(4)
else:
    # print(ls)
    print(len(ls)-2)

Submission status: Accepted

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

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

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]*1000001
get_ans = False
ans = 0
for i in range(2,1000001):
    #aiを保存しながら進む&見つかったら進まなくてよい
    if i==2:
        a[1] = s
        a[2] = f(s)
        if a[1]==a[2]:
            ans = 2
            break
    else:
        a[i]=f(a[i-1])
        for j in range(1,i):
            if a[i]==a[j]:
                ans = i
                get_ans = True
                break
    if get_ans:
        break
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())
vals = []
vals += [s]
n=1
while True:
    if vals[n-1]%2==0:
        val = vals[n-1]/2
    else:
        val = vals[n-1]*3+1
        
    if val in vals:
        print(len(vals)+1)
        break
    else:
        vals += [val]
        n += 1

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    a = int(input())

    s = set()
    s.add(a)
    for ans in count(2):
        if a % 2 == 0:
            a //= 2
        else:
            a = 3 * a + 1
        if a in s:
            print(ans)
            break

        s.add(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = int(input())
cache = {}
cache[S] = 1
for i in range(1000000):
  if S % 2 == 0:
    S = S // 2
  else:
    S = 3 * S + 1
  if cache.get(S):
    print(i + 2)
    exit()
  cache[S] = 1

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
s = int(input())

dict = {}
dict[s] = 1

last_a = s
f = 0
n = 2
ans = 0
while True:
    if last_a % 2 == 0:
        last_a = last_a // 2
    else:
        last_a = 3 * last_a + 1

    if last_a not in dict.keys():
        dict[last_a] = n
    else:
        ans = n
        break
    n += 1

print(ans)

Submission status: Accepted

Solution code:
#n = map(int,input().split())
mlist = list(map(int,input().split()))

i=0
while(True):
    if mlist[i] % 2 == 0:
        mlist.append(mlist[i]/2)
    else:
        mlist.append(3*mlist[i]+1)
    
    breakFlg = False
    for num in range(0,i):
        if int(mlist[num])==int(mlist[i]):
            if num!=i:
                breakFlg = True
    i=i+1
    if(breakFlg):
        break
print(i)

Submission status: Accepted

Solution code:
s = int(input())
m = 1000000
a = set()
a.add(s)
ans = 0
for i in range(1,m+5):
    tmp = 0
    if s%2==0:
        tmp = s//2
    else:
        tmp = 3*s+1
    if tmp in a:
        ans = i+1
        break
    s = tmp
    a.add(s)
print(ans)

Submission status: Accepted

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

s = int(input())

an = set()
an.add(s)

c = 1
ai = s
while True:
    c += 1
    ai = f(ai)
    let = an.isdisjoint({ai})
    if let:
        an.add(ai)
    else:
        break
print(c)

Submission status: Accepted

Solution code:
# coding: utf-8


def is_unique(seq):
    return len(seq) == len(set(seq))


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


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

    while (len(li) <= 1000000):
        li.append(func_f(s))
        s = li[-1]
        if not is_unique(li):
            print(len(li))
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

print(i)

Submission status: Accepted

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

print(len(s_l)+1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s=int(input())
cnt = 1
while not(s==4 or s==2 or s==1):
    cnt += 1
    if s%2==1:
        s = 3*s+1
    else:
        s=s/2
print(cnt+3)

Submission status: Accepted

Solution code:
s=int(input())

chk = set([s])
def f(a):
  if a%2 == 0:
    return a/2
  else:
    return 3*a+1

for i in range(2,1000000):
  s = f(s)
  if s in chk:
    print(i)
    break
  chk.add(s)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


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


s = d_in()
searched = [s]
idx = 1
while True:
    s = func(s)
    idx += 1
    if s in searched:
        print(idx)
        exit()
    else:
        searched.append(s)

Submission status: Accepted

Solution code:
s=int(input())

co=1
while co>0 :
    if s==1 or s==2 or s==4 :
        print(co+3)
        break
    else :
        if s%2==1 :
            s=3*s+1
        else :
            s=s//2
        co+=1

Submission status: Accepted

Solution code:
def is_unique(seq):
    return len(seq) == len(set(seq))
  
s = int(input())
lists=[]
lists.append(s)
for x in range(1,1000000):
  if lists[x-1] % 2 == 0:
    lists.append(int(lists[x-1]/2))
  else:
    lists.append(int(lists[x-1]*3+1))
  if not is_unique(lists):
    print(x+1)
    break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

S = int(input())

a = list()
a.append(0)
a.append(S)

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

Submission status: Accepted

Solution code:
s = int(input())

def myfnc(input):

    if input % 2 == 0:
        return input // 2
    else:
        return (3 * input) + 1

answer = list()
answer.append(s)
for i in range(2, 1000000):
    ret = myfnc(answer[-1])

    if ret in answer:
        print(i)
        exit(0)
    else:
        answer.append(ret)

Submission status: Accepted

Solution code:
s = int(input())

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

cache = []
def calc(s):
    cache.append(s)
    if cache.count(s) > 1:
        print(len(cache))
        return
    calc(ehu(s))

calc(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a1=int(input())
L=[a1,]
ans=0

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


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
dict_ = {}
def collatz(s):
    if s in dict_.keys():
        dict_[s] += 1
        return sum(dict_.values())
    else:
        dict_[s] = 1
        return collatz(s/2) if s%2==0 else collatz(3*s+1)

s = int(input())
print(collatz(s))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

tmp_a = s
next_a = s
ans = 0
for i in range(100000):
    next_a = collatz(tmp_a)
    if next_a in outputs:
        ans = i + 2
        break
    else:
        outputs.add(next_a)
        tmp_a = next_a

print(ans)

Submission status: Accepted

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


from sys import stdin


############################################

import numpy as np
# read data for n sequences.
n = stdin.readline().split()
a = int(n[0])

out = np.zeros(1000000)
out[0] = int(a)

for i,x in enumerate(out[:-1]):
    # do func.
    if a%2 == 0:
        a/=2
    else:
        a=a*3+1
    # check if m exists   
    if a in out:
        answer = i+2
        break
    out[i+1]=int(a)
    
print(int(answer))

Submission status: Accepted

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



s = int(input())
stack = [s]
index = 1
while True:
    s = collatz(s)
    index += 1
    if s in stack:
        print(index)
        break
    stack.append(s)

Submission status: Accepted

Solution code:
s = int(input())
numset = {s}
ans = 1
while 1:
    if ans != len(numset):
        break
    if s%2 == 0:
        s = s//2
        numset.add(s)
    else:
        s = s*3 + 1
        numset.add(s)
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python

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


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

    res = set()

    m = 1

    while True:
        if s in res:
            print(m)
            return
        res.add(s)
        m += 1
        s = f(s)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def f(n):
    return 3 * n + 1 if n % 2 else n / 2
a = int(input())
li = set([a])
ans = 1
while True:
    ans += 1
    a = f(a)
    if a in li:
        break
    else:
        li.add(a)

print(ans)

Submission status: Accepted

Solution code:
a = int(input())
time = 0
ch_1 = 2
ch_2 = 2
ch_4 = 2
while True:
    time += 1
    if a == 1:
        ch_1 -= 1
        if ch_1 == 0:
            break
    if a == 2:
        ch_2 -= 1
        if ch_2 == 0:
            break
    if a == 4:
        ch_4 -= 1
        if ch_4 == 0:
            break
    if a % 2 == 0:
        a = a / 2
    else:
        a = a * 3 + 1

print(int(time))

Submission status: Accepted

Solution code:
import math
import sys
from operator import itemgetter

# N, K = map(int, input().split())
# h = list(map(int, input().split()))
# S = [input() for _ in range(H)]
# X = [[0 for j in range(100)] for i in range(200)]


### input
a = list(range(0))
a.append(int(input()))

## solve
ans = 0
while(ans == 0):
	p = 0
	if (a[-1] == 1):
		p = 4
	elif (a[-1] % 2 == 0):
		p = a[-1]//2
	else:
		p = a[-1]*3+1
	
	if (p in a):
		ans = len(a)+1
	else:
		a.append(p)

print(ans)

Submission status: Accepted

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

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

while True:
    a.append(f(a[i-1]))
    i += 1

    if a[-1] in a[:-1]:
        break

print(i)

Submission status: Accepted

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

s = int(input())
a = [0]
for i in range(1, 1000001):
    if i == 1:
        a.append(s)
    else:
        a.append(f(a[i-1]))
        if a.count(a[-1]) == 2:
            print(i)
            break

Submission status: Accepted

Solution code:
s =  int(input()) # 整数
A = []
# print(s)
# print(A)

an = s
n=1
while(True):
    A.append(an)
    if an%2==0:
        # print(A)
        an=int(an/2)
    else:
        an=an*3+1
    n+=1

    if an in A:
        break

print(n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

while not s in _:
    _.add(s)
    if 0 == s % 2:
        s = int(s / 2)
    else:
        s = 3 * s + 1
print(len(_) + 1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

if __name__=='__main__':
  S = int(input())
  f = lambda x: int(x/2) if x%2==0 else int(3*x+1)
  li = [S]
  m = 1
  curr = S
  while True:
    curr = f(curr)
    m += 1
    if curr in li:
      break
    li += [curr]
  print(m)

Submission status: Accepted

Solution code:
s = int(input())

t = [s]
u = 0
v = 0

while u == 0:
    v += 1
    if s % 2 == 0:
        s = s//2
        t.append(s)
    else:
        s = 3*s + 1
        t.append(s)
    for i in range(0,v):
        if s == t[i]:
            u += 1

print(v+1)

Submission status: Accepted

Solution code:
lis=[0 for i in range(1000000)]
s=int(input())
k=1
lis[s]+=1
while True:
    k+=1
    if s%2==0:
        s=s//2
    else:
        s=3*s+1
    if lis[s]==1:
        break
    lis[s]=lis[s]+1

print(k)

Submission status: Accepted

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

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

print(len(arr))

Submission status: Accepted

Solution code:
MAX_RANGE = 99999999999

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

def main():
    s = float(input().strip())

    def a(i):
        if i < 1:
            raise ValueError
        elif i == 1:
            return s
        else:
            return f(a(i-1))

    a_s = [None, s]
    for i in range(2, MAX_RANGE):  # 1 .. MAX_RANGE-1
        value = a(i)
        for j in range(1, i):  # 1 .. i-1
            if a_s[j] == value:
                print(i)
                return
        a_s.append(value)

    # print(a_s)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

a = s
arr = []
count = 1


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

print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# Luis Yoichi Morales January 2019

a = int( raw_input())

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

    for j in range( len(my_list) ):
        if a == my_list[j]:
            print i+1
            exit()
    my_list.append( a )

Submission status: Accepted

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

Submission status: Accepted

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

def ans1(s):
    a = list()
    a.append(s)
    a.append(f(s))

    while True:
        x = f(a[-1])
        if x in a:
            return len(a) + 1
        else:
            a.append(x)

def ans2(s):
    if s == 1:
        return 4
    
    if s == 2:
        return 4
    
    n = s
    i = 0
    while n != 4:
        n = f(n)
        i += 1
    return i + 4

s = int(input())
print(ans2(s))

Submission status: Accepted

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

def ans1(s):
    a = list()
    a.append(s)
    a.append(f(s))

    while True:
        x = f(a[-1])
        if x in a:
            return len(a) + 1
        else:
            a.append(x)

s = int(input())
print(ans1(s))

Submission status: Accepted

Solution code:
#ABC116B-CollatzProblem.py

s = int(input())
i = 0
A = []
m = 0

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

A.append(s)

while m == 0:
    A.append(f(A[i]))
    if len(A) != len(set(A)):
        m = i+2
    i += 1

print(m)

Submission status: Accepted

Solution code:
s = int(input())

inf = 1
i = 0
list = [s]
while(inf == 1):
    if list[i] % 2 == 1:
        tmp = 3*list[i] + 1
    elif list[i] % 2 == 0:
        tmp = list[i]/2
    for j in list:
        if j == tmp:
            print(i+2)
            inf = 0
            break
    list.append(tmp)
    i += 1