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())
cur=set([s])
i=1
while True:
  i=i+1
  if s%2==0:
    s=s//2
  else:
    s=3*s+1
  if s in cur:
    print(i)
    break
  else:
    cur.add(s)

Submission status: Accepted

Solution code:
import sys


s = int(input())
A = [0, s]

for i in range(2, 1000001):
    n = A[i-1]
    if n % 2 == 0:
        tmp = n / 2
        if tmp in A:
            print(i)
            sys.exit()
        else:
            A.append(tmp)
    else:
        tmp = 3 * n + 1
        if tmp in A:
            print(i)
            sys.exit()
        else:
            A.append(tmp)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

Solution code:
# ABC116b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

s = int(input())


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


a = [0, s]

for i in range(2, 10**6):
    num = f(a[i-1])
    a.append(num)
    idx = a.index(num)
    #print(a)
    if(idx+1 < i):
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
a = []
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 = [s]
tmp = s
cnt = 1
while 1:
    cnt += 1
    if tmp % 2 == 0:
        tmp //= 2
    else:
        tmp = 3 * tmp + 1

    if tmp in a:
        break
    a.append(tmp)

print(cnt)

Submission status: Accepted

Solution code:
def f(a):
  if a%2==0:
    a = a//2
  else:
    a = a*3+1
  return a
s = int(input())
cnt = [0]*1000001
cnt[s] = 1
ans = 1
while 1:
  s = f(s)
  if cnt[s]==0:
    ans += 1
    cnt[s]=1
  elif cnt[s]==1:
    ans += 1
    print(ans)
    exit()

Submission status: Accepted

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

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:
a=int(input())
list=[a]
for i in range(1,1000001):
    if a%2 == 0:
        a = a//2
    else:
        a = 3*a + 1
    if a in list:
        print(i+1)
        exit()
    list.append(a)

Submission status: Accepted

Solution code:
s=int(input())
m=[0]*100000
m[s]+=1

mm=0
while 1:
  mm+=1
  if s%2==0:
    s=s//2
    m[s]+=1
  else:
    s=s*3+1
    m[s]+=1
  #print(s)
  if m[s]==2:
    print(mm+1)
    break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
count=1
s=int(input())
while True:
    if  s in (4,2,1):
        print(count+3)
        break
    if s % 2 == 1:
        s = s*3 + 1
    else:
        s = s//2
    count+=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = int(input())
def ff(x):
  if x % 2 == 0:
    return x/2
  else:
    return x * 3 +1
A = [0] * 1000
A[0] = S
for i in range(1,1000):
  A[i] = ff(A[i-1])
  if A.count(A[i]) == 2:
    print(i+1)
    exit()

Submission status: Accepted

Solution code:
s=int(input())

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

result=[s]
for i in range(2,10000000):
  s=f(s)
  if s in result:
    print(i)
    exit()
  else:
    result.append(s)

Submission status: Accepted

Solution code:
s=int(input())
a=s
if s==1 or s==2 or s==4:
  print(4)
else:
  cnt=0
  flag=True
  while flag:
    if a%2==0:
      a=a//2
    else:
      a=3*a+1
    cnt+=1
    if a == 4:
      flag=False
  print(cnt+3+1)

Submission status: Accepted

Solution code:
s=int(input())

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

result=[s]
for i in range(2,10000000):
  s=f(s)
  if s in result:
    print(i)
    exit()
  else:
    result.append(s)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

for i in range(1000000):
	if i == 0:
		A.append(s)
	X = f(A[i])
	if X in A:
		break
	A.append(X)

print(i + 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())


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

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

Submission status: Accepted

Solution code:
s = int(input())

dic = {}
dic[s] = 1
a_old = s
counter = 1

while True:
  counter += 1  
  if a_old % 2 == 0:
    a_old //= 2
  elif a_old % 2 == 1:
    a_old = a_old * 3 + 1
  
  if a_old in dic.keys():
    dic[int(a_old)] += 1    
  else:
    dic[int(a_old)] = 1
    
  if 2 in dic.values():
    break

print(counter)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
a = int(input())
m = 1
que = deque([-1, -2], maxlen=4)
while a not in que:
    que.append(a)
    a = a // 2 if a % 2 == 0 else a * 3 + 1
    m += 1
print(m)

Submission status: Accepted

Solution code:
s = int(input())
M = [-1]*1000001
As = [s]
M[s] = 0
for i in range(1, 1000001):
  a = As[i-1]
  b = a//2 if a%2 == 0 else 3*a+1
  if not(M[b] < 0):
    print(i+1)
    exit()
  M[b] = i
  As.append(b)
print(-1)

Submission status: Accepted

Solution code:
s = int(input())

ls = [False for _ in range(1000001)]
ls[s] = True

count = 1
while True:
    if s % 2 == 0:
        s //= 2
    else:
        s = 3 * s + 1
    if ls[s]:
        break
    ls[s] = True
    count += 1
print(count + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
M = 1000000
m = 1

while m <= M:
    if a in (1, 2, 4):
        m += 3
        break
    if a % 2 == 0:
        a //= 2
    else:
        a = 3 * a + 1
    m += 1

print(m)

Submission status: Accepted

Solution code:
s = int(input())
M = 1000000
m = 1
a = s

while m <= M:
    if a == 4:
        m += 3
        break
    if a % 2 == 0:
        a //= 2
    else:
        a = 3 * a + 1
    m += 1

if s in (1, 2):
    m = 4

print(m)

Submission status: Accepted

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: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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]
m = 1
for i in range(2,1000001):
    a.append(f(a[i-2]))
    m = i
    if len(set(a))!=len(a):
        break
print(m)

Submission status: Accepted

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


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

Submission status: Accepted

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


s = int(input())
if s==1:
    print(4)
elif s==2:
    print(4)
elif 3<=s and s<=100:
    print(func(s))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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


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

memory = [0]*1000000
tmp = N
memory[N]=1
while True:
    ans+=1
    tmp=f(tmp)
    if memory[tmp] == 1:
        break
    else:
        memory[tmp]=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

def f(n):
  if n % 2 == 0:
    return n // 2
  else:
    return 3 * n + 1
  
def a(n):
  if n == 1:
    return s
  elif n >= 2:
    return f(a(n-1))
m, p = 2, 0
while p == 0:
  for i in range(1, m):
    if a(i) == a(m):
      p += 1
  if p == 0:
    m += 1

print(m)

Submission status: Accepted

Solution code:
start = int(input())

def calc(x):
  if x %2 ==0:
    Answer = x /2
  else:
    Answer = 3*x+1
  return Answer
counter = 1
number = 0
Answer_list = [start]
while number < 1:
  if calc(start) in Answer_list:
    Answer_list.append(calc(start))
    number = counter+1
    print(number)
  else:
    start = calc(start)
    Answer_list.append(start) 
    counter +=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""#################################################################
【ABC116】
B_Collatz_Problem
#################################################################"""

#インポート
import sys

#入力用
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def IS(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def SS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()

lst = []
lst.append(II())
i = 1
while 0==0:
    if lst[i-1] % 2 == 0:
        lst.append(lst[i-1] / 2)
    else:
        lst.append(3 * lst[i-1] + 1)
    if lst.count(lst[i]) == 2:
        print(i+1)
        break
    i += 1

Submission status: Accepted

Solution code:
s = int(input())

a = 0
S = [s]
i = 0

while a not in S:
    if i > 0:
        S.append(a)
    if S[i]%2 == 0:
        a = int(S[i]/2)
    else:
        a = S[i]*3+1
    i += 1

print(i+1)

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)+1)

Submission status: Accepted

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

print(i+4)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = int(input())

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

list = []
list.append(S)

for i in range(2,1000000):
  S = ansgen(S)
  if S in list:
    print(i)
    exit()
  list.append(S)

Submission status: Accepted

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*ans+1
    
  if ans not in counter.keys():
    counter[ans]=count
  else:
    print(count)
    break

Submission status: Accepted

Solution code:
s = int(input())
import sys
tmp = s
A = [tmp]
flag = 0
while flag==0:
    if tmp%2 == 0:
        tmp//=2
        A.append(tmp)
    else:
        tmp = 3*tmp+1
        A.append(tmp)
    if tmp==1:
        flag = 1
A += [4,2,1]
N = len(A)
flag = 0

for i in range(N):
    tmp = A[i]
    for j in range(i+1,N):
        if A[j]==tmp:
            print(j+1)
            sys.exit()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

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

print(len(L) + 1)

Submission status: Accepted

Solution code:
L = [int(input())]
i = 2
while True:
    n = L[-1]
    v = int(n / 2) if n % 2 == 0 else (3 * n) + 1

    if v in L:
        print(i)
        break
    else:
        L.append(v)

    i += 1

Submission status: Accepted

Solution code:
s = int(input())

a = set()
a.add(s)
i = 1
while True:
  i += 1
  if s&1:
    s = 3 * s + 1
  else:
    s = s//2
  if s in a:
    print(i)
    break
  a.add(s)

Submission status: Accepted

Solution code:
a = [0]*1000001
a[1] = int(input())
def fun(n):
    if n%2:
        return 3*n + 1
    else:
        return int(n/2)
    
for i in range(2,1000001):
    a[i] = fun(a[i-1])
    if a[i] in a[:i]:
        print(i)
        break

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

s = ni()

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

num = []
m = 1

while s not in num:
    num.append(s)
    s = f(s)
    m += 1

print(m)

Submission status: Accepted

Solution code:
s = int(input())

used = [False] * (1000000 + 1)
used[s] = True

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

i = 1
cur = s
while True:
    cur = f(cur)
    i += 1
    if (used[cur]):
        print(i)
        exit()
    else:
        used[cur] = True

Submission status: Accepted

Solution code:
import sys
s=int(input())
l=[]
def f(x):
  if x%2==0:
    return x//2
  else:
    return 3*x+1
  
l.append(s)

for i in range(10000000):
  s=f(s)
  l.append(s)
  for j in range(len(l)-1):
    if l[j]==s:
      print(i+2)
      sys.exit()

Submission status: Accepted

Solution code:
s = int(input())
a = []
a.append(s)
#E:f(n)=n/2 O:f(n)=3n+!

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

Submission status: Accepted

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

    a = [s]
    found = False
    i = 1
    ans = -1
    while not found:
        if a[i - 1] % 2 == 0:
            a.append(a[i - 1] / 2)
        else:
            a.append(3 * a[i-1]+1)

        for j in range(len(a) - 1):
            if a[j] == a[-1]:
                found = True
                ans = i + 1
                break

        i += 1

    print(ans)


if __name__ == '__main__':
    func()

Submission status: Accepted

Solution code:
s = int(input())

MAX = 1000000


def f(n):
    def odd(n):
        return 3*n+1

    def even(n):
        return n/2
    return odd(n) if n % 2 else even(n)


dic = {}


def a(n):
    if n == 1:
        dic[n] = s
        return dic[n]
    else:
        dic[n] = f(dic[n-1])
        return dic[n]


for m in range(1, MAX):
    am = a(m)
    if sum(1 if v == am else 0 for v in dic.values()) == 2:
        print(m)
        break

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
S=[]
S.append(s)
n=s
    
while (1):
    if n%2==0:
        n=n/2
    else :
        n=3*n+1
    if n in S:
        break
    S.append(n)
# print(S)
# print(n)
print(len(S)+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

m = s
s = {s}
ans = 1

for i in range(1000000):
    m = f(m)
    ans += 1
    if m in s:
        print(ans)
        exit()
    else:
        s.add(m)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(2,10**6):
    if s%2==0:
        s/=2
    else:
        s = 3*s+1
    if s in num_box:
        print(i)
        exit()
    num_box.append(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt=0
while cnt==0:
  if s[-1]%2==0:
    s.append(s[-1]//2)
  else:
    s.append(s[-1]*3+1)
  for i in range(len(s)-1):
    if s[-1]==s[i]:
      ans=len(s)
      cnt+=1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

s = int(input())
tmp = s
ctr = 1
array = [s]

while True:
    ctr += 1
    if tmp % 2 == 0:
        tmp = tmp // 2
    else:
        tmp = 3 * tmp + 1
    if tmp in array:
        print(ctr)
        exit()
    else:
        array.append(tmp)

Submission status: Accepted

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

s = int(input())
a = [s] #数列
i = 0 #進行マーカー(数列の添え字に対応)
flag = -1 #printするmの値をここにいれる
while flag == -1:#同じのが数列上に現れた時点でbreak
    another = function(a[i])#次のやつを算出
    for j in range(len(a)):#ダブってないかチェック
        if another == a[j]:#ダブってったらflagに記録してbreak
            flag = i + 2
            break
    a.append(function(a[i]))#数列に追加
    i = i + 1#次の項へ
print(flag)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
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()

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

Submission status: Accepted

Solution code:
def main():
    s = int(input())
    num = [s]

    ans = 1

    for i in range(1000000):
        if num[i] % 2 == 0:
            num.append(num[i]//2)
            if len(set(num)) == ans:
                print(ans+1)
                exit()
            else:
                ans = len(set(num))
        else:
            num.append(num[i]*3+1)
            if len(set(num)) == ans:
                print(ans+1)
                exit()
            else:
                ans = len(set(num))



main()

Submission status: Accepted

Solution code:
import bisect
s = int(input())
Data = []
Data.append(s)
n = 1
while True:
    n += 1
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
    index = bisect.bisect_left(Data,s)
    if index < len(Data) and Data[index] == s:
        break
    Data.insert(index,s) 
print(n)

Submission status: Accepted

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

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

for i in range(1000):
    if a[i] % 2:
        tmp = 3 * a[i] + 1
    else:
        tmp = a[i] // 2

    if tmp in a:
        print(i + 2)
        exit()
    else:
        a = a + [tmp]

print('Meh')

Submission status: Accepted

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

Submission status: Accepted

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

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

print(i)

Submission status: Accepted

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

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

print(i+1)

Submission status: Accepted

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

while True:
    prev_el = s[-1]
    next_el = 0

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

    s.append(next_el)

    if s.count(next_el) == 2:
        break

print(len(s))

Submission status: Accepted

Solution code:
#B - Collatz Problem(ABC116)
s=int(input())
A=[]
A.append(s)
c=0
while len(set(A))==len(A):
    if A[c]%2==0:
        A.append(A[c]/2)
    else:
        A.append(3*A[c]+1)
    c+=1
print(c+1)

Submission status: Accepted

Solution code:
a = [int(input())]
def fc(n):
    if n%2:
        p = 3*n+1
    else:
        p = n//2
    return p

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

Submission status: Accepted

Solution code:
s = int(input())

A = [0]*1000002

c4 = 0
c2 = 0
c1 = 0

m4 = 0
m2 = 0
m1 = 0

for i in range(1,1000002):
    if i == 1:
        A[i-1]=s
        #i += 1
    
    if A[i-1]%2==0:
        A[i] = A[i-1]/2
    else:
        A[i] = 3*A[i-1] + 1

for i in range(len(A)):
    if A[i] == 4:
        c4 += 1
        if c4 == 2:
           m4 = i
    elif A[i] == 2:
        c2 += 1
        if c2 == 2:
           m2 = i
    elif A[i] == 1:
        c1 += 1
        if c1 == 2:
           m1 = i

print(min(m1,m2,m4)+1)

Submission status: Accepted

Solution code:
def test():
    s = int(input())
    a = [s]
    b = []
    while 1:
        if s % 2 == 0:
            s = int(s / 2)
            a.append(s)
        elif s % 2 == 1:
            s = 3*s + 1
            a.append(s)
        if len(a) != len(set(a)):
            for i in range(len(a)-1):
                for j in range(i+1,len(a)):
                    if a[i] == a[j]:
                        b.append(j)
            break
    print(max(b)+1)


if __name__ == "__main__":
    test()

Submission status: Accepted

Solution code:
s = int(input())
anslist = {s}
m = 1
for i in range(100000):
    m += 1
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
    if s in anslist:
        print(m)
        break
    else:
        anslist.add(s)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    print(main())