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

l = [s]

def f(n):
    if n % 2 == 0:
        a = n // 2
    else:
        a = 3 * n + 1
    if a in l:
        return
    l.append(a)
    f(a)

f(s)
print(len(l) + 1)

Submission status: Accepted

Solution code:
s = int(input())

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

lis = [s]
now = s
for i in range(1000000):
    next = make_col(now)
    if next in lis:
        print(i+2)
        break
    else:
        lis.append(int(next))
        now = next

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

a = []
a.append(s)

for i in range(1000000):
    tmp = f(a[i])
    if tmp in a:
        ans = i
        break
    else:
        a.append(tmp)

print(ans+2)

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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

    result = []

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

    print(len(result) + 1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=int(input())
def f(k):
  if k%2==0:
    return k//2
  else:
    return 3*k+1
n=1
li=[]
if s==1 or s==2 or s==4:
  li.append(s)
while True:
  s=f(s)
  n+=1
  if s==1 and s not in li:
    li.append(s)
  elif s==2 and s not in li:
    li.append(s)
  elif s==4 and s not in li:
    li.append(s)
  elif s==1 and s in li:
    print(n)
    exit()
  elif s==2 and s in li:
    print(n)
    exit()
  elif s==4 and s in li:
    print(n)
    exit()

Submission status: Accepted

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

s = int(input())

box = [-1]*(int(1e6+1))

box[s] = 1

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

Solution code:
def collatz(n):
    if n%2==0:
        return int(n/2)
    else:
        return 3*n+1
    
a=int(input())
cnt=1
if a==1 or a==2:
    ans=cnt+3
else:
    while a !=4:
        a=collatz(a)
        cnt+=1
    ans=cnt+3  

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

while True:
	
	if i == 1:
		a.append(s)
	
	else:

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

	
	if a.count(a[-1]) >= 2:
		print(max([i for i, x in enumerate(a) if x == a[-1]]) + 1)
		exit()

	i += 1

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

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

    val = s
    ls = set([val])
    for m in range(2, 1000001):
        val = calc(val)
        if val in ls:
            print(m)
            exit()
        else:
            ls.add(val)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = int(input())

a = set()
n = s
c = 1

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


print(c)

Submission status: Accepted

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


s = int(input())
As = [s]
num = collatz(s)
while num not in As:
    As.append(num)
    num = collatz(num)

print(len(As) + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

tmp = [s] + [0]*(10**6 - 1)
for i in range(1,10**6+1):
    if tmp[i-1]&1:
        tmp[i] = 3*tmp[i-1]+1
    else:
        tmp[i] = tmp[i-1]//2
    if tmp.count(tmp[i]) == 2:
        print(i+1)
        exit()

Submission status: Accepted

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

ans=[s]
for i in range(1000000):
  temp = func(ans[-1])
  try:
    t = ans.index(temp)
    print(i + 2)
    break
  except:
    ans.append(temp)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = int(input())
a = {s}
a_i = s
def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1
ans = 1
for _ in range(10 ** 6 + 1):
    a_i = f(a_i)
    ans += 1
    if a_i in a:
        print(ans)
        break
    else:
        a.add(a_i)

Submission status: Accepted

Solution code:
s=int(input())
a=[-12345]*100000
for i in range(100000):
    
    a[i]=s
    if s%2==1:
        s=s*3+1
    else:
        s=s/2

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

Submission status: Accepted

Solution code:
s = int(input())
a = {s}
a_i = s


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


ans = 1
for _ in range(10**6+1):
    a_i = f(a_i)
    ans += 1
    if a_i in a:
        print(ans)
        break
    else:
        a.add(a_i)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

a = [s]
for i in range(1000001):
    #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: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
n=10**6
hist=[0]*(n+1)

a=s
ans=0
for i in range(n):
    if hist[a]==0:
        hist[a]+=1
    else:
        ans=i+1
        break
    if a%2==1:
        a=3*a+1
    else:
        a=a//2
print(ans)

Submission status: Accepted

Solution code:
def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3*n + 1
s = int(input())
a = [0]
a.append(s)
for i in range(2,10**7+1):
    x = a[-1]
    y = f(x)
    if y in a:
        print(i)
        break
    a.append(y)

Submission status: Accepted

Solution code:
s = int(input())
num = []
ans = 1

while True:
  num.append(s)
  ans += 1
  if s%2 == 1:
    s = 3*s + 1
  else:
    s = s/2

  if s in num:
    print(ans)
    exit(0)

Submission status: Accepted

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

while True:
    if a[-1] % 2 == 0:
        num = a[-1] / 2
    else:
        num = a[-1] * 3 + 1

    if num in a:
        print(len(a) + 1)
        break
    else:
        a.append(num)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s = int(input())
def collatz(n):
    if n%2 == 0:
        return (n//2)
    else:
        return 3*n+1
A = [s]
while True:
    A.append(collatz(A[-1]))
    for i in range(0,len(A)):
        for j in range(0,len(A)):
            if A[i] == A[j] and i!= j:
                print(j+1)
                sys.exit(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

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

Submission status: Accepted

Solution code:
import sys

s = int(input())

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

a = list()
a.append(s)
i = 1
r = 0
g = 0
while 1:
    n = f(a[i-1])
    for r in a:
        if r==n:
            print(i+1)
            sys.exit()
            
            
    a.append(n)
    i=i+1

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
inf = 10**6+1
visit = [0]*inf
s = int(input())
visit[s] = 1
cnt = 1
while True:
    cnt += 1
    if s % 2: s = s*3 + 1
    else: s = s // 2
    if visit[s]:
        print(cnt)
        exit(0)
    else: visit[s] = 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
c=set([s])
i=1
while True:
  i+=1
  if s&1:
    s=3*s+1
  else:
    s//=2
  if s in c:
    print(i)
    break
  c.add(s)

Submission status: Accepted

Solution code:
S = int(input())
se = {S}
x = S
for i in range(2, 1000001):  
  if x%2 == 0:
    x = x//2
  else:
    x = 3*x+1
  if x in se:
    print(i)
    exit()
  se.add(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s=[int(input())]
while True:
    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[i]==s[-1]:
            print(len(s))
            sys.exit()

Submission status: Accepted

Solution code:
import sys
import math
import itertools

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

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left, insort_left

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)


def main():
    s = INT()

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

        if bisect_left(l, a) == len(l):
            l.append(a)
        elif l[bisect_left(l, a)] == a:
            print(i + 2)
            sys.exit()
        else:
            insort_left(l, a)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def ff(a1, history, n):
    a2 = f(a1)
    n += 1
    if a2 in history:
        return n

    history.append(a2)

    return ff(a2, history, n)

s = int(input())
print(ff(s,[s],1))

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#問題の理解に少し時間を要した。理解できるとコードを書くのが楽しいアルゴリズム

s = int(input())

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

a = [s]

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

Submission status: Accepted

Solution code:
s = int(input())

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

a = [s]

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

Submission status: Accepted

Solution code:
s = int(input())

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

print(len(cnt))

Submission status: Accepted

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

    else:
            key = 3*(list[i-1])+1
            if key in list:
                print(i+1)
                exit()
            else:
                list.append(key)

Submission status: Accepted

Solution code:
S = int(input())

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

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

results = [S]
while True :
    if S % 2 == 0:
        S = even(S)
    else :
        S = odd(S)
    if S in results:
        results.append(S)
        break
    else :
        results.append(S)

print(len(results))

Submission status: Accepted

Solution code:
def check(s,i):
    if s in l:
        return i
    if s % 2 == 0:
        l.append(s)
        ans = check(s//2, i+1)
    else:
        l.append(s)
        ans = check(3 * s + 1, i + 1)
    return ans
s = int(input())
l = [s]
ans = 0
if s % 2 == 0:
    ans = check(s//2,2)
else:
    ans = check(3 * s + 1,2)
print(ans)

Submission status: Accepted

Solution code:
a1 = int(input())

calRList = []

calRList.append(a1)

i = 0
while True:
  if calRList[i] % 2 == 0:
    calRList.append(calRList[i]//2)
  else:
    calRList.append(3*calRList[i]+1)
  
  if calRList.count(calRList[i+1]) > 1:
    #index合わせ
    print((i+1)+1)
    break
  
  i+=1

Submission status: Accepted

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

a[0] = s
nums.add(s)
for i in range(1, 1000002):
    if a[i - 1] % 2 == 0:
        a[i] = a[i - 1] // 2
    else:
        a[i] = a[i - 1] * 3 + 1
    if a[i] in nums:
        ans = i + 1
        print(ans)
        break
    else:
        nums.add(a[i])

Submission status: Accepted

Solution code:
s = int(input())
a = {s}
ans = 1

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

    ans += 1

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

print(ans)

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

s = ni()

def collatz(x, i):
    if x <= 1:
        return i
    if x % 2 == 0:
        return collatz(x / 2, i + 1)
    else:
        return collatz(3 * x + 1, i + 1)

if s <= 2:
    print(4)
else:
    print(collatz(s, 1) + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def examA():
    L = LI(); L.sort()
    ans = L[0]*L[1]//2
    print(ans)
    return

def examB():
    def fun(s):
        if s%2==0:
            return s//2
        else:
            return s*3+1
    S = I()
    d = defaultdict(bool)
    d[S] = True; cur = 1
    while(True):
        cur +=1
        S = fun(S)
        if d[S]:
            break
        d[S] = True
    print(cur)
    return

def examC():
    return

def examD():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,ALPHABET, _ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 1e-9
alphabet = [chr(ord('a') + i) for i in range(26)]
ALPHABET = [chr(ord('A') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = [list(map(int, s.split()))[0] for s in open(0)][0]

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

cnt = 1
li = [a]
while True:
    a = fn(a)
    cnt += 1
    if a in li:
        print(cnt)
        break
    li.append(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ans = [N]
tmp=N
count=1
flag=True
while flag:
  count+=1
  if tmp%2==0:
    tmp=tmp/2
  else:
    tmp=3*tmp+1
  # print(tmp)
  if tmp in ans:
    flag=False
    break
  ans.append(tmp)
print(count)

Submission status: Accepted

Solution code:
s = int(input())
d = {s:1}
def func(n,i):
    tmp = 0
    if n%2 == 0:
        tmp = n//2
    else:
        tmp = 3*n + 1
    if tmp in d:
        return i+1
    else:
        d[tmp] = 1
        return func(tmp,i+1)
print(func(s,1))

Submission status: Accepted

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

    if a not in v:
        v.append(a)
    else:
        break;

print(i)

Submission status: Accepted

Solution code:
a = int(input())
v = {}
v[a] = True
ans = 1
while True:
    ans += 1
    if a % 2 == 1:
        a = (a * 3) + 1
    else:
        a = (a//2)
    if v.get(a): 
        break
    else:
        v[a] = True
 
print(ans)

Submission status: Accepted

Solution code:
a = int(input())
v = []
v.append(a)
t = 1
i = -1
while t == 1:
    i += 1
    if v[i] % 2 == 1:
        b = (v[i] * 3) + 1
        if b not in v: 
            v.append(b)
        else:
            v.append(b)
            break;
            ans = i
    else:
        b = (v[i]//2)
        if b not in v:
            v.append(b)
        else:
            v.append(b)
            break;
            ans = i

print(i+2)

Submission status: Accepted

Solution code:

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

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

print(i)

Submission status: Accepted

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

ans = 1
n_tmp = s
while True:
  if history.setdefault(str(n_tmp), 0) > 0:
    break
  else:
    history[str(n_tmp)] = 1
  #
  ans += 1
  if n_tmp % 2 > 0:
    n_tmp = 3 * n_tmp + 1
  else:
    n_tmp = n_tmp // 2
    
print(ans)

Submission status: Accepted

Solution code:
def p_b():
    s = int(input())
    u = {s}
    for i in range(1, 1000001):
        if s & 1 == 0:
            s //= 2
        else:
            s = 3 * s + 1
        if s in u:
            print(i + 1)
            exit()
        else:
            u.add(s)

            
p_b()

Submission status: Accepted

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

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

   if(fn in a):
      print(len(a) + 1)
      break
   else:
      a.append(fn)

Submission status: Accepted

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

print(cnt+1)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

s = int(sys.stdin.readline().rstrip())

def main():
    a_m = set([1, 2, 4])
    a = s
    for i in range(1, 10**6-2):
        if a in a_m:
            return i + 3
        a = f(a)

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

Submission status: Accepted

Solution code:
import sys

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

s = int(sys.stdin.readline().rstrip())

def main():
    a = s
    res = set([a])
    for i in range(2, 10**6+1):
        a = f(a)
        if a in res:
            return i 
        res.add(a)

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

Submission status: Accepted

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


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


for i in range(1000000):
    if i == 0:
        l.append(s)
    else:
        l.append(f(l[i - 1]))

count = [0] * len(l)
for i in range(len(l)):
    count[int(l[i])] += 1
    if 1 < count[int(l[i])]:
        print(i+1)
        break

Submission status: Accepted

Solution code:
#%%
s = int(input())

count = 2
a = s
a_list = [a]
while True:
    if a % 2 == 0:
        an = a // 2
    else:
        an = 3 * a + 1

    if an in a_list:
        break
    else:
        count += 1
        a_list.append(an)
        a = an

print(count)

Submission status: Accepted

Solution code:
n = int(input())
k = set()
i = 1
while True:
  if n in k: break
  k.add(n)
  i += 1
  n = 3*n+1 if n&1 else n//2
  
print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    s=int(input())
    S=set()
    S.add(s)
    n=s
    for i in range(2,10**7):
        if n%2:
            n=3*n+1
        else:
            n=n//2
        if n in S:
            print(i)
            exit()
        S.add(n)
            

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def up(num, li):
    if num % 2 == 0:
        next_num = num // 2
    else:
        next_num = 3 * num + 1
    if num in li:
        return len(li) + 1
    li.append(num)
    return up(next_num, li)

print(up(int(input()), []))

Submission status: Accepted

Solution code:
s = int(input())

d = {s: 0}

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

    if s in d:
        break
    else:
        d[s] = 1

print(len(d)+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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


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

Submission status: Accepted

Solution code:
s = int(input())

a = [s]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
a=set()
a.add(s)
cnt=2

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

Submission status: Accepted

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

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

for i in range(2, 1000000):
  a=calc(F[i-1])
  if a in F:
    print(i)
    break
  else:
    F.append(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
data=[0]*(10**6+100)
data[s]=1
cnt=1
while True:
    if s%2==0:
        s//=2
    else:
        s=3*s+1
    cnt+=1
    if data[s]==1:
        break
    data[s]=1
print(cnt)

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(i, s):
    if i == 1:
        return s
    return f(a(i - 1, s))


i = 1
a_l = []
while True:
    a_l.append(a(i, s))
    if len(a_l) != len(set(a_l)):
        print(i)
        break
    i += 1

Submission status: Accepted

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

S = int(sys.stdin.buffer.readline())

seen = [0] * 1000001

a = S
i = 0
while not seen[a]:
    seen[a] = 1
    if a % 2 == 0:
        a //= 2
    else:
        a = 3 * a + 1
    i += 1
print(i + 1)

Submission status: Accepted

Solution code:
# coding: utf-8

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

first = int(input())

log = {first: 0}

prev = first
for i in range(1, 1000000 + 1):
    num = f(prev)
    if num in log:
        print(i + 1)
        break
    log[num] = i
    prev = num

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())]
def f(x):
    if x%2==0:
        return x//2
    else:
        return 3*x+1

for i in range(1,1000001):
    a.append(f(a[i-1]))
    if a.count(f(a[i-1]))==2:
        print(i+1)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
check = ""
count = 1
result = [s]
while check != "OK":
    if s % 2 == 0:
        s = s/2
    else:
        s = 3*s + 1
    count += 1
    s = int(s)
    result.append(s)
    for i in range(len(result)-1):
        if result[i] == s:
            check = "OK"
        else:
            pass
        
print(count)