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

S = [s]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

    print(a.index(4) + 4)

Submission status: Accepted

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

Submission status: Accepted

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

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

a.append(int(s))

for i in range(10**10):
    if f(a[i]) in a:
        ans = i+2
        break
    a.append(int(f(a[i])))

print(ans)

Submission status: Accepted

Solution code:
s = int(input())
l = [s]
max=s
 
while 1:
  if s %2 == 0:
    l.append(s/2)
    s = int(s/2)
  else:
    l.append(3*s + 1)
    s = 3*s+1
    max = s
  
  if any(l.count(i) >= 2 for i in range(s+1)):
    print(len(l))
    break

Submission status: Accepted

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

while 1:
  if s %2 == 0:
    l.append(s/2)
    s = int(s/2)
  else:
    l.append(3*s + 1)
    s = 3*s+1
    max = s
  
  if any(l.count(i) >= 2 for i in range(s+1)):
    print(len(l))
    break

Submission status: Accepted

Solution code:
s=int(input())
a=s
num=[s]
if a==4 or a==1 or a==2:
  print(4)
  exit()
for i in range(2,10**7+1):
  if a%2==0:
    a=a//2
  else:
    a=3*a+1
  if a==4 or a==1 or a==2:
    ans=i+3
    break
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
L=set();i=4
while 1:
  if N in[1,2,4]:print(i);exit()
  N=N*3+1 if N%2 else N//2;i+=1

Submission status: Accepted

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

s = int(input())

i=0
sl = [s]
while True:
    n = func(sl[-1])
    if( n  in sl):
        print(i+2)
        exit()
    sl.append(n)
    #sl = list(set(sl))
    i+=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
def func(n):
  if n%2 == 1:
    return 3*n+1
  else:
    return n//2
def prog(N):
  if N == 1:
    return s
  else:
    a=s
    for i in range(1,N):
      a = func(a)
    return a

b=[]
for i in range(1,1000000):
  tmp = prog(i)
  if tmp in b:
    print(i)
    break
  else:
    b.append(tmp)

Submission status: Accepted

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

Submission status: Accepted

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

print(len(A)+1)

Submission status: Accepted

Solution code:
s = int(input())
ans_list = {1:4,2:4,3:9,4:4,5:7,6:10,7:18,8:5,9:21,10:8,11:16,12:11,13:11,14:19,15:19,16:6,17:14,18:22,19:22,20:9,21:9,22:17,23:17,24:12,25:25,26:12,27:113,28:20,29:20,30:20,31:108,32:7,33:28,34:15,35:15,36:23,37:23,38:23,39:36,40:10,41:111,42:10,43:31,44:18,45:18,46:18,47:106,48:13,49:26,50:26,51:26,52:13,53:13,54:114,55:114,56:21,57:34,58:21,59:34,60:21,61:21,62:109,63:109,64:8,65:29,66:29,67:29,68:16,69:16,70:16,71:104,72:24,73:117,74:24,75:16,76:24,77:24,78:37,79:37,80:11,81:24,82:112,83:112,84:11,85:11,86:32,87:32,88:19,89:32,90:19,91:94,92:19,93:19,94:107,95:107,96:14,97:120,98:27,99:27,100:27}
#トンデモナイクソコード
print(ans_list[s])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
ans = -999
ans_list = []
counter = 1
ans_list.append(s)
while   True:
    counter += 1
    if s%2 == 0:
        s = s//2
    else:
        s = 3*s +1

    if  s in ans_list:
        ans = counter
        break
    elif  counter > 1000000:
        break
    ans_list.append(s)
print(ans)

Submission status: Accepted

Solution code:
import math

s = int(input().strip())


def get_next(a):
    if a % 2 == 0:
        return math.floor(a / 2)
    else:
        return 3 * a + 1


flag = True
tmp = s
As  = [s]
counter = 1
while flag:
    nex = get_next(tmp)
    counter += 1
    tmp = nex
    if nex in As:
        flag = False
    As.append(nex)

print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
s=int(stdin.readline().rstrip())
al=[s]
while True:
    if al[-1]%2 == 0:
        new = int(al[-1]/2)
    else:
        new = int(3*al[-1]+1)
    if new in al:
        al.append(new)
        print(len(al))
        break
    al.append(new)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#116

n = int(input())

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

a = [n]
i = 0
while a.count(f1(a[i]))!=1:
    a.append(f1(a[i]))
    i+=1

print(i+2)

Submission status: Accepted

Solution code:
a = int(input())

l = [a]
b = a
c = 1
while True:
    if b % 2 == 0:
        b = int(b/2)
    else:
        b = 3 * b + 1

    c += 1

    if b in l:
        break

    l.append(b)

print(c)

Submission status: Accepted

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

for i in range(1, 1000001):
    new = func(a[i])
    if new in a:
        break
    
    a.append(new)
    
print(i+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

a = ['#']
i = 0
while i < 1000001:
  i += 1
  if i == 1:
    a.append(s)
  else:    
    if a[i-1]%2 == 0:
      ai = a[i-1] / 2
    else:
      ai = 3 * a[i-1] + 1
   
    if ai in a:
      print(i)
      exit()
    
    a.append(ai)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
###B - Collatz Problem
s = int(input())
cnt =  0
a = []

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

a_n = s
a_set = {a_n}
i = 1
while True:
    a_n_1 = (3 * a_n + 1 if a_n % 2 else a_n // 2)
    if a_n_1 in a_set:
        print(i + 1)
        break
    else:
        a_set.add(a_n_1)
        a_n = a_n_1
        i += 1

Submission status: Accepted

Solution code:
a = int(input())
def f(x):
    return (3*x+1) if x%2 else (x//2)
i = 1
already = set()
while 1:
    if a in already:
        break
    else:
        i+=1
        already.add(a)
        a = f(a)
print(i)

Submission status: Accepted

Solution code:
import sys

s = int(sys.stdin.readline().strip())
a = s
a_all = []
a_all.append(a)

def fnc_odd(n):
    return 3*n+1
    
def fnc_even(n):
    return int(n/2)
    
i = 2

while (i<120):
    if(a%2==0):
        a = fnc_even(a)
        a_all.append(a)
    else:
        a = fnc_odd(a)
        a_all.append(a)
    if(i>3 and a_all[(i-3)-1]==a):
        break
    i += 1
        
print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

  B = list(set(A))
  if(len(A) != len(B)):
    m = i
    break
  i += 1
  
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

a = [n]

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

Submission status: Accepted

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

def judge(a, numbers):
    for i in range(len(numbers)):
        if a == numbers[i]:
            return False

    return True

s = int(input())
number = s
numbers = []
count = 1

while judge(number, numbers):
    numbers.append(number)
    count += 1
    number = func(number)

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

l = [int(input())]
while True:
    x = f(l[-1])
    if x in l:
        print(len(l) + 1)
        break
    l.append(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
i = int(input())
seen = set()
seen.add(i)
temp = i
for x in range(2,1000000):
    if(temp%2 == 0):
        temp = temp/2
    else:
        temp = 3*temp+1
    if(temp in seen):
        print(x)
        break
    else:
        seen.add(temp)

Submission status: Accepted

Solution code:
s = int(input())
if s==1 or s==2 or s==4:
    print(4)
else:
    t = {}
    while True:
        if s not in t:
            t.setdefault(s, 0)
        t[s]+=1
        if (4 in t) and t[4]==2:
            break
        if s%2==0:
            s//=2
        else:
            s = 3*s+1
    print(sum(list(t.values())))

Submission status: Accepted

Solution code:
s = int(input())

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

array = []
for i in range(1,1000000):
  if i == 1:
    a_new = s
  else:
    a_new = f(array[-1])
  if a_new in array:
    print(i)
    break
  array.append(a_new)

Submission status: Accepted

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

s = int(input())
if((s == 1) or (s == 2)):
  print(4)
  exit()
  
cnt = 1
while(s != 1):
  s = func(s)
  cnt += 1
print(cnt + 1)

Submission status: Accepted

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

while True:
	if s in [1,2,4]:
		break
	else:
		s = collatz(s)
		i += 1

print(str(i+3))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(l[0])

Submission status: Accepted

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

while True:
	if s in [1,2,4]:
		break
	else:
		s = collatz(s)
		i += 1

print(str(i+3))

Submission status: Accepted

Solution code:
def main():
    s = get_params()
    collatz_seq = collatz(s)
    am_index = first_duplicate_index(collatz_seq)
    print(am_index+1)


def get_params():
    return int(input())


def collatz(s):
    return iterate(f, s)


def iterate(f, init):
    while True:
        yield init
        init = f(init)


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


def first_duplicate_index(seq):
    s = set()
    for e in seq:
        if e in s:
            return len(s)
        s.add(e)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s=int(input())
a=[]
a.append(0)
a.append(s)#初項a[1]
i=1
k=0
while k==0:
    if a[i]%2==0:
        a.append(a[i]/2)
    else:
        a.append(3*a[i]+1)
    i+=1
    for j in range(1,i):
        if a[j]==a[i]:
            print(i)
            k=1
            break

Submission status: Accepted

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

s = int(input())

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

print(len(ls)+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


# get from std-I/O.
def loading_inputs():
    S = raw_input()
    S = int(S)
    return S


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


def check_index(li, x, i, default=-1):
    if x in li: return i + 1
    else:       return default



def main():

    ans = 0
    an  = list()

    a_i = loading_inputs()
    an.append(a_i)
    for i in range(1, 10**6):

        a_i = an_func(a_i)
        ans = check_index(an, a_i, i)
        if(ans!=-1):
            break
        else:
            an.append(a_i)

    print ans



if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc116/tasks/abc116_b
s = int(input())
a = [s]
for n in range(1, 1000000):
    if a[n - 1] % 2 == 0:
        v = a[n - 1] // 2
    else:
        v = a[n - 1] * 3 + 1
    if a.count(v) == 1:
        print(n + 1)
        exit()
    else:
        a.append(v)

Submission status: Accepted

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

Submission status: Accepted

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


def collatz_problem(s: int) -> int:
    if s == 1 or s == 2 or s == 4:
        return 1 + 3

    i = 1
    while True:
        i += 1
        s = collatz(s)
        if s == 4:
            return i + 3

    return - 1


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
a_prev = s
a_old = {s:1}
for i in range(2,1000001):
    if a_prev % 2:
        a = int(3 * a_prev + 1)
    else:
        a = int(a_prev / 2)
    if a in a_old:
        print(int(i))
        break
    else:
        a_old[a] = 1
        a_prev = a

Submission status: Accepted

Solution code:
s = int(input())

ans = 0

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

exist = set()
while True:
    if s in exist:
        break
    exist.add(s)
    ans += 1
    s = f(s)

print(ans+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
a_list = [s]
INF = 10 ** 5
for i in range(INF):
    value = a_list[-1]
    if value % 2 == 0:
        next_value = value / 2
        if next_value in a_list:
            print(i + 2)
            break
        else:
            a_list.append(int(next_value))
    else:
        next_value = (3 * value) + 1
        if next_value in a_list:
            print(i + 2)
            break
        else:
            a_list.append(int(next_value))

Submission status: Accepted

Solution code:
s = int(input())

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

print(cnt)

Submission status: Accepted

Solution code:
s = int(input())

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

a = s
L = set()
i = 1
while not a in L:
    # print(a)
    L.add(a)
    a = f(a)
    i+=1

print(i)

Submission status: Accepted

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

Submission status: Accepted

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

## 最初の入力をリストに入れる
s = int(input())
s_list = [s]

while len(set(s_list)) == len(s_list):
    s_list.append(f(s_list[-1]))

print(len(s_list))

Submission status: Accepted

Solution code:
s = int(input())

numList = [s]
count = 0
ans = 2
while(True):
    nextNum = numList[count] / 2 if numList[count] % 2 == 0 else numList[count] * 3 + 1

    if nextNum in numList:
        print(ans)
        break
    numList.append(nextNum)
    count += 1
    ans += 1

Submission status: Accepted

Solution code:
def keisan(mylst, i):
    mylst.append(i)
    result = 0
    if i % 2 == 0:
        result = i/2
    else:
        result = 3*i+1

    if result in mylst:
        return len(mylst) + 1
    else:
        return keisan(mylst, result)

mylist = list()
s = int(input())
print(keisan(list(), s))

Submission status: Accepted

Solution code:
s, = (int(x) for x in input().split())

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

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

print(ncount+1)

Submission status: Accepted

Solution code:
from collections import Counter
s = int(input())

def func(n):
    if n % 2 == 0:
        return n // 2
    else :
        return 3 * n + 1
l = []
m = 0
l.append(s)
while True:
    l.append(func(l[m]))
    if 2 <= l.count(l[m+1]):
        print(m+2)
        break
    m += 1

Submission status: Accepted

Solution code:
s = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


s = int(input())

collatz = [s]
count = 1
continue_flg = True
while continue_flg:
    collatz_nums = set(collatz)
    count += 1
    s = f(s)
    for collatz_num in collatz_nums:
        if collatz_num == s:
            continue_flg = False
    collatz.append(s)
print(count)

Submission status: Accepted

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

s = set()
i = 1
a = int(input())
while True:
    if a in s:
        print(i)
        break

    s.add(a)
    a = f(a)
    i += 1

Submission status: Accepted

Solution code:
import sys
s = int(input())
a = [None]*2000000
r = [False]*2000000

def f(n):
  if n % 2 == 0:
    return n // 2
  else:
    return 3 * n + 1
a[1] = s
r[s] = True
for i in range(2, 2000000):
  a[i] = f(a[i-1])
  #print(i, a[i])
  if r[a[i]]:
    print(i)
    sys.exit()
  r[a[i]] = True

Submission status: Accepted

Solution code:
s=int(input())

chk=s
d={s:0}
for i in range(130):
    if chk%2: chk=chk*3+1
    else: chk//=2
    if chk in d:
        print(i+2)
        break
    else:
        d[chk]=0

Submission status: Accepted

Solution code:

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

def solve():
    s = int(input())
    l = []
    l.append(s)

    n = s
    count = 1
    while True:
        n = func(n)

        if n in l:
            print(count+1)
            return

        l.append(n)
        count += 1


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

s = int(input())

num = [s]
count = 0
while True:
    
    ans = calc(num[count])
    if ans in num:
        print(count+2)
        break
    num.append(ans)
    count += 1

Submission status: Accepted

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

Submission status: Accepted

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

a=int(input())
L=[a]
b=1
while True:
  L.append(f(L[len(L)-1]))
  S=list(set(L))
  if len(L)==len(S):
    b+=1
  else:
    print(b+1)
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

nums = set([s])
ans = 2
while True:
    s = s//2 if s%2 == 0 else 3*s+1
    if s in nums:
        print(ans)
        break
    else:
        nums.add(s)
        ans += 1

Submission status: Accepted

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

x = []
n = int(input())
x.append(n)
test = n

for i in range(1, 1000001):
    a = collatz(test)
    if a in x:
        print(i+1)
        exit()
    else:
        x.append(a)
        test = a

Submission status: Accepted

Solution code:
s = int(input())

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

    return n

m = 10**6
num_li = []
num_li.append(s)
for i in range(m):
    if(function(num_li[i]) in num_li):
        print(i+2)
        break
    else:
        num_li.append(function(num_li[i]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

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

Submission status: Accepted

Solution code:
s = int(input())

aset = set([s])
preva = s
for m in range(10**6):
  if preva % 2 == 0:
    if preva // 2 in aset:
      break
    else:
      aset.add(preva // 2)
      preva = preva // 2
  else:
    if preva * 3 + 1 in aset:
      break
    else:
      aset.add(preva * 3 + 1)
      preva = preva * 3 + 1
print(m+2)

Submission status: Accepted

Solution code:
def even(n):
  return n//2
def odd(n):
  return 3*n+1
s=input()
if s in"124":
  print(4)
  exit()
s=int(s)
c=0
while 1:
  if s%2==0:
    s=even(s)
  else:
    s=odd(s)
  c+=1
  if s==4:
    print(c+4)
    exit()

Submission status: Accepted

Solution code:
from collections import defaultdict

s = int(input())
L = defaultdict(int)
m = 1
a = s
L[a] += 1
while True:
	m += 1
	if a % 2 == 0:
		a = int(a / 2)
	else:
		a = 3 * a + 1
	L[a] += 1
	if L[a] == 2:
		print(m)
		break

Submission status: Accepted

Solution code:
import sys
n = int(input())
if n==4:
    print(4)
    sys.exit()
elif n==2:
    print(4)
    sys.exit()
elif n==1:
    print(4)
    sys.exit()
a = n
b = 0
i = 1
while True:
    if a%2==0:
        b = a//2
    else:
        b = 3*a+1
    i+=1
    a = b
    # print(a)
    if b ==4:
        break
print(i+3)