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:
import collections
import math
import re
import numpy
def ai():return input()#s
def a():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
def say(i):return print("Yes" if i == 0 else "No")
def Say(i):return print("YES" if i == 0 else "NO")
k= [0]
l = []
f = 0
s=0
c=0
e =1
k[0] =a()
for i in range(0,1000001):
    if k[i] in k[:i]:
        c=i
        break
    if k[i]%2==0:
        k.append(k[i]//2)
    else:k.append(k[i]*3+1)
print(c+1)

Submission status: Accepted

Solution code:
s = int(input())


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

A = [s]

for i in range(1000000):
    a = f(A[-1])
    if a in A:
        print(i+2)
        break
    else:
        A.append(a)

Submission status: Accepted

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

print(i+1)

Submission status: Accepted

Solution code:
s = int(input())

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

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

Submission status: Accepted

Solution code:
def solve(s):
    d = set()

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

    while True:
        d.add(s)
        s = f(s)
        if s in d:
            return len(d) + 1


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lis = [0 for i in range(10000000)]
cou = 1
while 1:
    if lis[n] == 1:
        print(cou)
        exit()
    lis[n] = 1
    if n % 2 == 0:
        n = n // 2
    else:
        n = 3 * n +1
    cou += 1

Submission status: Accepted

Solution code:
s = int(input())
seen = {s}
steps = 2

while True:
  if s & 1:
    s = 3 * s + 1
  else:
    s >>= 1
  if s in seen:
    print(steps)
    break
  steps += 1
  seen.add(s)

Submission status: Accepted

Solution code:
from collections import defaultdict
def collatz(a):
    if a % 2 == 0:
        return a//2
    return 3*a+1

s = int( input())
d = defaultdict( int)
d[s] = 1
for i in range(2, 1000000):
    s = collatz(s)
    if d[s] == 0:
        d[s] = 1
    else:
        ans = i
        break
print( ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
A=[s]
Ans=1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INF, MOD = float("inf"), 1e9 + 7
MAX, MIN = -INF, INF
dx1, dy1, dx2, dy2 = [-1, 0, 1, 0], [0, -1, 0, 1], [-1, 0, 1, -1, 1, -1, 0, 1], [-1, -1, -1, 0, 0, 1, 1, 1]

def get_int():
    return int(input())

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

def mins(x, y):
    x = min(x, y)

def maxs(x, y):
    x = max(x, y)

while(True):
    try:
        n = int(input())
        a = []
        a.append(n)
        while(True):
            x = 3 * a[len(a) - 1] + 1 if a[len(a) - 1] % 2 else int(a[len(a) - 1] / 2)
            if x in a:
                print(len(a) + 1)
                break
            a.append(x)
    except EOFError:
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]
mod = 1000000007

#A
"""
a,b,c = LI()
s = a+b+c
s /= 2
ans = (s*(s-a)*(s-b)*(s-c))**(1/2)
print(int(ans))
"""

#B
s = int(input())
m = 1
lis = [True for i in range(1000001)]

while lis[s]:
    lis[s] = False
    if s % 2 == 1:
        s = 3*s+1
    else:
        s //= 2
    m += 1
print(m)
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
d = {}
s = int(input())
d[s] = 1
i = 1
while 1:
    if s & 1:
        s = 3*s+1
    else:
        s = s//2
    i += 1
    if s in d:
        print(i)
        break
    d[s] = i

Submission status: Accepted

Solution code:
n = int(input())
cnt = 1

bl = [False] * (10**6 + 1)
bl[n] = True

while 1:
    cnt += 1
    if n % 2 == 0:
        next = n // 2
    else:
        next = 3 * n + 1
    if bl[next]:
        break
    n = next
    bl[n] = 1

print(cnt)

Submission status: Accepted

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

i = 0
n = int(input())
while True:
    if n == 4 or n == 2 or n == 1:
        print(i+4)
        break
    i += 1
    n = f(n)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None

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

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

    L = [s]

    for i in range(2, 10**10):
        s = f(s)

        if s in L:
            print(i)
            return
        
        L.append(s)



main()

Submission status: Accepted

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

print(len(A)+1)

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

s = int(input())
i = 1
As = set()
As.add(s)
prev = s
while True:
    i += 1
    if prev % 2:
        s = 3 * prev + 1
    else:
        s = prev // 2
    if s in As:
        print(i)
        break
    As.add(s)
    prev = s
8

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: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=int(input())
G =[s]
while all(G[i]!=G[-1] for i in range(len(G)-1)):
  if G[-1] % 2==0:
    G.append(int(x/2))
  else:
    G.append(int(3*x+1))
print(len(G))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# abc116_b.py
# https://atcoder.jp/contests/abc116/tasks/abc116_b

# B - Collatz Problem /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 数列 a={a1,a2,a3,......}は、以下のようにして定まります。
#     初項 sは入力で与えられる。
#     関数 f(n)を以下のように定める: n が偶数なら f(n)=n/2、n が奇数なら f(n)=3n+1。
#     i=1のとき ai=s、i>1 のとき ai=f(ai−1)である。
# このとき、次の条件を満たす最小の整数 mを求めてください。
#     am=an(m>n)を満たす整数 nが存在する。

# 制約
#     1≦s≦100
#     入力はすべて整数である。
#     aのすべての要素、および条件を満たす最小の m は 1000000以下となることが保証される。

# 入力
# 入力は以下の形式で標準入力から与えられます。
# s

# 出力
# 条件を満たす最小の整数 mを出力してください。

# 入力例 1
# 8

# 出力例 1
# 5

# a={8,4,2,1,4,2,1,4,2,1,......}です。a5=a2 なので、答えは 5です。

# 入力例 2
# 7

# 出力例 2
# 18

# a={7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4,2,1,......}です。

# 入力例 3
# 54

# 出力例 3
# 114


def calculation(lines):
    # X = lines[0]
    s = int(lines[0])
    # values = list(map(int, lines[0].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))
    
    values = [s]

    for i in range(101):
        s = func_f(values[i])
        if s in values:
            return [i+2]
        values.append(s)


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


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['8']
        lines_export = [5]
    if pattern == 2:
        lines_input = ['7']
        lines_export = [18]
    if pattern == 3:
        lines_input = ['54']
        lines_export = [114]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
L = []
n = int(input())
t, a = map(int, input().split())
l = list(map(int, input().split()))
for i in range(n):
  L.append(abs(a-(t - l[i] * 0.006)))
  
print(L.index(min(L))+1)

Submission status: Runtime Error

Solution code:
s = int(input())
def f(n):
	if n%2==0:
    	return n/2
	else:
		return 3*n+1
cnt = 0
m = 0
while True:
	s = f(s)
    m = m+1
	if s == 4:
		if cnt == 0:
			cnt = 1
            continue
		else:
          	print(m)
	else:
		continue
	break

Submission status: Runtime Error

Solution code:
a=int(input())
A={a}
cnt=1
while True:
    cnt+=1
    if a%2==0:
        if a//2 in A:
            break
        else:A+=a//2
    else:
        if 3*a+1 in A:
            break
        else:A+=3*a+1
print(cnt)

Submission status: Runtime Error

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())
a = [number]
while True:
    number = collatz(number)
    a += [number]

    if number == 1:
        break
print(a.index(4)+4)

Submission status: Runtime Error

Solution code:
s=int(input())

if s==4 or s==2 or s==1:
    print(4)
    
l=[]
else:
    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: Runtime Error

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(k+1)
                exit()
resolve()

Submission status: Runtime Error

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(k+1)
                exit()
resolve()

Submission status: Runtime Error

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 se:
        print(cnt)
        exit()
    else:
        l.append(s)

Submission status: Runtime Error

Solution code:
s = int(input())
a = [s]
z = set(s)
idx = 1
for i in range(10**8):
    idx += 1
    if a[i] % 2 == 0:
        ai = a[i] // 2
    else:
        ai = 3 * a[i] + 1
    if ai in z:
        print(idx)
        exit()
    a.append(ai)
    z.add(ai)

Submission status: Runtime Error

Solution code:
print([1, 3, 3, 8, 3, 6, 9, 17, 4, 20, 7, 15, 10, 10, 18, 18, 5, 13, 21, 21, 8, 8, 16, 16, 11, 24, 11, 112, 19, 19, 19, 107, 6, 27, 14, 14, 22, 22, 22, 35, 9, 110, 9, 30, 17, 17, 17, 105, 12, 25, 25, 25, 12, 12, 113, 113, 20, 33, 20, 33, 20, 20, 108, 108, 7, 28, 28, 28, 15, 15, 15, 103, 23, 116, 23, 15, 23, 23, 36, 36, 10, 23, 111, 111, 10, 10, 31, 31, 18, 31, 18, 93, 18, 18, 106, 106, 13, 119, 26, 26][int(input())]+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = int(input())
a = [0 for i in range(1000001)]
a[s] = 1
ai = s
i = 2
while True:
  if ai % 2 == 0:
    ai /= 2
  else:
    ai = 3 * ai + 1
  if a[ai] > 0:
    print(i)
    break
  else:
    a[ai] = 1
    i += 1

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = int(input())

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

Submission status: Runtime Error

Solution code:
s = int(input())
a = list(map(int,input().split()))
ans = [s]

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

  if s in ans:
        break
  else:
        ans.append(s)
      
print(len(ans)+1)

Submission status: Runtime Error

Solution code:
import copy

n = int(input())
h = []
for i in range(n):
    h.append(int(input()))

h = h.sort()

cnt = 1
now = copy.deepcopy(h[0])
h.pop(0)

while not len(h) == 0:
    if h[0] != now:
        cnt += 1
        now = copy.deepcopy(h[0])
    h.pop(0)

Submission status: Runtime Error

Solution code:
s = int(input())
a = set(s)
p = s
n = 0
cnt = 0
while True:
  if n in a:
    print(cnt)
    exit()
  if p&1:
    n = 3*p +1
  else:
    n = p//2
  cnt += 1
  a.add(n)
  p = n

Submission status: Runtime Error

Solution code:
s = int(input())
a = set(s)
p = s
n = 0
cnt = 0
while True:
  if n in a:
    print(cnt)
    exit()
  if p&1:
    n = 3*p +1
  else:
    n = p//2
  cnt += 1
  set.add(n)
  p = n

Submission status: Runtime Error

Solution code:
s = int(input())

if s == 2:
  print(4)
elif s == 4:
  print(4)
elif s == 1:
  print(4)
else:
  count = 2
  while s > 1:
  	count+=1
  	if s % 2 == 0:
    	s = s//2
  	else:
    	s = 3*s+1
  print(count)

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

s = int(input())

box = [-1]*(int(1e10))

i = 1

while 1:
    if box[collaz(s)] == 1:
        print(i+1)
        break
    else:
        box[collaz(s)] = 1
        s = collaz(s)
        i += 1

Submission status: Runtime Error

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

a = [s]
for i in range(10):
    #print(i)
    if a[i] % 2 == 0:
        a.append(a[i] // 2)
    else:
        a.append(3 * a[i] + 1)
#print(a)
i = 0
flag = True
while flag:
    for j in range(i):
        if a[i] == a[j]:
            ans = i + 1
            flag = False
            break
    i += 1
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
s = int(input())
rec = {}


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


c = 0
while True:
    if s in rec:
        print(c)
        exit()
    rec.add(s)
    s = f(s)
    c += 1

Submission status: Runtime Error

Solution code:
ai=[s]
for i in range(1000000):
    if s%2:
        s =3*s+1
        ai.append(s)
    else:
        s = s//2
        ai.append(s)
    print(ai)
    if len(ai) != len(set(ai)):
        c=0
        for j in range(len(ai)):
            if ai.count(ai[j])==2:
                c +=1
                if c ==2:
                    print(j+1)
                    break
        exit()

Submission status: Runtime Error

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

print(ans + 3)

Submission status: Runtime Error

Solution code:
a,b,c=map(int,input().split())
print((a*b)//2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = int(input())

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

if s == 1 or s == 2 or s == 4:
  print(4)
else:
  count = 1
  while s != 4:
    s = calc(s)
    count += 1

print(count + 3)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = int(input())

log = set()
set.add(s)
for i in range(1001000):
    if s%2==0:
        s //=2
    else:
        s = 3*s+1

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

    log.add(s)

Submission status: Runtime Error

Solution code:
s=int(input())
def f(x):
  if x%2==0:
    return x/2
  else:
    return 3*x+1
def lol(n):
  if n>1:
    return f(lol(n-1))
  elif n==1:
    return s
List=[]
for i in range(1,1000000):
  if lol(i)==2:
    break
  List.append(lol(i))
print(List.index(4)+4)

Submission status: Runtime Error

Solution code:
s=int(input())
def f(x):
  if x%2==0:
    return x/2
  else:
    return 3*x+1
def lol(n):
  if n>1:
    return f(lol(n-1))
  elif n==1:
    return s
List=[]
for i in range(1000000):
  if lol(i)==2:
    break
  List.append(lol(i))
print(List.index(4)+3)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a=input()
cnt=1
while a!=1
  if(a%2==0):
    a//=2
    cnt+=1
  else:
    a=3a+1
    cnt+=1
print(cnt=+3)

Submission status: Runtime Error

Solution code:
s = int(input())
if s==1:
    print(4)
elif s==2:
    print(4)
else:
    print(func(s))

Submission status: Runtime Error

Solution code:
import collections
s=int(input())
count=1
ans=s
prev=0
counter = collections.defaultdict(int)
counter[ans]=1
while(1):
  count+=1
  if ans % 2 == 0:
    ans = ans / 2
  else:
    ans = 3*n+1
    
  if ans not in counter.keys:
    counter[ans]=count
  else:
    print(counter[ans])
    break

Submission status: Runtime Error

Solution code:
s=int(input())
a=s
g=1
for i in range(1000000):
  if a%2==0:
    a=a/2
    g+=1
    if a==4:
      m=g+3
      break
  elif a%2==1:
    a=3*a+1
    g+=1
print(m)

Submission status: Runtime Error

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

def f(n,i):
    if i==1:
        return s

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

A={}
n=0
for i in range(1,M):
    n=f(n,i)
    A.setdefault(i,n)
    for j in range(1,i):
        if A[j]==A[i]:
            print(i)
            return

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

#define mod 1000000007

#define rep(i, n) for(int i=1; i<=n; ++i)

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int a[100000];
	
	cin >> a[0];
	
	rep(i, 100000){
		if(a[i-1] % 2 == 0)
			a[i] = a[i-1] / 2;
		else
			a[i] = 3 * a[i-1] + 1;
		rep(j, i){
			if(a[j] == a[i]){
				cout << i;
				return 0;
			}
		}
	}
}

Submission status: Runtime Error

Solution code:
s = int(input())
array = []
cnt = 1
array.append(s)
while True:
    s = cal(s)
    array.append(s)
    if array[cnt] in array[:cnt]:
        print(cnt +1)
        break
    cnt += 1

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
Flag = 0
nList = []
nList.append(N)
i = 2
while Flag==0:
  Tmp = N % 2
  if Tmp == 0:
    TmpN /= 2
  else:
    TmpN = 3 * N + 1
  
  if TmpN in nList:
    Flag = 1
    break
  else:
    nList.append(TmpN)
    N = TmpN
    i += 1

print(i)

Submission status: Runtime Error

Solution code:
import collections

s = int(input())
A = [s]
for i in range(1000000+1):
  A.append(i//2 if i%2==0 else 3*n+1)
  c = collections.Counter(A)
  if c.most_common()[0][1] ==2:
    print(i)
    break

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

print(4 if i < 4 else max(i+3))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=int(input())
an=[0]*1000000
tmp=[False]*300
an[0] = s
for i in range(1, 1000000):
    if an[i-1] % 2 == 0:
        an[i] = int(an[i-1]/2)
    else:
        an[i] = 3*an[i-1] + 1
    if not tmp[an[i]]:
        tmp[an[i]] = True
    else:
        print(i+1)
        exit()

Submission status: Runtime Error

Solution code:
s=int(input())
an=[0]*1000000
tmp=[False]*300
an[0] = s
for i in range(1, 1000000):
    if an[i-1] % 2 == 0:
        an[i] = an[i-1]/2
    else:
        an[i] = 3*an[i-1] + 1
    if not tmp[an[i]]:
        tmp[an[i]] = True
    else:
        print(i)
        exit()

Submission status: Runtime Error

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

while 1:
    if s%2==0:
        s=s/2
        a.append(s)
    else:
        s=3*s+1
        a.append(s)
    if len(a)!=len(set(a)):
        print(len(a))
        exit()