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())
a = [s]

def func(n):
  if n % 2 == 0:
    a.append(n//2)
  elif n % 2 == 1:
    a.append(3*n + 1)
  
i = 1
while True:
  func(a[-1])
  i += 1
  if a.count(a[-1]) == 2:
    break
  else:
    pass


print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    s = int(input())
    # a, b, c = map(int, input().split())
    # h = list(map(int, input().split()))
    # s = input()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = int(input())

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

coll = s
i = 1
while 1:
    if coll == 1 or coll == 2 or coll == 4:
        print(i  + 3)
        break
    coll = collatz(coll)
    i += 1

Submission status: Accepted

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

print(i+1)

Submission status: Accepted

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

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

print(i+1)

Submission status: Accepted

Solution code:
def main():
    def f(n):
        return 3 * n + 1 if n % 2 else n // 2
    s = int(input())
    a = [s]
    for i in range(1, 11**6):
        x = f(a[i-1])
        if x in a:
            return len(a) + 1; exit()
        a.append(x)


print(main())

Submission status: Accepted

Solution code:
s = int(input())

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

ans = 1
while s != 4:
    ans += 1
    if s % 2 == 0:
        s //= 2
    else:
        s *= 3
        s += 1

print(ans + 3)

Submission status: Accepted

Solution code:
n = int(input())

dp = [True]*(n*1000000)
dp[n] = False
res =1
while n <1000001:
    res +=1
    if n % 2 ==1:
        n = n*3+1
    else:
        n = n//2
    
    if dp[n]:
        dp[n] = False
    else:
        print(res)
        exit()

Submission status: Accepted

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

cnt=0

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

while s!=4:
  if s%2!=0:
    s=3*s+1
    cnt+=1
  elif s%2==0:
    s=s//2
    cnt+=1

if s==4:
  print(cnt+4)

Submission status: Accepted

Solution code:
a=int(input())
s=set()
i=1
while True:
    if a in s:
        print(i)
        break
    s|={a}
    if a%2==0:
        a>>=1
    else:
        a=3*a+1
    i+=1

Submission status: Accepted

Solution code:
S = int(input())
s, c = S, 1
result = [s]
while True:
    if s % 2 == 0:
        s = s // 2
    elif s % 2 == 1:
        s = s * 3 + 1

    result.append(s)
    c += 1
    if len(set(result)) < len(result):
        break

print(c)

Submission status: Accepted

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

if s==1 or s==2:
    print(4)
else:
    while TMP[-1]!=1:
        if TMP[-1] % 2 == 0:
            TMP.append(TMP[-1]//2)
        elif TMP[-1] % 2 != 0:
            TMP.append(3 * TMP[-1] + 1)
    print(len(TMP)+1)

Submission status: Accepted

Solution code:
s = int(input())

max_ = 1000000
chk = [0]*max_
a = s
i = 1
while i <= max_:
    if chk[a] == 0:
        chk[a] += 1
    else:
        print(i)
        exit()
    if a%2 == 0:
        a = int(a/2)
    else:
        a = 3*a + 1
    i += 1

Submission status: Accepted

Solution code:
# import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#    c.append(i)
# e1,e2 = map(int,input().split())
# f = list(map(int,input().split()))
#g = [input() for _ in range(a)]

da=True
ap=[a]
count=1
while da:
    if a%2==0:
        a=a//2
        ap.append(a)
    elif a%2==1:
        a=3*a+1
        ap.append(a)
    count+=1
    if len(set(ap))<len(ap):
        print(count)
        da=False

Submission status: Accepted

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

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

for i in range(1000000):
    if i == 0:
        a=[s]
    else:
        a.append(f(a[i-1]))
    
    if a.count(a[i]) == 2:
        print(i+1)
        sys.exit(0)

Submission status: Accepted

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

n = int(input())
arr = [n]
for i in range(10**6):
  nn = cor(n)
  if nn in arr:
    print(i+2)
    exit()
  else:
    arr.append(nn)
    n = nn

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

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

def main():
    s = int(input())
    dp=[s]
    counter=0

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

    while counter < 1000001:
        n=dp.pop()
        tmp = func(n)
        dp.append(n)
        dp.append(tmp)
        counter+=1
        if tmp==4:
            print(dp.index(tmp)+4)
            break

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
s = int(input())

def f(x):
    if x%2 == 0:
        return int(x/2)
    else:
        return 3*x + 1
i = 1
m_max = 1000000
b_s = s
b = set([s])
while i <= m_max:
    i += 1
    a = f(b_s)
    if a in b:
        break
    b.add(a)
    b_s = a
print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s = int(input())
f = [0 for _ in range(1000005)]
f[s] = 1
n = s
for i in range(1000005):
  if(n%2==0):
    n = int(n/2)
  else:
    n = int(3*n + 1)
  if(f[n] == 1):
    print(i+2)
    sys.exit()
  else:
    f[n] = 1

Submission status: Accepted

Solution code:
s = int(input())
L = []
for c in range(2 , 10 ** 6 + 1):
  L.append(s)
  if s % 2 == 0:
    s = s // 2
  elif s % 2 == 1:
    s = s * 3 + 1
  if s in L:
    break
print(c)

Submission status: Accepted

Solution code:
s = int(input())
a = s
c = 0
if a == 1 or a == 2:
  ans = 4
else:
  while a != 1:
    if a%2 == 0:
      a = int(a/2)
      c += 1
    else:
      a = int(3*a+1)
      c += 1
  ans = c+2
print(ans)

Submission status: Accepted

Solution code:
s = int(input())

count = 1
n = s
check = 0
list = [s]


for i in range(30000):
        if n % 2 == 0:
            n = n / 2
            list.append(n)
        else:
            n = n*3 + 1
            list.append(n)
        
        count = count + 1
        list.sort()
        for j in range(len(list) - 1):
            if list[j] ==list[j+1]:
                check = 1
                break
            
        if check == 1:
            break
        


print(count)

Submission status: Accepted

Solution code:
def resolve():
    s = int(input())
    hist = set([])
    idx = 1
    while True:
        if s in hist:
            print(idx)
            return
        hist.add(s)
        idx += 1
        if s%2==0:
            s //= 2
        else:
            s = 3*s + 1



if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [n]
index = 0

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

Submission status: Accepted

Solution code:

url = "https://atcoder.jp//contests/abc116/tasks/abc116_b"

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


def main():
    s = int(input())
    ans = [s]
    while True:
        tmp = calc(ans[-1])
        ans.append(tmp)
        if ans.index(tmp) != len(ans)-1:
            print(len(ans))
            break



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
a = [s]
i = 0
while True:
    i = i+1
    # 前回の値によって計算を変える。
    if a[i-1] % 2 == 0:
        n = a[i-1]//2
    else:
        n = 3*a[i-1]+1
    # 数列に同じ値が含まれているかどうか？
    if n in a:
	  	# 配列が0から始まるため、カウントアップ。
        print(i+1)
        break
    a.append(n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


s = int(input())
cnt = 0
a = [s]
while True:

    temp = f(a[cnt])

    if temp in a:
        print(len(a)+1)
        exit()
    a.append(temp)
    cnt += 1

Submission status: Accepted

Solution code:
# B - Collatz Problem
s = int(input())
a = s
S = set([s])
for i in range(2,10**6+1):
    a = a//2 if a%2==0 else 3*a+1
    if a in S:
        print(i)
        break
    S.add(a)

Submission status: Accepted

Solution code:
s = int(input())

if s < 3:
  print(4)
  exit(0)

cnt = 1
val = s
while True:
  if cnt > 1 and val == 1:
    break
  
  if val % 2 == 0:
    val = val//2
  else:
    val = val*3+1
    
  cnt += 1
             
print(cnt+1)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = int(readline())
    d = dict()
    d[s] = 1

    def solve():
        cur = s
        i = 1

        while True:
            i += 1
            if cur % 2 == 0:
                cur //= 2
            else:
                cur = 3 * cur + 1
            if d.get(cur):
                return i
            else:
                d[cur] = i

    print(solve())

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    a = int(input())
    a_dict = {a: 1}

    for i in range(2, 1000001):
        a = f(a)
        if a not in a_dict:
            a_dict[a] = 1
        else:
            print(i)
            break


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def func(x):
  if x%2==0:
    return x//2
  else:
    return 3*x + 1
A = [True for i in range(1000001)]
N = int(input())
count = 1
while A[N]:
  A[N] = False
  N = func(N)
  count += 1
print(count)

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

Submission status: Accepted

Solution code:
s = int(input())

sec = [s]
count = 1
while(s):
  if sec[-1]%2 == 0:
    sec.append(sec[-1]/2)
  else:
    sec.append(3*sec[-1]+1)
  count+=1
    
  if sec[-1] in sec[:-1]:
    print(count)
    break

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

s = int(stdin.readline().strip())
mem = []
a = s

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

Submission status: Accepted

Solution code:
s = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = int(input())

seq = set()
seq.add(s)

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

print(len(seq) + 1)

Submission status: Accepted

Solution code:
def collatz_problem(s):
    a = []

    a.append(s)
    counter = 1
    while True:
        counter += 1
        if s % 2 == 0:
            s /= 2
            a.append(s)
        else:
            s = s * 3 + 1
            a.append(s)
        for i in range(len(a)-1):
            if a[i] == s:
                return counter


def main():

    s = int(input())
    answer = collatz_problem(s)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = int(input())

a = [0,s]
for n in range(2,10**6+1):
  if a[n-1] % 2 == 0:
    an = a[n-1] // 2
  else:
    an = a[n-1] * 3 + 1
  
  if an in a:
    m = n
    break
  
  a.append(an)
  
print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')

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

print(i)

Submission status: Accepted

Solution code:
s=int(input())
a=[0]*10**6
a[0]=s

def f(x):
  if x%2==0:
    return x//2
  else:
    return 3*x+1
t=0 
while f(a[t])>0:
  p=f(a[t])
  if p in a:
    print(t+2)
    exit()
  a[t+1]=p
  t+=1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

while True:
  count = 0
  if S % 2 == 0:
    S = S / 2
    array.append(S)
  else:
    S = 3 * S + 1
    array.append(S)
  for i in range(len(array)):
    if S == array[i]:
      count += 1
      if count == 2:
        print(i + 1)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    m = 1
    pre = s
    st = {s}
    while True:
        m += 1
        if pre%2==0:
            tmp = pre/2
        else:
            tmp = 3*pre+1
        if tmp in st:
            print(m)
            return
        pre = tmp
        st.add(tmp)
    return

if __name__=='__main__':
    s = I()
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(100000):
  if a[i] % 2 == 0:
    b = a[i]/2
  else:
    b = 3*a[i]  + 1  
  a.append(b)
  count += 1
  if a.count(b) >1:
    break

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

i = 1
a_set = {s}

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

print(ans)

Submission status: Accepted

Solution code:
lis=[int(input())]
for i in range(1000):
    if lis[i]%2==0:
        a=lis[i]//2
        lis.append(a)
        def has_duplicates(x):
            return len(x) != len(set(x))
        if has_duplicates(lis)==True:
            break
    else:
        a=lis[i]*3+1
        lis.append(a)
        def has_duplicates(x):
            return len(x) != len(set(x))
        if has_duplicates(lis)==True:
            break
print(len(lis))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

numbers = []

for i in range(10000001):
    if i == 0:
        numbers.append(s)
    else:
        if numbers[-1] % 2 == 0:
            numbers.append(numbers[-1] // 2)
        else:
            numbers.append(3*numbers[-1]+1)
    if numbers.count(4) == 2 or numbers.count(2) ==2 or numbers.count(1) == 2:
        break

print(len(numbers))

Submission status: Accepted

Solution code:
import sys
import numpy as np
import numba
from numba import jit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@jit
def main(n):
  ans = [n]
  m = 0
  while not ans[m] in ans[:m]:
    if n%2 == 0:
      n /= 2
      ans.append(n)
    else:
      n = 3 * n + 1
      ans.append(n)
    m += 1
  return m+1
    
    
  
n = int(input())
print(main(n))

Submission status: Accepted

Solution code:
n=int(input())

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

Submission status: Accepted

Solution code:
a=int(input())
if a==1:
    print(4)
    exit()
elif a==4:
    print(4)
    exit()
elif a==2:
    print(4)
    exit()

ans=1
while True:
    if a==4:
        break
    elif a%2==0:
        a=a/2
        ans+=1
    else:
        a=3*a+1
        ans+=1

print(ans+3)

Submission status: Accepted

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

Submission status: Accepted

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

def main(s):
    temp = []
    count = 0
    ans = 0
    for i in range(s, 100000000):
        if i == s:
            a = i
        else:
            a = f(temp[count-1])
        
        temp.append(a)
        count += 1

        if a == 4 or a == 2 or a == 1:
            ans = count + 3
            break
    # print(temp)
    print(ans)


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

    main(s)

Submission status: Accepted

Solution code:
def f(n):
    if n%2==0: return n//2
    else: return 3*n+1
s = int(input())
v = set()
cnt = 1
while s not in v:
    v.add(s)
    s = f(s)
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
s = int(input())

ans = [s]

while True:
    if s % 2 == 0:
        s //= 2
    else:
        s = 3 * s + 1
    if ans.count(s) != 0:
        ans.append(s)
        break
    else:
        ans.append(s)


print(len(ans))

Submission status: Accepted

Solution code:
s = int(input())

a = [s]
used = [0] * (10**6+1)
used[s] = 1
for i in range(2, 10**6+2):
    if a[-1] % 2 == 0:
        a.append(val := a[-1]//2)
    else:
        a.append(val := 3*a[-1]+1)

    if used[val]:
        print(i)
        break
    else:
        used[val] = 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
visited = set()
count = 0

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
if s == 1 or s == 2:
    print(4)
    exit(0)
cnt = 1
while(1):
    cnt += 1
    #print(s)
    if s == 1:
        break
    elif s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
print(cnt)

Submission status: Accepted

Solution code:
import sys
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
s, = [int(num) for num in lines.pop(0).split(" ")]
count = 2
ss = set([s])
while True:
    if s % 2 == 0:
        next = s // 2
    else:
        next = 3 * s + 1
    if next in ss:
        break
    else:
        ss.add(next)
        s = next
        count += 1
print(count)

Submission status: Accepted

Solution code:
s=int(input())
S=[]
ans=0
for i in range(10**6):
    S.append(s)
    if s%2==0 :
        s=s//2
    else:
        s=3*s+1
    for j in range(i):
        if S[j]==s:
            ans=i+1
            break
    if ans!=0 :
        break            
print(ans+1)

Submission status: Accepted

Solution code:
s = int(input())

l = [0]*1000001
check = [False]*5000000

l[1] = s
ans = 0

for i in range(2, 1000000):
    if l[i-1] % 2 == 0:
        l[i] = round(l[i-1]/2)
    else:
        l[i] = 3*l[i-1]+1

for i in range(1,1000000):
    if check[l[i]]==False:
        check[l[i]]=True
    else:
        ans=i
        break

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
s = int(input())

ans = np.zeros(1000000)
a = s
ans[a] += 1
for i in range(1,1000000):
  if a % 2 == 0:
    a =  a//2
    ans[a] += 1
  else:
    a = 3*a+1
    ans[a] += 1
  if ans[a] == 2:
    print(i+1)
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [n]
cnt = 1
while True:
    if a[-1] % 2 == 0:
        x = [a[-1] // 2]
        if set(x) & set(a) == set():
            a.append(x[0])
        else:
            cnt += 1
            break
    else:
        x = [a[-1] * 3 + 1]
        if set(x) & set(a) == set():
            a.append(x[0])
        else:
            cnt += 1
            break
    cnt += 1
print(cnt)

Submission status: Accepted

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

a = [0]
a.append(int(input()))
for i in range(2,1000001):
    tmp = f(a[i-1])
    if tmp in a:
        break
    a.append(tmp)
#print(a)
print(i)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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


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

    d = dict()

    a = s
    d[a] = 1
    for i in range(2, 10000000):
        a = f(a)
        if a in d:
            ans = i
            break
        else:
            d[a] = i

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=int(input())
A=[s]
while s!=1:
    if s%2==0:
        s=s//2
        A.append(s)
    else:
        s=(3*s)+1
        A.append(s)
AA=A+[4,2,1]
if AA[0]==1 or AA[0]==2:
    print(4)
else:
    for m in range(len(AA)):
        for n in range(len(AA)):
            if AA[m]==AA[n] and m>n:
                M=m-1
                break
    print(M)

Submission status: Accepted

Solution code:
from collections import defaultdict

s = int(input())
D = defaultdict(int)
D[s] += 1
ans = 1

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

while True:
  s = f(s)
  ans += 1
  if D[s] == 1:
    print(ans)
    break
  D[s] += 1

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]
for i in range(10000000):
    a_last = f(a[i])
    if a_last in a:
        print(i+2)
        break
    a.append(a_last)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

v = [False] * 1000001
v[s] = True

i = 1
while True:
    i += 1
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
    
    if v[s]:
        break
    else:
        v[s] = True

print(i)

Submission status: Accepted

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

Submission status: Accepted

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



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

Submission status: Accepted

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

s = int(input())
c = 1
n = s
l = [s]

while True:
  m = calc(n)
  if l.count(m) == 1:
    break
  l.append(m)
  c += 1
  n = m
   
print(c+1)

Submission status: Accepted

Solution code:
s = int(input())

A = []
A.append(s)

while True:
    if s%2 == 0:
        s = s//2
    else:
        s = 3*s+1
    if s in A:
        print(len(A)+1)
        break
    else:
        A.append(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=int(input())
ct=1
if a==1:
  print(4)
  exit()
elif a==2:
  print(4)
  exit()
while a!=1:
  ct+=1
  if a%2==0:
    a=a//2
  else:
    a=3*a+1
else:
  ct+=1
  print(ct)

Submission status: Accepted

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

Submission status: Accepted

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