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

Submission status: Accepted

Solution code:
s = int(input())

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

S = [s]
m = 2
i = ABC_B(s)
while(i not in S):
    m = m + 1
    S.append(i)
    i = ABC_B(i)
    
print(m)

Submission status: Accepted

Solution code:
def cal_a(a_prev):
    """Calculate a[i] when i > 1, according to below formula
    f(n) = n/2 if n is even, and f(n) = 3n + 1 if n is odd.
    """
    return a_prev // 2 if a_prev % 2 == 0 else a_prev * 3 + 1

a_cur = int(input())
found = set()
index = 1
while a_cur not in found:
    found.add(a_cur)
    a_cur = cal_a(a_cur)
    index += 1

print(index)

Submission status: Accepted

Solution code:
def cal_a(a_prev):
    """Calculate a[i] when i > 1, according to below formula
    f(n) = n/2 if n is even, and f(n) = 3n + 1 if n is odd.
    """
    return a_prev // 2 if a_prev % 2 == 0 else a_prev * 3 + 1

a_cur = int(input())
found = {}
index = 1
while a_cur not in found:
    found[a_cur] = index
    a_cur = cal_a(a_cur)
    index += 1

print(index)

Submission status: Accepted

Solution code:
first=int(input())

l=list()
ans=1

l.append(first)

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

s=set(l)
new=first

while(len(l)==len(s)):
    new=new_num(new)
    l.append(new)
    s=set(l)
    ans+=1
    
print(ans)

Submission status: Accepted

Solution code:
l = list()
l.append(int(input()))
s = set(l)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())


N = 1000000

a = [0]*N
a[0] = s
for i in range(0,N):
	if a[i]%2 == 0:
		a[i+1] = a[i]/2
	if a[i]%2 == 1:
		a[i+1] = 3*a[i]+1
	
	for j in range(0,i):
		if a[j] == a[i]:
			print(i+1)
			exit()

Submission status: Accepted

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


def main():
    s = int(input())
    aa = {s}
    a = f(s)
    for i in range(2, 1000001):
        if a in aa:
            print(i)
            break
        aa.add(a)
        a = f(a)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=int(input())

a=set([s])

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

    if s in a:
        print(len(a)+1)
        break
    else:
        a.add(s)

Submission status: Accepted

Solution code:
import numpy as np
import gc

if __name__ == '__main__':
    s=int(input())
    l=[]
    l.append(s)
    flag=False
    for i in range(1,1000000):
        if s%2:
            s=3*s+1
        else:
            s=s/2
        l.append(s)
        for j in range(0,i):
            if s==l[j]:
                print(i+1)
                del l
                gc.collect()
                flag=True
                break
        if flag:
            break

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input())
slist = []
p = calc(s)
slist.append(s)
slist.append(p)
s = p
while slist.count(p) != 2:
    p = calc(s)
    slist.append(p)
    s = p
slist.remove(p)
print(slist.index(p)+2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

f=1
ans = 1

al = [0 for i in range(10000)]

al[s]=1

while f>0:
    ans+=1
    
    if s%2==0:
        s=s//2
    else:
        s=3*s+1
       
    if al[s]==1:
        f=-1
    else:
        al[s]=1
        
print(ans)

Submission status: Accepted

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

s = int(input())
ans= [s]
i = 0
while True:
    s = f(ans[i])
    if s in ans:
        print(i+2)
        break
    else:
        ans.append(s)
        i +=1

Submission status: Accepted

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

a = int(input())
A = [a]
while True:
  b = calc(a)
  A.append(b)
  c = A.count(a)
  a = b
  if c == 2:
    break
print(len(A)-1)

Submission status: Accepted

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

a_n = int(input())
appeared = {a_n}

i = 1
while True:
    i += 1
    a_n = f(a_n)
    if a_n in appeared:
        print(i)
        break
    appeared.add(a_n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
i = 1
table = [False for _ in range(10**6)]
while True:
    if table[n]:
        print(i)
        exit()
    else:
        table[n] = True
    if n % 2 == 0:
        n = n // 2
    else:
        n = 3 * n + 1
    i += 1

Submission status: Accepted

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


s = int(input())
a = [s]
i = 0
while True:
  s = f(a[i])
  if s in a:
    print(i+2)
    break
  else:
    a.append(s)
    i += 1

Submission status: Accepted

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

Submission status: Accepted

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

    hoge.append(N)

Submission status: Accepted

Solution code:
import sys
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)
        sys.exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())

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

if s in (1, 2):
    res = 4
else:
    ai = s
    cnt = 1
    while ai != 4:
        ai = f(ai)
        cnt += 1

    res = cnt + 3

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a = []
a.append(int(input()))
ans = 0
def f_even(x):
        return x//2

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

for i in range(1000000):
        if a[i] % 2 == 0:
                a.append(f_even(a[i]))
        if a[i] % 2 == 1:
                a.append(f_odd(a[i]))
        for t in range(i):
                if a[i+1] == a[t]:
                        ans = i + 2
                        break
        else:
                continue
        break
print(ans)

Submission status: Accepted

Solution code:
i = int(input())

l = [i]
count = 0
f = True
while f:
  if l[-1] % 2 == 0:
    x = l[-1] / 2
  else:
    x = 3 * l[-1] + 1
  
  for y in l:
    if y == x:
      f = False
  l.append(x)

print len(l)

Submission status: Accepted

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

from collections import defaultdict
d = defaultdict(lambda: 0)
a = int(input())
d[a] = 1
for i in range(10**6):
    a = f(a)
    if d[a] != 0:
        print(i+2)
        break
    else:
        d[a] = 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
def f(n):
    return n // 2 if n % 2 == 0 else 3 * n + 1
table = {s}
for i in range(2,1000001):
    t = f(s)
    if t in table:
        print(i)
        break
    table.add(t)
    s = t

Submission status: Accepted

Solution code:
d = dict()
s = int(input())
d[s] = 1
i = 2
n = s

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

while True:
	c = f(n)
	if c not in d:
		d[c] = 1
	else:
		print(i)
		quit()
	n = c
	i += 1

Submission status: Accepted

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = INT()
N = 1000000

aN = [0] * (N+1)
aN[0] = s
c = Counter()
c[aN[0]] += 1
for i in range(1, N+1):
    n = aN[i-1]
    if n % 2 == 0:
        aN[i] = n // 2
    else:
        aN[i] = 3*n + 1
    if c[aN[i]] == 0:
        c[aN[i]] += 1
    else:
        print(i+1)
        exit()

Submission status: Accepted

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

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

    ft = [False] * 1001010
    ft[s] = True
    n = s
    i = 1
    while True:
        i += 1
        if n % 2 == 0:
            n //= 2
        else:
            n = 3 * n + 1
        if ft[n]:
            break
        ft[n] = True

    print(i)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
colatz=[1,2,4]
colatz.append(int(input()))
if colatz[3]==1 or colatz[3]==2 or colatz[3]==4:
    print(4)
else:
    b=3
    while colatz[b]!=4:
        if colatz[b]%2==0:
            colatz.append(colatz[b]/2)
        else: colatz.append(3*colatz[b]+1)
        b=b+1
    print(b+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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



# s = map(int, input().split())
s = int(input())

x = list()
x.append(s)

for i in range(1000000):
    s = hoge(s)
    #print(x)
    # print(s)
    if(s in x):
        print(len(x)+1)
        break
    x.append(s)

Submission status: Accepted

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


s = int(input())

already_exist = [s]
a = s
cnt = 1
while f(a) not in already_exist:
    a = f(a)
    already_exist.append(a)
    cnt += 1

print(cnt + 1)

Submission status: Accepted

Solution code:
s = int(input())
for m in range(1, 1000001):
    for k in range(1, m + 1):
        if k == 1:
            a = s
        else:
            if a % 2 == 0:
                a = int(a / 2)
            else:
                a = 3 * a + 1
    for n in range(1, m):
        if n == 1:
            b = s
            if a == b:
                print(m)
                break
        else:
            if b % 2 == 0:
                b = int(b / 2)
            else:
                b = 3 * b + 1
            if a == b:
                print(m)
                break
    else:
        continue
    break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def calc(_input):
  amari = _input % 2
  if amari == 0:
    return _input/2
  else:
    return _input*3 + 1

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    n = int(input())
    tmpset = set()
    res = 1
    while (n not in tmpset):
        tmpset.add(n)
        n = f(n)
        res += 1
    print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())

a = s
dic = {a:True}

while True:
    if a & 1:
        a = a*3+1
    else:
        a //= 2

    if a in dic:
        print(len(dic) + 1)
        break

    dic[a] = True

Submission status: Accepted

Solution code:
import sys
S = int(input())
a_list = []
a_list.append(S)

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

for i in range(10000):
    if i>1:
        tmp=function(a_list[i-2])
        a_list.append(tmp)
        for j in range(i-1):
            if a_list[i-1]==a_list[j]:
                print(i)
                sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def odd(n):
    return int(3 * n + 1)

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

num_list = [int(input())]
flag = True
m = 1
delete_num = 0
while(flag):
    if(num_list[-1] % 2 == 0):
        num_list.append(even(num_list[-1]))
    else:
        num_list.append(odd(num_list[-1]))
    num_len = len(num_list)
    delete_num = num_list[-1]
    m += 1
    if(delete_num in num_list[:num_len-1]):
        flag = False
print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

a = [s]

i = 2
while True:
    a_i = func(s)
    if a_i in a:
        print(i)
        break
    else:
        i += 1
        a.append(a_i)
        s = a_i

Submission status: Accepted

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

while flag:
  if a % 2 == 0:
    a = int(a / 2)
  else:
    a = a * 3 + 1
  for x in list:
    if a == x:
      ans = len(list) + 1
      flag = 0
      break
  list.append(a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

k = 1
while s not in (1, 2, 4):
  if s % 2 == 0:
    s //= 2
  else:
    s = s * 3 + 1
  k += 1

print(k+3)

Submission status: Accepted

Solution code:
def collatz(n, count):
    if (n == 1) or (n == 2) or (n == 4):
        return count + 3
    elif n % 2:
        return collatz(3 * n + 1, count + 1)
    else:
        return collatz(n // 2, count + 1)

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

Submission status: Accepted

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

def calc(s):
    array = []
    for i in range(1,1000000):
        if i == 1:
            array.append(s)
        elif i > 1:
            array.append(functionF(array[i - 2]))
            for k in range(1, i):
#                 print(i, k)
#                 print(array[i-1], array[k-1])
                if array[i-1] == array[k-1]:
                    print(i)
                    return
calc(s)

Submission status: Accepted

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

    if a in ans:
        print(i)
        exit()
    else:

        ans.append(a)

Submission status: Accepted

Solution code:
S = int(input())

ans = 0

a = [S]

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

print(ans + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


s = int(input())
check = {s: True}
m = 1

while True:
    s = collats(s)
    m += 1

    if s in check:
        print('%d' % m)
        break
    check[s] = True

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = int(input())

def f(n):
  if n%2 == 0:
    return n // 2
  else:
    return 3*n + 1
  
A = set()
X = [0] * 1000010

X[1] = S
A.add(S)

for i in range(2,1000001):
  X[i] = f(X[i-1])
  A.add(X[i])
  if i > len(A):
    break
    
print(i)

Submission status: Accepted

Solution code:
li=list(map(int,input().split()))


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

while True:
    if not f(list[-1]) in list:
        list.append(f(list[-1]))
        n+=1
    else:
        print(n)
        break

Submission status: Accepted

Solution code:
def solve(s):
    S = set()
    S.add(s)
    i = 1
    a = s
    while True:
        if a % 2 == 0:
            a = a / 2
        else:
            a = 3*a + 1
        if a in S:
            return i+1
        S.add(a)
        i += 1

s = int(input())
print(solve(s))

Submission status: Accepted

Solution code:
a = int(input())
n = 1
log = {a}
while n==len(log):
  if a%2==0:
    a //= 2
  else:
    a = a*3+1
  log.add(a)
  n+=1
print(n)

Submission status: Accepted

Solution code:
s = int(input())

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

def check(a, k):    
    for l in range(1, len(a)-k): 
        if a[k] == a[k+l]:
            print(k+l+1)
            return False
    return True

a = [s]
i = 0
flg = 1

while(flg):
    a.append(func(a[i]))
    #print(a)
    for k in range(len(a)):
        if not check(a, k):
            flg = 0
            break
    i += 1

Submission status: Accepted

Solution code:
s = int(input())

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

a = [s]
i = 0
flg = 1

while(flg):
    a.append(func(a[i]))
    #print(a)
    for k in range(len(a)):
        for l in range(1, len(a)-k): 
            if a[k] == a[k+l]:
                print(k+l+1)
                break
        else:
            continue
        break
    else:
        i += 1
        continue
    break

Submission status: Accepted

Solution code:
s = int(input())

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

a = [s]
i = 0
flg = 1
while(flg):
    a.append(func(a[i]))
    #print(a)
    for k in range(len(a)):
        for l in range(1, len(a)-k): 
            if a[k] == a[k+l]:
                print(k+l+1)
                flg = 0
                break
        if flg == 0:
            break
        
    i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


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


def main():
    s = int(stdin.readline().rstrip())
    am = s
    tmp = {am}
    for m in range(2, 1000001):
        am = f(am)
        if am in tmp:
            print(m)
            return
        tmp.add(am)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

s = int(input())

memo = []

for m in range(1,1000000000000000):
    if m == 1:
        memo.append(s)
    else:
        if f(memo[-1]) in memo:
            print(int(m))
            exit(0)
        else:
            memo.append(f(memo[-1]))

Submission status: Accepted

Solution code:
s = int(raw_input())
flag = 1
L = [s]
val = s
while flag == 1:
    if val % 2 == 0:
        val /= 2
        val = int(val)
        # print(val)
    else:
        val = val*3 + 1
        # print(val)
    if val in L:
        flag = 0
        point = len(L) + 1
        val = int(val)
        print(point)
    L.append(val)
# print(L)

Submission status: Accepted

Solution code:
n = int(input())
x = set()
cnt = 1
x.add(n)

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

    if n in x:
        print(cnt)
        break
    else:
        x.add(n)

Submission status: Accepted

Solution code:
s = int(input())

exist = set()
cnt = 1

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

Submission status: Accepted

Solution code:
S = int(input())

n = S
a = {S}
for i in range(1, 10**6+1):
    if n%2==0:
        n = n//2
    else:
        n = 3*n+1
    
    if n in a:
        print(i+1)
        exit()
    else:
        a.add(n)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
m=0
ans = 0
while m < 1000001:
	if a[m]%2==0:
		a.append(a[m]//2)
	else:
		a.append(3*a[m]+1)
	for i in range(m):
		if a[i] == a[m]:
			ans = m+1
			break
	if ans > 0:
		break
	m+=1
print(ans)

Submission status: Accepted

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


def suuretu(sa, hairetu):
    hairetu.append(float(sa))

    for i in range(len(hairetu)):
        for j in range(len(hairetu)):
            if hairetu[i] == hairetu[j] and i != j:
                print(max(i, j)+1)
                return 

    if sa % 2 == 0:
        suuretu(float(sa)/2, hairetu)
    else:
        suuretu(3*float(sa)+1, hairetu)


suuretu(float(s), a)

Submission status: Accepted

Solution code:
def run(s):
    n = 1000001
    a = [0, s]
    for i in range(2, n):
        pre = a[i-1]
        if pre % 2 == 0:
            a.append(pre // 2)
        else:
            a.append(3*pre + 1)
    ret_dic = {}
    ret = None
    for i in range(1, n):
        ai = a[i]
        if ai in ret_dic:
            ret = i
            break
        else:
            ret_dic[ai] = 1
    return ret


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = int(input())

li = [s]
k = 0

while True:
    if li[k] % 2 == 0:
        li.append(int(li[k] / 2))
    else:
        li.append(3 * li[k] + 1)

    for n in range(len(li) - 1):
        for m in range(n + 1, len(li)):
            if li[n] == li[m]:
                print(m + 1)
                quit()
    k += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
def formula(num):
    if (int(num) % 2 == 1):
        return int(3*num + 1)
    else:
        return int(num / 2)

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

n = formula(s)
while(True):
    if ( n in nums ):
        print(len(nums) + 1)
        sys.exit(0)
    nums.append(n)
    n = formula(n)

Submission status: Accepted

Solution code:
from collections import Counter
s = int(input())
c = Counter()
for i in range(1, 1000010):
  if c[s]:
    print(i)
    break
  c[s] = 1
  s = s // 2 if s % 2 == 0 else 3 * s + 1

Submission status: Accepted

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

s=int(input())
a=[]
m=1
while not s in a:
    a.append(s)
    s=f(s)
    m+=1
print(m)

Submission status: Accepted

Solution code:
s, = map(int, input().split())
l = {s:1}
a = s
i = 1
while True:
  i += 1
  a = a//2 if a%2==0 else 3*a+1
  if a in l:
    print(i)
    break
  l[a]=1

Submission status: Accepted

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

n=0
while True:
    if in_list[n]%2==1:
        in_list.append(int(3*in_list[n]+1))
    if in_list[n]%2==0:
        in_list.append(int(in_list[n]/2))
    if in_list[n+1] in in_list[0:n]:
        print(n+2)
        break
    n+=1

Submission status: Accepted

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

S = int(input())
l =[]
m = 1
while not S in l:
    l.append(S)
    S =f(S)
    m += 1
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input())
a = [s]
check = True
m = 1

while check:
    if function(a[m-1]) in a:
        check = False
    else:
        a.append(function(a[m-1]))
        m += 1
print(m+1)

Submission status: Accepted

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

Submission status: Accepted

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

print (counter)

Submission status: Accepted

Solution code:
s = int(input())
his = {s}
while 1:
    f = lambda n: n // 2 if n % 2 == 0 else 3 * n + 1
    s = f(s)
    if s in his:
        print(len(his) + 1)
        exit()
    his.add(s)

Submission status: Accepted

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


def main():
    s = int(input())
    a_list = [s]
    counter = 2
    while True:
        s = cal_f(s)
        if s in a_list:
            print(counter)
            break
        else:
            a_list.append(s)
            counter += 1

main()

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

a= []
a.append(int(input()))
for i in range(1000000):
  x = f(a[i])
  if x in a:
    print(len(a)+1)
    break
  a.append(x)

Submission status: Accepted

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

Submission status: Accepted

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