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

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

temp = s
a = []
i = 0
flg = True
while flg == True:
    if i == 0:
        a.append(temp)
        i += 1
        continue
    temp = myfunction(temp)
    a.append(temp)
    if a[i] in a[:(i-1)]:
        print(i+1)
        break
    i += 1

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


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


def solve(s: int):
    a = [s]
    for i in range(10**7):
        s = f(s)
        # print(s)
        for av in a:
            if av == s:
                print(i+2)
                return
        a.append(s)
    return


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:
# -*- coding: utf-8 -*-

# わからなかったので､他の人の回答をパクりました｡
# リストの中身を金太郎飴みたいにその都度作って､
# 今まで作った飴と新しい飴が重複したときの番号を出力するやつは
# set()で作る｡

n = int(input())
a = set()
count = 0

a.add(n)

for i in range(2, 100000):

    if n % 2 == 0:
        n = n // 2
    else:
        n = 3 * n + 1

    if n in a:
        count = i
        break

    a.add(n)

print(count)

Submission status: Accepted

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

tab = [False]*1000001
now = int(input())
ind = 1
while not tab[now]:
    tab[now] = True
    now = func(now)
    ind += 1

print(ind)

Submission status: Accepted

Solution code:
s = int(input())
covered = set([s / 1])

while 1:
    s = s / 2 if s % 2 == 0 else s * 3 + 1
    
    if s in covered:
        print(len(covered) + 1)
        exit()

    else:
        covered.add(s)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 2019/04/14
# AtCoder Beginner Contest 116 - B

# Input
s = int(input())

# Init
sl = list()
lflg = True
sl.append(s)
cnt = 1

# Calc and Output
while(lflg):
    cnt += 1
    if s % 2 == 0:
        s = int(s / 2)
    else:
        s = 3 * s + 1

    for i in range(len(sl)):
        if s == sl[i]:
            print(cnt)
            lflg = False
            break
        
    sl.append(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
a = [s]
i = 0
while True:
    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(int(i+1))
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

numset = {s}
for i in range(2, 1000001, 1):
  
  if s % 2 == 0:
    s = s / 2
  else:
    s = (s * 3) + 1
  
  if {s} <= numset:
    print(i)
    break
  else:
    numset.add(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
progression = [s]
n = s
count = 1
while True:
    count += 1
    if n % 2 == 0:
        n = n/2
    else:
        n = 3 * n + 1

    if n in progression:
        break
    else:
        progression.append(n)

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
a = s
already = set()
already.add(a)
for i in range(10000000):
    if a % 2:
        a = 3 * a + 1
        if {a} <= already:
            print(i + 2)
            exit(0)
        already.add(a)
    else:
        a //= 2
        if {a} <= already:
            print(i + 2)
            exit(0)
        already.add(a)

Submission status: Accepted

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

s = int(input())
l = [s]
m = 1

while True:
    num = f(l[m-1])
    if num not in l:
        l.append(num)
        m += 1
    else:
        print(m + 1)
        break

Submission status: Accepted

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

s=int(input())
List=[s]
s=COL(s)
while s not in List:
  List.append(s)
  s=COL(s)
print(len(List)+1)

Submission status: Accepted

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

s = int(input())
hist = [s, ]
m = 1
while True:
    elem = f(hist[m-1])
    if elem not in hist:
        hist.append(elem)
        m += 1
    else:
        print(m+1)
        break

Submission status: Accepted

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

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

print(i + 1)

Submission status: Accepted

Solution code:
s=int(input())

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

    a_unique = list(set(a))
    if len(a) != len(a_unique):
        break


print(i)

Submission status: Accepted

Solution code:
s = int(input())

S = []
ans = 1

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

print(ans)

Submission status: Accepted

Solution code:
s=int(input())

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

hist=set([s])

while True:
	s = f(s)
	if s in hist:
		break
	hist.add(s)

print(1+len(hist))

Submission status: Accepted

Solution code:
def collatz(n):
	if n%2 == 0: return n/2
	else: return 3*n+1
s = int(raw_input())
lst = []
tmp = s
while(True):
	if tmp in lst:
		print len(lst)+1
		break
	else:
		lst.append(tmp)
		tmp = collatz(tmp)

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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())
memo = [0]*1000000
memo[0] = s
dic = {s:1}

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

for i in range(1, 1000002):
    memo[i] = f(memo[i-1])
    if dic.get(memo[i]):
        print(i+1)
        exit()
    else:
        dic[memo[i]] = 1

Submission status: Accepted

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

s = int(input())
#コラッツ予想を認める
n = 1
b4 = 0
b2 = 0
while s!=1:
    if s == 4:
        b4 = 1
    elif s==2:
        b2 = 1
    s = f(s)
    n += 1
k = 3
if b4 == 1:
    k = 1
elif b2 == 1:
    k = 2
print(n+k)

Submission status: Accepted

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

a = int(input())
A = [a]
m = 1
while True:
  m += 1
  a = f(a)
  A.append(a)
  if len(A) > len(set(A)):
    break
print(m)

Submission status: Accepted

Solution code:
s = int(input())

mp = dict()
mp[s] = 1
cnt = 1
while True:
    if s % 2 == 0:
        s = s//2
    else:
        s = 3*s + 1

    cnt += 1

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

print(cnt)

Submission status: Accepted

Solution code:
import sys
a = [int(raw_input())]
for i in range(1000000):
	a.append(a[i]/2 if a[i]%2==0 else 3*a[i]+1)
	if a.count(a[i+1]) > 1:
		print i + 2
		sys.exit()

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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


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

A = [s]
for i in range(1,1000000):
    A.append(f(A[i-1]))
    if len(list(set(A))) != i+1:
        print(i+1)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = int(input())


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


memo = [0, S]
result = -1

for m in range(2, 1000000):

    a = f(memo[m - 1])
    memo.append(a)

    # print(memo)

    if a in memo[1:m - 1]:
        result = m
        break

print(result)

Submission status: Accepted

Solution code:
# Collatz Problem

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

ai = [s]
for i in range(2, 10**9):
	if ai[-1] % 2 == 0:
		am = int(ai[-1]/2)
	else:
		am = int(3*ai[-1]+1)
	
	if am in ai:
		print(i)
		break
	else:
		ai.append(am)

Submission status: Accepted

Solution code:
a = int(input())

if a in [1, 2, 4]:
    print(4)
    exit(0)
ans = 1 + 3

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
	s = int(input())
	f = defaultdict(bool)
	i = 1
	f[s] = True
	while True:
		s = s//2 if s%2==0 else 3*s+1
		i += 1
		if f[s]:
			print(i)
			break
		f[s] = True


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

A = []

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

Submission status: Accepted

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

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

while True:
        f(a[-1])
        if is_unique(a) == False:
                print(len(a))
                break

Submission status: Accepted

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

Submission status: Accepted

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

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

print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

i = 1
a = set([s])
while True:
    i += 1
    t = collatz(s)
    if t in a:
        break
    a.add(t)
    s = t
print(i)

Submission status: Accepted

Solution code:
import sys
s = int(input())
lis = [0 for i in range(1000001)]
lis[s] = lis[s] + 1
def solve(s):
    m = 1
    while True:
        m = m + 1
        if s%2 == 1:
            s = 3*s + 1
        else:
            s = s//2
        if not lis[s] == 0:
            return m
            sys.exit()
        else:
            lis[s] = lis[s]+1
print(solve(s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
an = int(input())

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

Submission status: Accepted

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

s = int(input())
l = [s]
for i in range(1000000):
    a_i = func(l[-1])
    if a_i in l:
        l.append(a_i)
        break
    l.append(a_i)
print(len(l))

Submission status: Accepted

Solution code:
s = int(input())
t = 1
an = [s]
while t>0:
    if s%2 == 0:
        si = int(s/2)
    if s%2 == 1:
        si = 3*s+1
    for a in an:
        if si == a:
            print(len(an)+1)
            exit()
            t=0
    s = si
    an.append(si)

Submission status: Accepted

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


def solve(s: int):
    memo = [-1] * 1000001
    for i in range(1000001):
        if memo[s] >= 0:
            ret = i + 1
            break
        memo[s] = i
        if s % 2 == 0:
            s //= 2
        else:
            s = 3 * s + 1
    print(ret)
    return


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

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


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

Submission status: Accepted

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

s=int(input())
nlist =[]
tmp_in = collatz(s)
nlist.append(s)
nlist.append(tmp_in)
cnt = 1
while True:
    cnt += 1
    tmp_out = collatz(tmp_in)

    if tmp_out in nlist:
        print(len(nlist)+1)
        #print(nlist)
        break
    nlist.append(tmp_out)
    tmp_in = tmp_out

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

for i in range(1, 1000000 + 1):
    x = f(s)

    if x in l:
        print(i + 1)
        break

    l.append(x)
    s = x

Submission status: Accepted

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

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

Submission status: Accepted

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

li_a = []
i = 0
s = int(input())
li_a.append(s)
while True:
    temp = collatz(li_a[i])
    if temp in li_a:
        print(i+2)
        break
    else:
        li_a.append(temp)
    i += 1

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())
    A = [0]
    A.append(s)
    flag = True
    count = 0
    while flag:
        count += 1
        A.append(f(A[count]))
        for i in range(1, len(A)):
            for j in range(i + 1, len(A)):
                if A[i] == A[j]:
                    flag = False
                    print(j)
main()

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]
while 1:
    m = f(s)
    if a.count(m) > 0:
        print(len(a) + 1)
        exit()
    a.append(m)
    s = m

Submission status: Accepted

Solution code:
def find_match(a):
    for i in range(len(a) - 1):
        if a[i] == a[-1]:
            return len(a)
    return None


s = int(input())
a = [s]
i = 1
ans = 1000000
while(True):
    if a[-1] % 2 == 0:
        a.append(a[-1] // 2)
    else:
        a.append(3 * a[-1] + 1)
    x = find_match(a)
    if x is not None:
        if ans < x:
            break
        ans = x
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,1000000):
  c=b[i-1]
  if c%2==0:
    d=int(c/2)
  else:
    d=c*3+1
  if d in b:
    print(i+1)
    break
  b.append(d)

Submission status: Accepted

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

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

def solve(s: int):
    a = [s]
    # for i in range(1,10):
    #     a.append(f(a[i-1]))
    # print(a)
    while(True):
        t = f(a[-1])
        if(t in a):
            print(len(a)+1)
            sys.exit(0)
        else:
            a.append(t)
    return


# Generated by 1.1.3 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())
a=[]
a.append(s)
for i in range(1,10000000):
    a1=a[i-1]
    if(a1%2==0):
        tmp=int(a1/2)        
    else:
        tmp=3*a1+1
    
    if tmp in a:
        print(i+1)
        exit()

    a.append(tmp)

Submission status: Accepted

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

l = []
l.append(s)
for i in range(2,MAX+1):
    temp = f(s)
    if temp in l:
        print(i)
        exit()
    l.append(temp)
    s = temp

Submission status: Accepted

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

l = [0] * MAX
l[s] = 1
for i in range(2,MAX+1):
    temp = f(s)
    if l[temp]==1:
        print(i)
        exit()
    l[temp] = 1
    s = temp

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

a = []

a.append(s)

for i in range(1, 10000000):
    if f(a[i-1]) in a:
        print(i+1)
        exit()

    a.append(f(a[i-1]))

Submission status: Accepted

Solution code:
s = int(input())

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

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 = [s]
A = set([s])
for m in range(1, 1000000):
    a_m = f(a_s[-1])
    if a_m in A:
        ans = m + 1
        break

    a_s.append(a_m)
    A.add(a_m)

print(ans)

Submission status: Accepted

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

INF = 1000000

s = int(input())
a = [s] * (INF + 1)

answer = 0

for i in range(INF):
    if a[i] % 2 == 0:
        a[i+1] = int(a[i] / 2)
    else:
        a[i+1] = 3 * a[i] + 1
    for j in range(0,i):
        if a[i] == a[j]:
            answer = i+1
            break
    if answer != 0:
        break

print(answer)

Submission status: Accepted

Solution code:
s = int(input())

a = [s]

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

Submission status: Accepted

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

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())
a = [s]
i = 0
while True:
    next_insert = f(a[i])
    #print(a)
    if (next_insert in a) == True:
        break
    a.append(next_insert)
    i +=1
print(i+2)

Submission status: Accepted

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

Submission status: Accepted

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

arr = [s]

for i in range(1, 1000001):
    c = f(arr[i-1])
    if c in arr:
        re = i + 1
        break
    arr.append(c)

print(re)

Submission status: Accepted

Solution code:
from functools import lru_cache

appeared = [False] * 1000001


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


def a(s):
    yield s
    y = s
    while True:
        y = f(y)
        yield y


def main():
    s = int(input())
    seq_a = a(s)
    i = 1
    while True:
        elem = next(seq_a)
        if appeared[elem]:
            print(i)
            return
        else:
            appeared[elem] = True
            i += 1


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = int(input())
def f(n):
    if n%2 == 0:
        return n // 2
    else:
        return 3*n + 1
    
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:
s = int(input())

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

def main():
    a = [s]
    for n in range(1, 1000000):
        a.append(f(a[n-1]))
        if len(set(a)) != n+1:
            return n+1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
cnt = 1
box = set()
while not s in box:
	box.add(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 = [S,]
n = 1
def calc1():
  global n
  while True:
    if A[n-1] % 2 == 0:
      A.append(int(A[n-1] /2))
    else:
      A.append(int(3*A[n-1] +1))
    if A[n] in set(A[0:n]):
      return n+1
    n += 1
      
print(calc1())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

i = 0
a = []
a.append(s)
b = [0] * 10000

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

print(i + 1)

Submission status: Accepted

Solution code:
n=int(input())
log=[]
cnt=1
while n not in log:
    cnt+=1
    log+=[n]
    n=3*n+1 if n%2 else n//2
print(cnt)

Submission status: Accepted

Solution code:
s=int(input())
SUM=[s]
for i in range(10**7):
  if SUM[i]%2==1:
    SUM.append(SUM[i]*3+1)
  else:
    SUM.append(int(SUM[i]/2))
  if SUM.count(SUM[i])==2:
    print(i+1)
    break

Submission status: Accepted

Solution code:
def even(n):
    return n//2

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


s = int(input())
a = [s]
count = 1
while 1:
    if a[count-1] % 2 == 0:
        a.append(even(a[count-1]))
    else:
        a.append(odd(a[count-1]))
    count += 1
    if a[-1] in a[:-1]:
        print(count)
        quit()

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

while f(s) not in L:
    s = f(s)
    L.append(s)
    Count += 1
print(Count)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

s = read_int()[0]

A = [False for _ in range(1000000 + 1)]

def solve():
    a = s
    A[a] = True
    ans = 0
    m = 1
    while True:
        if a % 2 == 0:
            a = a // 2
            m += 1
            if A[a]:
                ans = m
                break
            else:
                A[a] = True
        elif a % 2 == 1:
            a = 3*a + 1
            m += 1
            if A[a]:
                ans = m
                break
            else:
                A[a] = True
    return ans


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    s = int(input())
    se = {s}
    for i in range(10 ** 6):
        s = next(s)
        if s in se:
            print(i + 2)
            return
        se.add(s)

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

main()