Problem:


Score : 200 points

Problem Statement

A sequence a=\{a_1,a_2,a_3,......\} is determined as follows:

The first term s is given as input.

Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.

a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.

Find the minimum integer m that satisfies the following condition:

There exists an integer n such that a_m = a_n (m > n).

Constraints

1 \leq s \leq 100

All values in input are integers.

It is guaranteed that all elements in a and the minimum m that satisfies the condition are at most 1000000.

Input

Input is given from Standard Input in the following format:

s

Output

Print the minimum integer m that satisfies the condition.

Sample Input 1

8

Sample Output 1

5

a=\{8,4,2,1,4,2,1,4,2,1,......\}. As a_5=a_2, the answer is 5.

Sample Input 2

7

Sample Output 2

18

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

Sample Input 3

54

Sample Output 3

114



Sample input:
8


Sample output:
5

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
 
t = [False] * 1000001
i = 1
while True:
  if s <= 1000000 and t[s] == True:
    break
  t[s] = True
  i += 1
  if s % 2 == 0:
    s = s // 2
  else:
    s = 3 * s + 1
 
print(i)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = int(input())
l = [s]
a = s
for i in range(2, 1000000):
  if(a%2==0):
    b = int(a/2)
  else:
    b = 3*a+1

  if(b in l):
    print(i)
    break
  else:
    l.append(b)
    a = b

Submission status: Accepted

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

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

def main():
    s=int(input())
    p=s
    ss={s}
    for i in range(2,1000001):
        n=f(p)
        if n in ss:
            print(i)
            return
        ss.add(n)
        p=n

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def collatz(num: int) -> int:
    if num%2 == 0:
        return int(num/2)
    return 3*num+1

s = [int(input())]

cnt = 1
while True:
    s.append(collatz(s[-1]))
    cnt += 1
    if s[:-1].count(s[-1]):
        break

print(cnt)

Submission status: Accepted

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

m = 1
while True:
    if s in se:
        ans = m
        break
    se.add(s)
    m += 1
    s = 3*s+1 if s & 1 else s//2

print(ans)

Submission status: Accepted

Solution code:
s = int(input())
se = set([s])
cur = s
cnt = 1
while True:
    cnt += 1
    if cur%2==0:
        cur = cur//2
    else:
        cur = 3*cur + 1
    if cur in se:
        print(cnt)
        exit()
    se.add(cur)

Submission status: Accepted

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

s = int(input())

old = [s]
n = s
for i in range(2, 1000001):
  n = f(n)
  if n in old:
    print(i)
    exit()
  old.append(n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

def excute_min_m(a):
    m = len(a)
    for i,a_i in enumerate(a[:-1]):
        for j,a_j in enumerate(a[i+1:]):
            if a_i == a_j:
                m = min(j+i+2, m)
    print(m)

def solve(s: int):
    a = []
    a.append(s)
    tmp = s
    flag = False
    b = [4, 2, 1, 4]
    while not flag:
        if tmp%2==0:
            tmp = tmp//2
        else:
            tmp = 3*tmp + 1
        a.append(tmp)
        if len(a) >= 4 and a[-4:] == b:
            flag = True
    excute_min_m(a)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = int(next(tokens))  # type: int
    solve(s)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

def gusu(n):
    return(n/2)

def kisu(n):
    return(3*n + 1)

ss = [s]
count = 1

while True:
    n = ss[count-1]
    if n % 2 == 0:
        nn = gusu(n)
    else:
        nn = kisu(n)
    if nn in ss:
        print(count+1)
        break
    else:
        ss.append(nn)
        count += 1
#         print(ss)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
point = 0
kaisuu = 1
a = n

if n == 1:
    moto = 1
    point += 1
elif n == 2:
    moto = 2
    point += 1
elif n == 4:
    moto = 4
    point += 1
else:
    moto = 4
while point <2:
    if a % 2 == 0:
        a = a//2
        kaisuu += 1
        if a == moto:
            point += 1
    else:
        a = a*3+1
        kaisuu += 1
        if a == moto:
            point += 1

print(kaisuu)

Submission status: Accepted

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

Submission status: Accepted

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

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

    return(result)

while True:
        i+=1
        s= MY_function(s)
        P +=[s]

        if P.count(s) != 1:
            break
    
print(i)

Submission status: Accepted

Solution code:
import math
x = int(input())
res=[x]
for n in range(1000000):
  if len(res)!=1:
    if res.count(res[n])>1:
      break
  if res[n]%2==0:
    res.append(math.floor(res[n]/2))
  else:
    res.append(3*res[n]+1)

print(n+1)

Submission status: Accepted

Solution code:
start = int(input())
s = set([start])
cnt = 1
n = start
while(1):
    if (n % 2):
        n = 3*n + 1
    else:
        n = n//2
    cnt += 1
    if (n in s):
        break
    s.add(n)
print(cnt)

Submission status: Accepted

Solution code:
s = int(input())
def fn(n):
    if n%2 == 0:
        return n/2
    else:
        return 3*n+1
tmp = [s]
flag = 1
count = 1
while flag == 1:
    count += 1
    s = fn(s)
    tmp.append(s)
    if s in tmp[:-1]:
        break
print(count)

Submission status: Accepted

Solution code:
s = int(input())

def f(n) :
    if n % 2 == 0 :
        return n // 2
    else :
        return 3 * n + 1
        
done = set()
a = s
i = 1
while not a in done :
    done.add(a)
    a = f(a)
    i += 1
print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f(a):
    cnt=1
    while a != 4:
        cnt +=1
        if a%2==0:
            a /=2
        else:
            a=3*a+1
    return cnt+3

s=int(input())

if s!=1 and s!=2 and s!=4:
    print(f(s))
else:
    print(4)

Submission status: Accepted

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

count = 0
for i in range(1000001):
    tester = a_list[i]
    if a_list.count(tester) == 2:
        print(count + 1)
        break
    else:
        count += 1
        if tester % 2 == 0:
            tester = int(tester / 2)
            a_list.append(tester)
        else:
            tester = 3 * tester + 1
            a_list.append(tester)

Submission status: Accepted

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

cur = int(input())

ans = 1
ss = set([cur])

while True:
	ans += 1
	cur = f(cur)
	ss.add(cur)
	
	if ans > len(ss):
		break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(2,1000001):
    if s%2 == 0:
        s = s//2
        s_list.append(s)
    else:
        s = s*3 + 1
        s_list.append(s)
    if s_list.count(s) == 2:
        print(i)
        break

Submission status: Accepted

Solution code:
S = int(input())

INF = 10 ** 9 

list = [S]

con = 0

for i in range(INF):
	if S % 2 == 0:
		S = int(S / 2)
		list.append(S)
		con += 1

	else:
		S = (3 * S) + 1
		list.append(S)
		con += 1

	if S in list[:i]:
		break



print(con + 1)

Submission status: Accepted

Solution code:
a=int(input())
slis=[a]
for i in range(2,1000001):
	if a%2==0:
		a=a/2
		slis.append(int(a))
	elif a%2!=0:
		a=3*a+1
		slis.append(int(a))
	if slis.count(a)==2:
		print(i)
		break

Submission status: Accepted

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

Submission status: Accepted

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

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

def main():
    s = int(input())
    arr = [s]

    for _ in range(1000000):
        s = f(s)
        if s in arr:
            break
        arr.append(s)

    print(len(arr)+1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

    i += 1
    # print(a, i)
print(i)

Submission status: Accepted

Solution code:
s=int(input())

l=[s]
c=0

while s!=1 or c<2:
  s = 3*s+1 if s%2 else s//2
  if s==1:
    c += 1
  l.append(s)

for i in range(len(l)):
  if l.count(l[i]) >= 2:
    for j in range (i+1,len(l)):
      if l[i]==l[j]:
         print(j+1)
         exit()

Submission status: Accepted

Solution code:
import sys
s = int(input())
a = []
a.append(s)
N = 1000000

for i in range (0,N):
  if a[i] % 2 == 0:
    x = a[i] / 2
    a.append(x)
  else:
    x = 3 * a[i] + 1
    a.append(x)
  if a[i+1] in a[0:i]:
    print(i+2)
    sys.exit()

Submission status: Accepted

Solution code:
s = int(input())

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

print(count)

Submission status: Accepted

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

s=int(input())
i=1
T=set()
while True:
    if s in T:
        break
    else:
        T.add(s)
        s=f(s)
        i+=1

print(i)

Submission status: Accepted

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

Submission status: Accepted

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

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]
while len(a)==len(set(a)):
    if a[-1]%2==0:
        k=a[-1]//2
        a.append(k)
    else:
        k=3*a[-1]+1
        a.append(k)
else:
    print(len(a))

Submission status: Accepted

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

Submission status: Accepted

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

    if s in lst:
        break
print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

A = [s]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    s = int(input())
    a_list = [s]
    a = s
    index = 1
    while(True):
        index += 1
        new_a = func(a)
        if new_a in a_list:
            print(index)
            break
        a_list.append(new_a)
        a = new_a


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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict

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

ｓ = int(input())
ans = 2
d = defaultdict(lambda: 0)
d[s] += 1

while True:
    s = collatz(s)

    if d[s] != 0:
        print(ans)
        break

    d[s] += 1
    ans += 1

Submission status: Accepted

Solution code:
s = int(input())

c=1

if s==2 or s==1:
  print(4)
else:
  while s!=4:
    if s%2==0:
        s=s/2
    else:
        s=s*3+1
    c+=1
  print(c+3)

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())
l = [False for _ in range(10**6)]
for i in range(1, 10**5 + 1):
  if l[s]:
    print(i)
    exit()
  l[s] = True
  if s % 2 == 0:
    s = s // 2
  else:
    s = 3 * s + 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input().split()[0])
s_list = []
n = 1
a = s
i = 2
s_list.append(a)

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

ans = i
print(ans)

Submission status: Accepted

Solution code:
s = int(input())

def func(n):
    if n%2 == 0:
        return n/2
    else:
        return 3*n+1
    
l = [s]
m = 2

while 1:
    n = func(l[-1])
    if n in l:
        print(m)
        exit()
    l.append(n)
    m += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


def func():
    n = int(input())
    if n == 2:
        print(4)
        exit(0)
    if n == 1:
        print(4)
        exit(0)
    count = 0
    while n > 1:
        if n % 2 == 0:
            n /= 2
        else:
            n = (3 * n) + 1
        count += 1

    print(count + 2)


if __name__ == "__main__":
    func()

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())
cnt = 2
if s == 1 or s == 2 or s == 4:
  cnt += 2
else:
  while s != 1:
    cnt += 1
    if s%2:
      s = 3*s + 1
    else:
      s//= 2
print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
L=[N]
i=2
while True :
    if L[i-2] %2 == 0 :
        A=L[i-2]/2
    elif L[i-2] %2 == 1 :
        A=L[i-2]*3+1
    
    
    if A in L :
        print(i)
        break
    L.append(A)
    i+=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

a = [s]
for x in range(10000):
    i = a[-1]
    a.append(f(i))

if s == 1 or s == 2:
    print("4")
else:
    print(a.index(4)+4)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f(x):
    if x%2==0:
        return x//2
    else:
        return 3*x+1
s=int(input())
cnt=1
check={}
while s not in check:
    check[s]=1
    s=f(s)
    cnt+=1
print(cnt)

Submission status: Accepted

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

s = int(input())
cnt = 1
st = {s}


while len(st) == cnt:
    s = func(s)
    st.add(s)
    cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

a_1 = s
a_2 = 0
i = 2

dict = {}
dict[s] = 1
while(1000000):
  if a_1 % 2 == 0:
    a_2 = int(a_1 / 2)
  else:
    a_2 = 3 * a_1 + 1
#  print("a_1",a_1)
  if a_2 in dict:
    print(i)
    break
  else:
    dict[a_2] = i
  i += 1
  a_1 = a_2

Submission status: Accepted

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

for i in range(10**6):
    if s%2==0 and s//2 not in l:
        s//=2
        l.append(s)
    elif s%2==1 and s*3+1 not in l:
        s=s*3+1
        l.append(s)
    else:
        break

print(len(l)+1)

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    S = int(input())
    pool = [S]
    while True:
        if pool[-1]%2 == 0:
            nxt = pool[-1]//2
        else:
            nxt = pool[-1]*3+1
        if nxt in pool:
            print(len(pool)+1)
            return 0
        else:
            pool.append(nxt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def func(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1
s = int(input())
a = []
a.append(s)
for i in range(2,1000001):
    a.append(func(a[i - 2]))
    for j in range(len(a) - 2):
        if a[j] == a[i - 1]:
            print(i)
            exit()

Submission status: Accepted

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

    print(res+3)

Submission status: Accepted

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

s = int(input())
a = [s]
i = 1
while len(set(a)) == len(a):
    a.append(function(a[i-1]))
    i += 1
print(len(a))

Submission status: Accepted

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

s = int(input())
a = []
a.append(s)
i = 1
while len(set(a)) == len(a):
    a.append(function(a[i-1]))
    i += 1
print(len(a))

Submission status: Accepted

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    d = collections.defaultdict(list)
    n = int(input().rstrip('\n'))
    d[n]
    for i in range(2, 10 ** 10):
        if n % 2 == 0:
            n //= 2
        else:
            n = 3 * n + 1
        if n in d:
            print(i)
            exit()
        else:
            d[n]


if __name__ == '__main__':
    slove()

Submission status: Accepted

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


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

  if s in a:
    print(index)
    exit()
  else:
    index += 1
    a.add(s)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
d=defaultdict(lambda:False)
i=0
s=int(input())
while True:
  i+=1
  if d[s]:
    print(i)
    break
  d[s]=True
  if s%2==0:
    s//=2
  else:
    s=s*3+1

Submission status: Accepted

Solution code:
n=int(input())
ls=[0,0,0,n]
def col(num):
  if num%2==0:
    return num//2
  else:
    return 3*num+1
while True:
  ls.append(col(ls[-1]))
  if ls[-1]==ls[-4]:
    print(len(ls)-3)
    break

Submission status: Accepted

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

if s != 1:
    m = 1
    while True:
        c[s] = 1
        if s % 2 == 0:
            s = s//2
        else:
            s = 3*s + 1
        m += 1
        if c[s] == 1:
            break
else:
    m = 4

print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

exist_set = set()
index = 1

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

print(index)

Submission status: Accepted

Solution code:
import sys
s = int(input())
a_list = [0, s]
check_set = set([s])
counter = 2
while len(check_set) <= 10**9:
    if a_list[-1]%2 == 0:
        a_i = a_list[-1]/2
    else:
        a_i = a_list[-1]*3 + 1
    a = set([a_i])
    if a.issubset(check_set):
        print(counter)
        sys.exit()
    else:
        a_list.append(a_i)
        check_set.add(a_i)
    counter += 1

Submission status: Accepted

Solution code:
fn = int(input())

L = []
ans = 1
while fn not in L:
      L.append(fn)
      if fn%2 == 0:
            fn = fn/2
      else:
            fn = 3*fn + 1
      ans += 1
     
print(ans)

Submission status: Accepted

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

s = input()
l =[]
l.append(s);

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

    # 重複チェック
    for val in l:
        if val == s:
            keepCheck = False

    l.append(s)

print counter

Submission status: Accepted

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

if n in (4,2,1):
    print(4)
else:
    while n != 4:
        if n%2 == 0:
            n /= 2
        else:
            n = 3*n+1
        ct += 1
    
    print(ct+3)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.append(s)
m=s
for i in range(1,100000):
    n=main(m)
    a.append(n)
    m=n
    if len(set(a[:i]))==len(set(a[:i-1])):
        print(i)
        exit()

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

Solution code:
s = int(input())

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

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

    log.add(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
l=[]
def f(n):
    if n%2==0:
        return n//2
    else:
        return 3*n+1
while s not in l:
    #print(f"{len(l)} times")
    l.append(s)
    s=f(s)
    #print(f"list:{l}")
    #print(f"s{len(l)}:{s}")
print(len(l)+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]
i=1
while(1):
  i+=1
  x=f(a[-1])
  if (x in a):
    print(i)
    exit()
  a.append(x)

Submission status: Accepted

Solution code:
s=int(input())
def f(x):
  if x%2==0:
    return x/2
  else:
    return 3*x+1
  
counter=1
nums=[s]
temp=f(s)
while any([temp==nums[i] for i in range(counter)])==False:
  nums.append(temp)
  counter+=1
  temp=f(temp)
  
print(counter+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:
s=int(input())
def f(i):
    if i%2==0:
        return i//2
    else:
        return 3*i+1
a=[]
a.append(s)
for i in range(1,pow(10,7)):
    b=f(a[i-1])
    if b in a:
        print(i+1)
        break
    a.append(b)

Submission status: Accepted

Solution code:
s = int(input())
tmp = s
number = [s]
output = 1

while True:
    if tmp % 2 == 0:
        tmp //= 2
        output += 1

    else:
        tmp = tmp * 3 + 1
        output += 1

    if not tmp in number:
        number.append(tmp)

    elif tmp in number:
        print(output)
        break

Submission status: Accepted

Solution code:
def f(ai):
    if ai % 2 == 0:
        return ai/2
    else:
        return 3*ai + 1
s = int(input())
a = [s]
for n in range(2,1000002):
    tmp = f(a[len(a)-1])
    if tmp in a:
        print(len(a)+1)
        exit()
    else:
        a.append(tmp)

Submission status: Accepted

Solution code:
import sys
n = int(input())
def calc(x):
    if x%2 == 0:
        return int(x/2)
    else:
        return 3*x+1
li = [n]
flg = 0
ans = n
count = 1
while flg == 0:
    ans = calc(ans)
    if ans in li:
        print(count+1)
        flg += 1
        sys.exit()
    else:
        li.append(ans)
        count += 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:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    

s=int(input())
S=[s]
cnt=2

while s>0:
	if s%2==0:
		s=s//2
		if s in S:
			print(cnt)
			sys.exit()
		S.append(s)
	else:
		s=3*s+1
		if s in S:
			print(cnt)
			sys.exit()
		S.append(s)
	cnt+=1

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input())

a = [-1]
i = 1
while True:
    if i == 1:
        a.append(s)
    else:
        tmp = func(a[i-1])
        if tmp in a:
            print(len(a))
            break
        else:
            a.append(tmp)

    i += 1

Submission status: Accepted

Solution code:
def gusu(n):
    return n // 2
def kisu(n):
    return 3 * n + 1

s = int(input())
num = [s]
i = 2
while True:
    if(s % 2 == 0):
        j = gusu(s)
    else:
        j = kisu(s)
    if(j in num):
        break
    else:
        num.append(j)
        i += 1
        s = j
print(i)