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:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

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

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)












###################################################################
def main():
    #CODE GOES HERE:
    s=ii()
    st=set()
    st.add(s)
    i=1
    while True:
        if s%2==0:
            s//=2
        else:
            s=3*s +1
        i+=1
        if s in st:
            print(i)
            return
        st.add(s)
    
















    
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()

Submission status: Accepted

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

s = int(input())
ans = 2
if s == 1 or s == 2:
    print(4)
    exit()
while(s > 1):
    s = f(s)
    ans += 1
print(ans)

Submission status: Accepted

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

s = int(input())
inf = 1000000
l = []
l.append(s)
for i in range(1, inf+1):
    ai = func(l[i-1])
    if ai in l:
        print(i+1)
        break
    else:
        l.append(ai)

Submission status: Accepted

Solution code:
s = int(input())
c = set([s])

i = 1
while 1:

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

  i += 1

  if s in c:
    break
  else:
    c.add(s)

print(i)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def collatz(number):
    if number % 2 == 0:
        return number // 2  # 整数の商
    else:  # elseで良い
        return 3 * number + 1  # // intは不要では？


number = int(input())
if number == 1:
    print(4)
    quit()
a = [number]
while True:
    number = collatz(number)
    a += [number]

    if number == 1:
        break
if 4 in a:
    print(a.index(4)+4)
elif 2 in a:
    print(a.index(2)+4)
else:
    print(a.index(1)+4)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    setN =set([n])
    count=1
    while True:
        if n %2 ==1:
            n=3*n+1
        else:
            n=n/2
        if n in setN:
            print(count+1)
            break
        else:
            count+=1
            setN.add(n)

Submission status: Accepted

Solution code:
s=int(input())

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

else:
    l=[]
    for i in range(10**6+1):
        l.append(s)
        if l.count(4)>2:
            break
        elif s%2==0:
            s=s//2
        else:
            s=3*s+1
    x=l.index(4)

    l=l[x+1:]
    y=l.index(4)

    print(y+x+2)

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

Submission status: Accepted

Solution code:
s = int(input())
def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1
num = set({s})
cnt = 2
pre = s
while True:
    ai = f(pre)
    #print(ai)
    if ai in num:
        print(cnt)
        break
    else:
        num.add(ai)
        pre = ai
        cnt += 1

Submission status: Accepted

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

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

m = s
c = 2
while f(m) not in a:
    a.append(f(m))
    m = f(m)
    c += 1

print(c)

Submission status: Accepted

Solution code:
s = int(input())

nums = []
nums.append(s)

for i in range(2, 1000001):
    q, m = divmod(s, 2)
    
    if m:
        s = 3*s + 1
    else:
        s = q

    if s in nums:
        print(i)
        break
    else:
        nums.append(s)

Submission status: Accepted

Solution code:
s = int(input())

lis = [s]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

sec = [s]
i = 1

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

def my_index_multi(l,x):
    return [i for i, _x in enumerate(l) if _x == x]

while len(my_index_multi(sec,s))!=2:
    s = f(s)
    sec.append(s)
print(my_index_multi(sec,s)[1]+1)

Submission status: Accepted

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

s = int(input())

a = set([s])


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

Submission status: Accepted

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

Submission status: Accepted

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

arr.append(s)

while s > 4:
    if s % 2 == 0:
        s = s // 2
        arr.append(s)
    else:
        s = 3 * s + 1
        arr.append(s)

if s == 3:
    print(9)
else:
    print(len(arr) + 3)

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

Solution code:
s = int(input())

l = [s]
N = s
count = 1

while 1:
  count += 1
  if N % 2 == 0:
    N = N // 2
  else:
    N = 3 * N + 1
    
  if N in l:
    print(count)
    break
  else:
    l.append(N)

Submission status: Accepted

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

Submission status: Accepted

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

S = int(input())

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

e = S
cnt = 0
while True:
    if e % 2 == 0:
        v = e//2
    else:
        v = 3*e+1
    e = v
    cnt += 1
    if v == 4:
        print(cnt+4)
        exit()

Submission status: Accepted

Solution code:
s = int(input())

st = set([])
x = s
for i in range(1,1000010):
    if x in st:
        print(i)
        break
    st.add(x)
    if x % 2 == 0:
        x = x // 2
    else:
        x = 3*x + 1

Submission status: Accepted

Solution code:
s = int(input())
cnt = 0
cnt4 = 0

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

while cnt4 < 2:
    cnt += 1
    if s == 4:
        cnt4 += 1
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#116-B（Collatz Problem）
a = []
s = input()
s = int(s)
a.append(s)

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

Submission status: Accepted

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


def main():
    from builtins import int, map, list, print, len
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    s = input_number()
    ls = [s]
    for i in range(1000000):
        a = func(ls[-1])
        ls.append(a)
        if a in ls[:-1]:
            print(len(ls))
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

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

S = int(input())

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

A = [S]
e = S
cnt = 0
while True:
    if e % 2 == 0:
        v = e//2
    else:
        v = 3*e+1
    A.append(v)
    e = v
    cnt += 1
    if v == 4:
        print(cnt+4)
        exit()

Submission status: Accepted

Solution code:
def main():
    s = int(input())
    n = s
    A = []
    i = 0
    while True:
        for ele in A:
            if ele == n:
                print(i+1)
                return
        A.append(n)
        if n%2 == 0:
            n = n // 2
        else:
            n = 3*n + 1
        
        i += 1
        
main()

Submission status: Accepted

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

Submission status: Accepted

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

        if len(a) != len(set(a)):
            print(len(a))
            return

resolve()

Submission status: Accepted

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

arr = [s]
i = 1
flag = 0
while flag == 0:
  an = f(arr[i - 1])
  arr.append(an)
  for j in range(i):
    if an == arr[j]:
      flag = 1
      break
  i += 1
print(len(arr))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter
import itertools
import fractions
import datetime
from decimal import Decimal
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
C=set()
C.add(s)
Cl=[s]
m=0

def f(x):
    if x%2==0:
        return int(x/2)
    else:
        return 3*x+1
while(1):
    m+=1
    x=f(Cl[m-1])
    if x in C:
        break
    Cl+=[x]
    C.add(x)
print(m+1)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    ans = 1
    for i in range(1000000):
        if N == 1 or N == 2 or N == 4:
            break
        elif N % 2 == 0 :
            N = N//2
            ans = ans + 1
        else:
            N = 3*N+1
            ans = ans+1 
    print(ans + 3)
resolve()

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s = int(sys.stdin.readline().rstrip())
n = set([s])
for i in range(2, 10**6 + 1):
    if s % 2 == 0:
        s_next = s // 2
    else:
        s_next = 3 * s + 1
    if s_next in n:
        print(i)
        exit()
    s = s_next
    n.add(s)

Submission status: Accepted

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

Submission status: Accepted

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

def f(n):
  if n % 2 == 0:
    return n//2
  else:
    return 3*n+1
  
for i in range(1000000):
  a[i+1] = f(a[i])
  
def solve(s,a):
  memo = []
  for i in range(len(a)):
    if a[i] in memo:
      return i+1
    else:
      memo.append(a[i])
  return -1

print(solve(s,a))

Submission status: Accepted

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

    if n in a:
        print(i+2)
        exit()
    else:
        a.append(n)

Submission status: Accepted

Solution code:
s = int(input())
l = [s]
#listにappend・同じ数字あるか探す
while True:
  if s%2 == 0:
    s = s//2
    l.append(s)
  else:
    s = 3*s+1
    l.append(s)
  if l.count(s) == 2:
    break
    
print(len(l))

Submission status: Accepted

Solution code:
def collatz(x):
  if(x==1 or x==2 or x==4):
    return[0,0]
  ret=[]
  while(x>1):
    if(x%2):
      x=3*x+1
    else:
      x/=2
    ret.append(x)
  return ret

print(len(collatz(int(input())))+2)

Submission status: Accepted

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

print(i+1)

Submission status: Accepted

Solution code:

s=int(input())
n=set()
a=s
for i in range(10**7):
    if a in n:
        break
    
    if a%2==0:
        n.add(a)
        a=a//2
    else:
        n.add(a)
        a=3*a+1
 
print(i+1)

Submission status: Accepted

Solution code:
s = int(input())
i = 2
al = set()
al.add(s)

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


print(i)

Submission status: Accepted

Solution code:
s = int(input())
l = []
f = s
l.append(f)
cnt = 1
while True:
  cnt += 1
  if f % 2 == 0:
    f = int(f/2)
  elif f % 2 == 1:
    f = int(3*f + 1)
  l.append(f)
  #print(l)
  #print(sorted(l), sorted(list(set(l))))
  if sorted(list(set(l))) == sorted(l): 
    #print(cnt)
    pass
  else:
    break

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

    if n in a[:len(a) - 1]:
        break

print(len(a))

Submission status: Accepted

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

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

print(len(a) + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

l = [0 for _ in range(1000000)]

l[s] += 1

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


def solve(s: int):
    nums = set([s])
    patterns = f(s, nums)

    print(len(patterns) + 1)
    return


def f(n: int, nums: set):
    before_size = len(nums)
    if n % 2 == 0:
        n = n / 2
    else:
        n = 3 * n + 1
    nums.add(n)
    if len(nums) == before_size:
        return nums

    return f(n, nums)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(s)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f(n):
  if n%2==0:
    return n//2
  else:
    return 3*n+1
S=int(input())
pre=S
dic={S:1}
while True:
  a=f(pre)
  if a not in dic:
    dic[a] = 1
  else:
    break
  pre = a
print(len(dic)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

a = [s]
t = s
while f(t) not in a:
    a.append(f(t))
    t = f(t)
print(len(a)+1)

Submission status: Accepted

Solution code:
s=int(input())
MAX=1000000
i=2
F=[0]*1000001
F[1]=s

def calc(n):
  n=F[n-1]
  if n%2==0:
    return n//2
  else:
    return 3*n+1

while i<=MAX:
  ans=calc(i)
  if ans in F:
    break
  F[i]=ans
  i+=1
print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = [int(input())]
flg = False
while flg == False:
    now = a[-1] 

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

    if new in a:
        flg = True
    else:
        a.append(new)
print(len(a)+1)

Submission status: Accepted

Solution code:
s = int(input())

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

    try:
        a.index(an)
        break
    except:
        a.append(an)
        s = an


print(m)

Submission status: Accepted

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


def has_duplicates(seq):
	return len(seq) != len(set(seq))
itr = 1
while True:
	#print(itr,A)
	itr += 1
	if A[-1] % 2 == 0:
		A.append(int(A[-1] / 2))
	else:
		A.append(int(3*A[-1]+1))
	#print(A)
	if has_duplicates(A):
		print(itr)
		break

Submission status: Accepted

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

s = int(input())
count = 0
a = [s]
n = s
while count < 1:
  n = check(n)
  length = len(a)
  a.append(n)
  if length+1 != len(set(a)):
    print(len(a))
    break

Submission status: Accepted

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


s = int(input())

a = []
a.append(s)

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

print(i + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
a_i = s
v = set([a_i])
for i in range(2, 1000000):
    if a_i % 2 == 0:
        a_i = int(a_i // 2)
    else:
        a_i = a_i * 3 + 1
    if a_i in v:
        print(i)
        break
    v.add(a_i)
    # print(f"i:{i} a_i:{a_i}", file=sys.stderr)

Submission status: Accepted

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

x = int(input())
A = []
count = 1
while x not in A:
	A.append(x)
	x = f(x)
	count += 1
print(count)

Submission status: Accepted

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

a=set([s])
mae=s
for i in range(100000):
  ai=f(mae)
  if ai in a:
    print(i+2)
    break
  else:
    a.add(ai)
    mae=ai

Submission status: Accepted

Solution code:
l = [True]*10000000

s = int(input())
l[s] = False
for i in range(2, 100000000):
  if s % 2 == 0:
    s //= 2
  else:
    s = 3*s + 1
  if l[s]:
    l[s] = False
  else:
    print(i)
    break

Submission status: Accepted

Solution code:
import copy
a = [int(input())]
t = []
i = 1


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


while True:
    a.append(f(a[i - 1]))
    t = copy.copy(a)
    t = [j for j, x in enumerate(t, 1) if t.count(x) > 1]
    if 0 < len(t):
        print(t[1])
        break
    i += 1

Submission status: Accepted

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

for i in range(10**6):
	if an%2 == 0:
		an //=2
		a.append(an)
	else:
		an = 3*an+1
		a.append(an)

for j in range(len(a)):
	cnt += 1
	if a[j] == a[j+3]:
		cnt += 3
		break
print(cnt)