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:
aList = [int(input().strip())]
while(True):
    aList.append(aList[-1] // 2 if aList[-1] % 2 == 0 else 3*aList[-1] + 1)
    if(aList.index(aList[-1]) != len(aList) - 1):
        break
print(len(aList))

Submission status: Accepted

Solution code:
s=int(raw_input())
f=lambda x:(x/2)*(x%2==0)+(3*x+1)*(x%2==1)
r=[s]
map(lambda x:r.append(f(r[-1])),xrange(1,300))
for i in xrange(300,1,-1):
  try:
    s=r[:i].index(r[i])
    rs=i+1
  except:
    pass
print rs

Submission status: Accepted

Solution code:
import sys

def main(inp):
    A=[inp]
    s=inp
    while True:
        if(s%2==0): s=s/2
        else: s=3*s+1
            
        for i in range(len(A)):
            if(s==A[i]):
                return len(A)+1
                break
        
        A.append(s)

print(main(int(next(sys.stdin))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s = int(s)
number = 1
l = list()
l.append(s)
while 1:
	if s%2 == 0:
		s = s / 2
	else:
		s = 3 * s + 1
	number=number+1
	if s in l:
		print(number)
		break
	else:
	    l.append(s)

Submission status: Accepted

Solution code:
def f(n):
    if n%2==0:
        return n//2
    else:
        return 3*n+1
s=int(input())
a=list()
i=1
while 1:
    if s in a:
        break
    a.append(s)
    s=f(s)
    i+=1
print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def main() :
    # 10^6なので愚直でいいはず。
    s = int(input())
    li = [s]
    loop_count = 1
    while(True) :
        loop_count += 1
        n = f(s)
        if (li.count(n) > 0) :
            print(loop_count)
            return
        else :
            li.append(n)
            s = n

    

main()

Submission status: Accepted

Solution code:
class Collatz_Problems:
	def __init__(self,n):
		self.n = [n]
	def calc_even_odd(self):
		if self.n[-1] % 2 == 0:
			self.n.append(self.n[-1]/2)
			
		elif self.n[-1] % 2 != 0:
			self.n.append(3*self.n[-1]+1)

	def compare(self):
		for i in range(0,len(self.n)-1):
			if self.n[-1] == self.n[i]:
				return True
        
n = int(raw_input().strip())
num = Collatz_Problems(n)
i = 0
while i != 100:
	num.calc_even_odd()
	if num.compare():
		print(len(num.n))
		break

Submission status: Accepted

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

Submission status: Accepted

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

#print(a)
i = 0

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

    if a[i+1] in a[:i+1]:
        break
    i += 1

print(i+2)

Submission status: Accepted

Solution code:
s = int(input())
query = [s]
tmp = s
count = 1
ans = -1
while tmp != 0:
 count += 1
    
 if tmp%2 == 0:
  tmp = tmp//2
  if tmp in query:
    break
  query.append(tmp)
 else:
  tmp = tmp*3 +1
  if tmp in query:
   break
  query.append(tmp)

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f(s):
    if s == 2 or s == 1:
        print(4)
        exit()

    a=[s]
    i=0
    while not s==4:
        if a[i]%2==0:
            s//=2
            a+=[s]
        else:
            s=3*s+1
            a+=[s]
        i+=1
    return i+4
print(f(int(input())))

Submission status: Accepted

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


s = int(input())
memory = dict()

n = s
count = 1
while True:
    if n in memory.keys():
        break

    memory[n] = True
    n = collatz(n)
    count += 1

print(count)

Submission status: Accepted

Solution code:
def oddFun(num):
	return num//2
 
def evenFun(num):
	return (3 * num) + 1
 
s = int(input())
set = set()
index = 1
while s not in set:
	set.add(s)
	if s % 2 == 0:
		s = oddFun(s)
	else:
		s = evenFun(s)
	index+=1

print(index)

Submission status: Accepted

Solution code:
n=int(input())
A=[]
A.append(n)
for i in range(2,10**6):
  if n%2==0:
    n/=2
  else:
    n=3*n+1
  if n in A:
    print(i)
    exit()
  else:
    A.append(n)

Submission status: Accepted

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

    ans = solve(s)
    print(ans)


def solve(s):
    """
    数列 a={a1,a2,a3,......} は、以下のようにして定まります。
    初項 s は入力で与えられる。

    関数 f(n) を以下のように定める
    n が偶数なら f(n)=n/2
    n が奇数なら f(n)=3n+1

    i=1 のとき ai=s
    i>1 のとき ai=f(a(i−1))

    このとき、次の条件を満たす最小の整数 mを求めてください。
    a(m) = a(n) (m>n) を満たす整数 n が存在する。
    制約: 1 ≦ s ≦ 100
    入力はすべて整数である。
    a のすべての要素、および条件を満たす最小の m は 1000000 以下となることが保証される。
    """
    bef_a = s
    d = {s: None}

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

    for i in range(2, 1000000 + 1):
        bef_a = f(bef_a)
        if bef_a in d:
            return i

        d[bef_a] = None


if __name__ == '__main__':
    main()

Submission status: Accepted

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

# AtCoder Beginner Contest 116：B - Collatz Problem


def f(n):
    if n & 1 == 1:
        return n+n+n+1
    else:
        return n>>1


def main():
    s = int(raw_input().strip())

    hist = [s]
    i = 2
    while True:
        n = f(s)
        if n in hist:
            print i
            exit()
        hist.append(n)
        s = n
        i += 1


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = int(input())


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


a = [s]
while True:
    a.append(f(a[-1]))
    if a[-1] in a[:-1]:
        print(len(a))
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

while True:
    m = a[-1]

    if m % 2 == 0:
        a_m = m / 2
    else:
        a_m = 3 * m + 1
        
    for index, a_n in enumerate(a):
        if a_m == a_n:
            ans = len(a) + 1
            print(ans)
            exit()

    a.append(a_m)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a = I()
    s = set([a])
    i = 2
    while 1:
        if a % 2 == 0:
            a //= 2
        else:
            a = a * 3 + 1
        if a in s:
            return i
        s.add(a)
        i += 1

    return -1



print(main())

Submission status: Accepted

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

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

print(cou)

Submission status: Accepted

Solution code:
s=int(input())

a=[]
a.append(s)

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

Submission status: Accepted

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

count = 1
while True:
    if s == 1 or s == 2 or s == 4:
        print(count + 3)
        break
    else:
        s = f(s)
    count += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    s = int(input())
    al = [s]
    prev = s

    while True:
        new_a = fn(prev)
        if new_a in al:
            break
        al.append(new_a)
        prev = new_a
    print(len(al) + 1)

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

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
s=int(input())

x=[]

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


count=0
if(s>4 or s==3):
    while(True):
        s=collatz(s)
        count+=1
        if(s==4):
            break


    
        

print(count+4)

Submission status: Accepted

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


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

for x in range(1000000):
    tmp = f(a_i[x])
    
    if tmp in a_i:
        print(x+2)
        break
    
    a_i.append(tmp)

Submission status: Accepted

Solution code:
s=int(input())
dp=[False]*1000000
dp[s]=True
for i in range(2,1000002):
    if s%2:
        s=s*3+1
    else:
        s//=2
    if dp[s]:
        print(i)
        break
    dp[s]=True

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = int(input())
A = set([])

while S not in A:
    A.add(S)
    if S % 2 == 0:
        S = S // 2
        
    else:
        S = 3 * S + 1
        
print(len(A) + 1)

Submission status: Accepted

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

s = int(input())
l = []
n = 1
while(1):
  if s in l:
    print(n)
    quit()
  l.append(s)
  s = f(s)
  n += 1

Submission status: Accepted

Solution code:
s = int(input())
a = [0] * 1000000
a[0] = s
m = 0
i = 0
while i < 1000000:
	if a[i] % 2 == 0:
		a[i + 1] = a[i] // 2
	else:
		a[i + 1] = a[i] * 3 + 1
	for j in range(i + 1):
		if a[j] == a[i + 1]:
			m = i + 2
			break
	if m > 0:
		break
	i += 1
print(m)

Submission status: Accepted

Solution code:
def f(n):
    # 数列の規則
    if n % 2 == 0:
        return int(n / 2)
    else:
        return 3 * n + 1
 
if __name__ == "__main__":
    s = int(input())
    if s == 2 or s == 1:
        print(4)
        exit()
    for m in range(1, 1000000): # m < 1000000となるので
        if s == 4:
            print(m + 3)
            break
        s = f(s)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = int(input())


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


a = [s]
used = [None] * 1000000
used[s] = True
while True:
    x = f(a[-1])
    if used[x] is not None:
        print(len(a) + 1)
        exit()
    a += [x]
    used[x] = True

Submission status: Accepted

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

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

for i in range(100000):
    for j in range(i + 1,100000):
        if nums[i] == nums[j]:
            print(j + 1)
            break
    else:
        continue
    break

Submission status: Accepted

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

Submission status: Accepted

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

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

print(len(a) + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())

kizon=[]

while(True):
  if s not in kizon:
    kizon.append(s)
    if s%2==1:
      s=3*s+1
    else:
      s=s/2
  else:
    print(len(kizon)+1)
    exit()

Submission status: Accepted

Solution code:
s=int(input())

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

print(i+2)

Submission status: Accepted

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


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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

Solution code:
s=int(input())

cnt = 1
dic = {}
dic[s] = True
while(1):
    cnt += 1
    if(s%2==0):
        s = s//2
    else:
        s=3*s+1
    if(s in dic.keys()):
        print(cnt)
        exit()
    dic[s] = True

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n = int(input())
a = {}
cnt = 0

while True:
    cnt += 1
    # print("{} {}", cnt, n)

    if n in a:
        print(str(cnt))
        exit()
    else:
        a[n] = 1

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

Submission status: Accepted

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

while True:
    idx += 1
    a.append(s)

    if s % 2 == 0:
        s //= 2
    else:
        s = 3 * s + 1
    if s in a:
        print(idx)
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
num = int(input())
li =[]
count = 1
li.append(num)
while True:
    count += 1
    new_num = li[-1]/2 if li[-1]%2 == 0 else li[-1]*3+1
    if new_num in li:
        print (count)
        break
    else:
        li.append(new_num)

Submission status: Accepted

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

Submission status: Accepted

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

    print(res+3)

Submission status: Accepted

Solution code:
s = int(input())

a = [0 for _ in range(1000001)]

a[s] = 1

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

Submission status: Accepted

Solution code:
s = int(input())
x = []
n = 0
while True:

    if x.count(s):
        print(n+1)
        break
    else:
        x.append(s)
        n += 1
    if s % 2 == 0:
        s /= 2
    else:
        s = 3*s + 1

Submission status: Accepted

Solution code:
s=int(input())
b=0
cnt=0
a=[0]*1000001
while b==0:
    cnt+=1
    if a[s]==1:
        b=1
    else:
        a[s]=1
        if s%2==0:
            s=s//2
        else:
            s=3*s+1
print(cnt)

Submission status: Accepted

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
s = int(input())

from collections import defaultdict
d = defaultdict(int)

num = 1
while True:
    # print("s: {}, num: {}, d.keys(): {} ".format(s,num, list(d.keys())))

    if s in d.keys():
        print(num)
        exit(0)
    d[s] += 1



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

    num += 1

Submission status: Accepted

Solution code:
flg=[False for i in range(1000001)]
a=int(input())
flg[a]=True
for i in range(2,10000000000000):
  if a%2==0:
    a//=2
  else:
    a=3*a+1
  if flg[a]:
    break
  flg[a]=True
print(i)

Submission status: Accepted

Solution code:
def main() -> None:
    s = int(input())
    dp = [s]
    st = set()
    st.add(s)

    i = -1
    while True:
        i += 1
        n = dp[i]
        if n % 2 == 0:
            dp += [n // 2]
        else:
            dp += [3 * n + 1]

        m = i + 1
        if dp[m] in st:
            print(m + 1)
            return
        st.add(dp[m])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def fun(n):
    if n%2:return 3*n+1
    return n//2
a=[0]+[int(input())]
i=1
while not fun(a[i]) in a:a.append(fun(a[i]));i+=1
print(i+1)

Submission status: Accepted

Solution code:
def judge(a):
    if a%2 == 0:
        n = a/2
    else:
        n = 3*a+1
    return(int(n))
list=[]
x=int(input())
list.append(x)
for i in range(100000):
    b = judge(x)
    if (b in list) == True:
        print(i+2)
        break
    else:
        list.append(b)
        x = b

Submission status: Accepted

Solution code:

s = int(input())
temp = []
temp.append(s)
former = s
idx = 1

while True:
    idx += 1
    later = former / 2 if former % 2 == 0 else former * 3 + 1

    if later in temp:
        print(idx)
        break
    temp.append(later)
    former = later

Submission status: Accepted

Solution code:
s = int(input())

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

a = cou(s)
a_list = [s]
while True:
    if a in a_list:
        print(len(a_list)+1)
        break
    a_list.append(a)
    a = cou(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

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

a = [s]
n = 1

while True:
  a.append(calc_next(a[n-1]))
  for i in range(n):
    if a[i] == a[n]:
      print(n+1)
      exit(0)
  n += 1

Submission status: Accepted

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

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

while 1:
  v=f(l[-1])
  if v in l:
    print(len(l)+1)
    break
  l.append(v)

Submission status: Accepted

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

s = int(input())

A = [s]
tmp = s
ind = 1

while not(tmp in A[:-1]) or ind == 1:
    ind += 1
    tmp = func(tmp)
    A.append(tmp)

print(ind)

Submission status: Accepted

Solution code:
s=int(input())
l=[]
l.append(s)
ans=[]
c=1
for i in range(10000000000):
    if l[c-1]%2==0:
        l.append(int(l[c-1]/2))
    else:
        l.append(int(l[c-1]*3+1))
    for v in range(len(l)):
        ans.append(l.count(l[v]))
    if 2 in ans:
        break
    c+=1
print(c+1)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


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


def solve():
    s = ii()
    d = {s: 0}
    for i in range(1, 1000000000):
        s = f(s)
        if d.get(s) is None:
            d[s] = 0
        else:
            return i + 1


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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

while (len(l)==len(set(l))):
  i+=1
  s = func(s)
  l.append(s)
print(i)

Submission status: Accepted

Solution code:
a=[]
cp_a=[]
an = input()
a.append(int(an))
i=0
cp_a.append(a[0])
t_or_f = 0
m = 0
n = 0

for k in range(1000000):
    if int(a[i])%2==0:
        cal = int(a[i])* (1/2)
        next_i = i+1
        a.append(int(cal))
        cp_a.append(a[next_i])
        i = i+1
    elif int(a[i])%2!=0:
        next_i = i+1
        cal  = 3*int(a[i]) + 1
        a.append(int(cal))
        cp_a.append(a[next_i])
        i = i+1


    for s in range(i):
        for t in range(s+1,i):
            if a[s]==cp_a[t]:
                n = s
                m = t
                print(m+1)
                t_or_f = 1
                break
        if t_or_f:
            break
    if t_or_f:
        break

# print(a)
# print(cp_a)

Submission status: Accepted

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

s = int(input())
a = dict()
a[0] = s
a[1] = a[0]

b = dict()
b[s] = 1

for i in range(1,1000001):
  a[i] = func(a[i-1]) 
  if a[i] in b.keys():
    print(i+1)
    break
  else:
    b[a[i]] = 1

Submission status: Accepted

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

a_list=[s]
i=1
while True:
    i+=1
    s=collatz(s)
    if s in a_list:
        break
    else:
        a_list.append(s)
print(i)

Submission status: Accepted

Solution code:
s=int(input())
def function(tmp):
    if tmp%2==0:
        return int(tmp/2)
    else:
        return int(3*tmp+1)
def hoge(t):
    if t==0:
        return s
    else:
        return function(a[t-1])
a=[]
for i in range(0,1000):
    if len(a):
        a.append(hoge(i))
    else:
        a=[hoge(i)]
    if a.count(hoge(i))==2:
        print(i+1)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(raw_input())

lis = []
count = 1

while not s in lis:
	lis.append(s)
	if s % 2:
		s = 3 * s + 1
	else:
		s = s / 2
	count +=1
	
	#print "lis",lis

print count

Submission status: Accepted

Solution code:
s = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
kaku = set()
kaku.add(s)
def f(x):
  if x %2 == 0:
    return x//2
  else:
    return 3*x+1
for i in range(2,10**9):
  s = f(s)
  if s in kaku:
    print(i)
    exit()
  kaku.add(s)

Submission status: Accepted

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

def io_generator():
	while True:
		yield raw_input()

#+++++++++++++++++++

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

def main(io):
	s=int(io.next())
	i=1
	opened=[]
	while True:
		opened.append(s)
		s=next(s)
		i+=1
		if s in opened:
			return i
	return -1

#++++++++++++++++++++

if __name__ == "__main__":
	io=io_generator()
	print main(io)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list_after = [int(input())]
counter = 1

def f(list_):
    if list_[-1] %2 == 0:
        after = list_[-1]/2
    else:
        after = 3 * (list_[-1]) + 1
    return after

break_ = 0
while break_ == 0:
    after = f(list_after)
    if after in list_after:
        print(counter+1)
        break_ = 1
        break
    list_after.append(after)
    counter += 1

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    s = int(input())

    i = 1
    n = s
    prev = set()
    while True:
        prev.add(n)
        i += 1
        if n % 2 == 0:
            n = n // 2
        else:
            n = 3 * n + 1
        if n in prev:
            break
    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

if s in [1,2,4]:
    print(4)
else:
    count = 1
    while s != 4:
        s = f(s)
        count += 1
    print(count+3)

Submission status: Accepted

Solution code:
# Collatz Problem
import sys

s = int(input())

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

a[0] = s

def getN(wk) :
    for _ in range(1, len(wk)) :
        if wk[_ - 1] % 2 == 0 :
            wk[_] = wk[_ - 1] // 2
        else :
            wk[_] = wk[_ - 1] * 3 + 1
        for i in range(_):
            if wk[i] == wk[_] and i < _ :
                return _ + 1

print(getN(a))

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)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

n = int(input())
r = set([n])
if n%2==0:
    s_next = n/2
else:
    s_next = n*3+1
i=2
while s_next not in r:
    r.add(s_next)
    if s_next%2==0:
        s_next = s_next/2
    else:
        s_next = s_next*3+1
    i+=1

print(i)

Submission status: Accepted

Solution code:
#coding:utf-8

s = int(input())

list = [s]

for i in range(1000000):
  n = list[i]
  if n%2 == 0:
    f = int(n/2)
  else:
    f = int(3*n+1)

  if f in list:
    print(i+2)
    break
  else:
    list.append(f)