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 = []

def a(i):
    if i == 1:
        return s
    elif A[i-2]%2:
        return 3*A[i-2]+1
    else:
        return A[i-2]/2

i = 1

while True:
    if a(i) in A:
        print(i)
        break
    else:
        A.append(a(i))
        i += 1

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def collatz(n: int):
    if n%2:
        return 3*n+1
    else:
        return n//2
    
s = ni()
numset = set([s])

prev = s
cur = 0
idx = 1
for i in range(2 * 10**6):
    idx += 1
    
    cur = collatz(prev)
    prev = cur
    
    if cur in numset:
        break
    else:
        numset.add(cur)
        
print(idx)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

s = int(input())


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

a = [s]
tmp = s
for i in range(1,10**6):
    tmp = func(tmp)
    if tmp in a:
        print(i+1)
        exit()
    else:
        a.append(tmp)

Submission status: Accepted

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

for i in range(10**8):
    ai1=f(a[i])
    if ai1 in a:
        print(i+2)
        break
    else:
        a.append(ai1)

Submission status: Accepted

Solution code:
s = int(input())

#関数f(n)の定義
def f(n):
  if n % 2 == 0:
    n = n/2
  else:
    n = 3 * n + 1
  return n
    
#数列anの作成
a = []
c = []  # 比較用のaのコピー数列
i = 1
a.append(s)
c.append(s)
while i <= 10000000:
  a.append(f(a[i-1]))
  if a[i] in c:
    print(i +1)
    break
  c.append(a[i])
  i += 1

Submission status: Accepted

Solution code:
def is_unique(seq):
    return len(seq)==len(set(seq))

s=int(input())
lstA=[s]
cnt=1
while is_unique(lstA)==True:
    if s%2==0:
        s=s/2
    else:
        s=3*s+1
    lstA.append(s)
    cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

print(i+1)

Submission status: Accepted

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

    for i in range(2, 1000000):
      x = int(a[-1] / 2) if a[-1] % 2 == 0 else int(a[-1] * 3 + 1)
      if x in a:
        print(i)
        break
      else:
        a.append(x)
    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

	if f in a:
		break

	a.append(f)

print(len(a) + 1)

Submission status: Accepted

Solution code:
s=int(input())
c=0
for i in range(1,1000001):
    if i==1:
        c=s
    else:
        if c%2==0:
            c=c//2
        else:
            c=3*c+1
    if c==1:
        break
    if c==2:
        break
    if c==4:
        break
print(i+3)

Submission status: Accepted

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

history = {}

a = s
for i in itertools.count(2):
    history[a] = True
    if a % 2:
        a = a * 3 + 1
    else:
        a = a // 2

    if history.get(a):
        print(i)
        break

Submission status: Accepted

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

while(1):
  index += 1
  tmp_a = func(tmp_a)
  if tmp_a in a:
    break
  else:
    a |= {tmp_a}

print(index)

Submission status: Accepted

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

s = int(input())

n = s
for i in range(1000000):
  if n in [1,2,4]:
    print(i+4)
    break
  n = next_num(n)

Submission status: Accepted

Solution code:
s = int(input())


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

a = set()
a.add(s)
m = 1
while True:
    s = f(s)
    m += 1
    if s in a:
        break
    else:
        a.add(s)
print(m)

Submission status: Accepted

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

s = int(input())
data = set()
data.add(s)
for i in range(1000010):
    l = len(data)
    val = func(s)
    data.add(val)
    if l == len(data):
        print(i+2)
        break
    s = val

Submission status: Accepted

Solution code:
s = int(input())

f_n = [s]

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

print(len(f_n))

Submission status: Accepted

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


def main():
    s = int(input())
    memo = set([s])
    cnt = 1
    while True:
        cnt += 1
        s = f(s)
        if s in memo:
            break
        memo.add(s)
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
prev = int(input())
count = 1
found = False
my_dict = {}
my_dict[prev] = 1

while not found:
    prev = int(prev / 2) if 0 == prev % 2 else 3 * prev + 1
    count += 1
    if not prev in my_dict:
        my_dict[prev] = 1
    else:
        print(count)
        break

Submission status: Accepted

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

a = []
i = 0

#リストに同じ要素がある場合，Trueを返す．
def is_not_unique(seq):
    return len(seq)  != len(set(seq))

while True:
    if i == 0:
        a.append(s)
        i += 1
    elif is_not_unique(a):
        out_flag = i
        break 
    elif a[i-1] % 2 == 0:
        a.append(a[i-1] / 2)
        i += 1
    elif a[i-1] % 2 == 1:
        a.append(3 * a[i-1] + 1)
        i += 1
    
def out(x):
    print(x)

out(out_flag)

Submission status: Accepted

Solution code:
s = int(input())
max_m = 1000000
f = []
f.append(s)
set_f = set(f)

for i in range(1,max_m):
  n = f[i-1]
  if n % 2 == 0:
    f.append(n/2)
  else:
    f.append(3 * n + 1)
  set_f.add(f[i])
  if (len(f) != len(set_f)):
      print(len(f))
      break

Submission status: Accepted

Solution code:
s = int(input())

def f(x):
  if x % 2==0:
    return x//2
  else:
    return 3*x + 1
A = [s]    
flag = True
counter = 0
while flag:
  s = f(s)
  A.append(s)
  B = set(A)
  counter += 1
  if len(B) < len(A):
    flag = False
    print(counter+1)

Submission status: Accepted

Solution code:
s = int(input())

p = {s: 0}

count = 1
n = s
while True:
	count += 1
	if n%2 == 0:
		n = n/2
	else:
		n = (3*n) + 1

	if n in p:
		print(count)
		break
	else:
		p[n] = count

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(string):
    s = int(string)
    checks = set([])
    for _ in range(10**6):
        if s in checks:
            break
        else:
            checks.add(s)
            s = collatz(s)
    return str(len(checks) + 1)


if __name__ == '__main__':
    print(solve(input()))

Submission status: Accepted

Solution code:
#cording: utf-8

s = int(input())

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

progression = []
count = 0
while len(progression) == len(set(progression)):
    if count == 0:
        progression.append(10**5)
    if count == 1:
        progression.append(s)
    if count >= 2:
        f = func(progression[count-1])
        progression.append(f)
    count += 1

print(count-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a0 = int(input())
an = [a0]
def f(n):
        if n%2 == 0:
                return n/2
        else:
                return 3*n + 1
frag = 0
while frag == 0:
        an.append(f(an[-1]))
        for i in range(len(an)-1):
                if an[-1] == an[i]:
                        frag = 1
print(len(an))

Submission status: Accepted

Solution code:
a0 = int(input())
an = [a0]
def f(n):
        if n%2 == 0:
                return n/2
        else:
                return 3*n + 1
frag = 0
term = 1
while frag == 0:
        an.append(f(an[-1]))
        term += 1
        for i in range(len(an)-1):
                if an[-1] == an[i]:
                        frag = 1
                        break
print(term)

Submission status: Accepted

Solution code:
s = int(input())

a = [s]

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

	a.append(now)
	i += 1

Submission status: Accepted

Solution code:
f=1
g=0
s=[]
def suretsu(n):
    if n%2==0:
        return n/2
    else:
        return 3*n+1
s.append(int(input()))
while g==0:
    f+=1
    s.append(int(suretsu(s[len(s)-1])))
    for i in range(len(s)-2):
        if s[len(s)-1]==s[i]:
            g=1
            break
print(f)

Submission status: Accepted

Solution code:
def appear_twice(L):
	return len(L) == len(set(L))

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

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

i = 1
while appear_twice(a_seq):
	a_seq.append(f(a_seq[-1]))
	i = i + 1

print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def func(n):
    if n % 2 == 0:
        return n / 2

    return 3 * n + 1

if __name__ == "__main__":
    s = int(input())
    num_pool = set([s])
    m = 1
    while True:
        s = func(s)
        m += 1
        if s in num_pool:
            break
        
        num_pool.add(s)

    print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())


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


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

Submission status: Accepted

Solution code:
n = int(input())

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

l = []
ans = 0

while n not in l:
    l.append(n)
    ans+=1
    n = func(n)

print(ans+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

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

s = ri()

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

Submission status: Accepted

Solution code:

# coding: utf-8

# In[6]:


import numpy as np


# In[85]:


s = int(input())


# In[87]:


a = np.array([])
a = np.append(a, s)
count = 1

while True:
    count += 1
    if a[-1] % 2 == 0:
        a = np.append(a, a[-1]/2)
    else:
        a = np.append(a, a[-1]*3 + 1)
    
    if (a[-1] == a[:-1]).any():
        print(count)
        break

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

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

s = ri()

t = [0 for _ in range(1000000)]

ans = 0
a = s
for i in range(1,1000000):
    if t[int(a)] == 1:
        ans = i
        break
    else:
        t[int(a)] = 1
    a = f(a)

print(ans)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input())

num = genetarete_num(s)

if num == s:
    print(2)
    exit()

num_list = [s,num]

for i in range(3,1000001):
    num = genetarete_num(num)
    if num in num_list:
        print(i)
        exit()
    num_list.append(num)

Submission status: Accepted

Solution code:
s = int(input())
i = 1
d = set()
d.add(s)

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

Submission status: Accepted

Solution code:
s = int(input())

# 8 4 2 1 4 2 1 4
# 7 22 11 34 17
a = set()


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


def r(s):
    if s in a:
        print(len(a) + 1)
    else:
        a.add(s)
        s = f(s)
        r(s)


r(s)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys

import math

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

def sol(a):
    dp = [a]
    #print(dp)
    for i in range(1, 1000000+1):
        x = dp[i-1]
        ans = f(x)
        if ans in dp:
            #print(i, ans, dp)
            return i+1
        else:
            dp.append(ans)
    return None




do_submit = True
#do_submit = False
def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(int, line.split())) for line in lines]
    a = parsed_lines[0]
    return a[0]


if not do_submit:
    a= input_parse("""
    54
    """)
    print(sol(a))
else:
    # a, b, c = list(map(int, input().split()))
    # print(sol(a, b, c))
    a = list(map(int, input().split()))
    print(sol(a[0]))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, 1000):
    n = l[i - 1]
    if n % 2 == 0:
        l.append(int(n / 2))
    else:
        l.append(int(3 * n + 1))

# print(l[:100])
for i, v in enumerate(l):
    for j in range(i + 1, len(l) - i):
        if l[j] == v:
            print(j + 1)
            exit()

Submission status: Accepted

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

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

while(a.count('1') != 2):
  a.append(func(a[-1]))
  for i in range(len(a) - 1):
    if a[-1] == a[i]:
      print(len(a))
      exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

s = int(input())

val = s
mp = {s:1}
i= 1
while True:
  i+=1
  if val%2==0:
    val = val//2
  else:
    val = 3*val+1
  
  if val in mp:
    print(i)
    break
  else:
    mp[val] = 1

Submission status: Accepted

Solution code:
import sys
a = int(input())
numlist = [a]
for i in range(2,500):
    if a % 2 ==0:
        a //= 2
        numlist.append(a)
    else:
        a = a*3 + 1
        numlist.append(a)

kind = {}
count = 0
for s in numlist:
    count += 1
    if s in kind:
        print(count)
        sys.exit()
    else:
        kind[s] = 1

Submission status: Accepted

Solution code:
import sys
a = int(input())
numlist = [a]
for i in range(2,1000):
    if a % 2 ==0:
        a //= 2
        numlist.append(a)
    else:
        a = a*3 + 1
        numlist.append(a)
#print(numlist)
kind = {}
count = 0
for s in numlist:
    count += 1
    if s in kind:
        print(count)
        sys.exit()
    else:
        kind[s] = 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#abc116c

n=int(raw_input())
l=[]
while n not in l:
 l.append(n)
 if n%2==0:
  n/=2
 else:
  n=n*3+1
print len(l)+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)
ln = [s]

while True:
    ln.append(f(ln[-1]))
    if f(ln[-1]) in ln:
        break
    else:
        pass
print(len(ln)+1)

Submission status: Accepted

Solution code:
s = int(input())

def f(n):
  if n%2==0:
    return n/2
  else:
    return 3*n + 1
  
m=1
a=s
_set=set([a])

while True:
  m +=1
  a = f(a)
  if a in _set:
    print(m)
    break
  else:
    _set.add(a)
    continue

Submission status: Accepted

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

an = int(input())
i = 2
res = []
res.append(an)
while(True):
    am = f(res[-1])
    if am in res:
        print(i)
        break
    res.append(am)
    i += 1

Submission status: Accepted

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

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


for i in range(10000):
    e.append(f(e[i]))
    for j in range(0, len(e) - 1):
        if e[-1] == e[j] :
            print(len(e))
            break
    else:
        continue
    break

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
fuga = []
class B:
    def __init__(self):
        self.m = 1

    def hoge(self, n):
        fix = [_n for _n in fuga if n == _n]
        if fix:
            print(int(self.m))
            exit()
        if n >= 1000000:
            exit()
        fuga.append(n)
        self.m = self.m+1
        if n%2 == 0:
            self.hoge(n / 2)
        if n%2 == 1:
            self.hoge(3*n + 1)
b = B()
b.hoge(s)

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
s=int(input())
a=[s]
i=0
while True:
    if a[i]%2==0:
        a.append(int(a[i]/2))
        i+=1
    else:
        a.append(int(3*a[i]+1))
        i+=1
    if [j for j in set(a) if a.count(j)>1]:
        a_duplicate=sorted([j for j in set(a) if a.count(j)>1],key=a.index)
        break
a[a.index(a_duplicate[0])]=0
print(a.index((a_duplicate[0]))+1)

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

result = [s]
i = 0
while True:
    target = f(result[i])
    if target in result:
        print(i+2)
        break
    else:
        result.append(target)
        i += 1

Submission status: Accepted

Solution code:
s=int(input())
a=[s]
for i in range(1000000):
    if a[i]%2==0:
        a.append(int(a[i]/2))
    else:
        a.append(int(3*a[i]+1))
a_duplicate=sorted([j for j in set(a) if a.count(j)>1],key=a.index)
a[a.index(a_duplicate[0])]=0
print(a.index((a_duplicate[0]))+1)

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input())
a = [s]
i = 1
while True:
    n = collatz(a[i-1])
    try:
        index = a.index(n)
        print(len(a)+1)
        break
    except ValueError:
        a.append(n)
        i += 1

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def is_unique(seq):
    return len(seq) == len(set(seq))

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(a[i-1]*3 + 1)
    if not is_unique(a):
        print(i+1)
        break

Submission status: Accepted

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

Submission status: Accepted

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

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


for i in range(1000000):
    
    a.append(s)
    s = f(s)
    if len(set(a)) != c:
        break
    else:
        c += 1
print(c)

Submission status: Accepted

Solution code:
N = int(input())

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

print(ans+1)

Submission status: Accepted

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

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

i = 1
flag = True

while flag:
    i += 1
    ins = f(a[-1])
    for j in range(len(a)):
        if a[j] == ins:
            flag = False
            break
    a.append(ins)

print( i )

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

def main(s):
	a = [0]*10000000
	a[s] = 1
	i = 1
	while True:
		s = f(s)
		i+=1
		if a[s] == 1:
			print(i)
			break
		a[s] = 1
	return

main(int(input()))

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 = s * 3 + 1

print(len(a) + 1)

Submission status: Accepted

Solution code:
import collections
s=int(input())
count=[]
count.append(s)
def is_even(num):
	return num % 2 == 0
def calc(a):
	if is_even(int(a)):
		return (int((a)/2))
	else:
		return (int((a)*3+1))

check=(s) not in [1,2,4]
while (s) not in [1,2,4]:
	calc(s)
	s=calc(s)
	count.append(s)
	continue
else:
	print (len(count)+3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
k = 1
if a == 4 or a == 2 or a == 1:
  print(4)
  exit()
for i in range(1000000):
  if a % 2 == 0:
    a = a // 2
    k = k + 1
  else:
    a = 3 * a + 1
    k = k + 1
  if a == 4:
    print(k + 3)
    break

Submission status: Accepted

Solution code:
def find_min_m(s):
        a = s
        m = 1
        hist = set()
        while a not in hist:
                hist.add(a)
                a = a // 2 if a & 1 == 0 else 3 * a + 1
                m += 1
        return m


print(find_min_m(int(input())))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
an = []
an.append(s)
n = s
while an.count(4) != 2:
    if n % 2 == 0:
        n /= 2
        an.append(int(n))
    else:
        n = 3 * n + 1
        an.append(int(n))
if an.index(1) == 0:
            print(4)
elif an.index(2) == 0:
            print(4)
else:
    print(an.index(4) + 4)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc116/tasks/abc116_b

s = int(input())
c = {}

c[s] = 1

prev = s
i = 2
while True:
    prev = int(prev/2) if prev % 2 == 0 else 3 * prev + 1
    if prev in c:
        print(i)
        exit()
    # print(prev)
    c[prev] = i
    i += 1

Submission status: Accepted

Solution code:
n = raw_input()
n = int(n)

n_dict = {n:1}
cont = 1
while n_dict[n]<=1:
	if n%2==0:
		n = n/2
	else:
		n = 3*n+1
	n_dict[n] = n_dict.get(n,0)+1
	cont += 1
print(cont)

Submission status: Accepted

Solution code:
n, = map(int,input().split())

cnt = 1

while(n!=4 and n != 2  and n!=1):
    if (n%2==0):
        n //=2
    else:
        n = 3*n + 1
    cnt += 1
print(cnt + 3)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

n = s
i = 0
p = []
while True:
    i = i+1
    if i == 1:
        n = s
    elif n % 2 == 0:
        n = n/2
    else:
        n = n*3 + 1

    p.append(n)
    if len(set(p)) != len(p):
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
def f(n):
    if n%2==0:
        return(int(n/2))
    if n%2!=0:
        return(3*n+1)
a = []
a.append(s)
while(1):
    a_next = f(a[-1])
    a.append(a_next)
    for i in a[:-1]:
        if(a[-1]==i):
            break
    if(a[-1]==i):
        break
print(len(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
value = list()
value.append(s)

while len(value) == len(set(value)):
    if s % 2 == 0:
        s = int(s/2)
        value.append(s)
    elif s % 2 == 1:
        s = s*3 + 1
        value.append(s)
    
print(len(value))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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