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

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

Solution (Python):
n = int(input())
cs = {0: n}  
used = {n: True}
for i in range(1, 10000000):
  cs[i] = cs[i-1] // 2 if cs[i-1] % 2 == 0 else cs[i-1]*3 +1
  if cs[i] in used:
      break
  used[cs[i]] = True
print(i + 1)

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

Solution (Python):
a = [int(input())]
seen = {a[0]}
f = lambda n: 3 * n + 1 if n & 1 else n // 2
for i in range(2, 1000001):
    next = f(a[-1])
    if next in seen:
        print(i)
        exit()
    a.append(next)
    seen.add(next)
raise Exception('Something went wrong...')

Solution (Python):
import sys

s = int(input())

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

Solution (Python):
n=int(input())
cnt=1
nl=[n]
for i in range(1000000):
    if n%2==0:
        n=int(n/2)
        cnt+=1
    elif n%2==1:
        n=3*n+1
        cnt+=1
    if n in nl:
        print(cnt)
        exit()
    nl.append(n)

Solution (Python):
s = int(input())
lis = set()
lis.add(s)
jud = True
cnt = 1
while jud:
    if s%2:
        s = 3*s+1
    else:
        s = s//2
    if s in lis:
        jud = False
    lis.add(s)
    cnt += 1
print(cnt)

Solution (Python):

import sys










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


def main():
    s = int(sys.stdin.readline().rstrip())

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

if __name__ == "__main__":
    main()

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

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

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

for i in range(1000000):
  if i == 0:
    l.append(s)
  else:
    s = calc(l[i-1])
    if s in l:
      break
    else:
      l.append(s)
      
print(len(l)+1)

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

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

Solution (Python):
from collections import defaultdict
s = int(input())

dict = defaultdict(int)
an = s
dict[an] += 1

for i in range(2, 1000000):
    if an % 2 == 0:
        an /= 2
    else:
        an = 3*an + 1

    dict[an] += 1
    if dict[an] == 2:
        print(i)
        exit()

Solution (Python):
a = int(input())
ai = a
a_set = set()
flag_1 = 0
flag_2 = 1
while(flag_1 == 0):
  if ai in a_set:
    flag_1 += 1
    print(flag_2)
  else:
    a_set.add(ai)
    flag_2 += 1 
    if ai % 2 == 0:
      ai //= 2
    else:
      ai = 3 * ai + 1

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

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

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

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

Solution (Python):

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

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

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

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

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

main()

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

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

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

s = [int(input())]

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

print(cnt)

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

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

print(ans)

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

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

s = int(input())

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

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

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

Solution (Python):
import sys
import numpy as np

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

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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = int(next(tokens))  
    solve(s)

if __name__ == '__main__':
    main()

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

Solution (Python):
s = int(input())

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

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

ss = [s]
count = 1

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

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

a = [s]
m = 1
for i in range(1000000):
    m += 1
    a.append(f(a[-1]))
    if a[-1] in a[:-1]:
        print(m)
        break

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

Solution (Python):
from sys import stdin

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

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

print(kaisuu)

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

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

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

    return(result)

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

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

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

print(n+1)

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

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

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

Solution (Python):
s = int(input())

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

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

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

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

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

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

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

s=int(input())

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

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

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

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

cur = int(input())

ans = 1
ss = set([cur])

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

print(ans)

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

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

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

Solution (Python):
S = int(input())

INF = 10 ** 9 

list = [S]

con = 0

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

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

	if S in list[:i]:
		break



print(con + 1)

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

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

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

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

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

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

    print(len(arr)+1)

if __name__ == '__main__':
    main()

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

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

i = 1

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

    i += 1
    
print(i)

Solution (Python):
s=int(input())

l=[s]
c=0

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

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

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

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

Solution (Python):
s = int(input())

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

print(count)

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

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

print(i)

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

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

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

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

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

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

    if s in lst:
        break
print(i)

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

Solution (Python):
s = int(input())

A = [s]

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

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

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


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

if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict

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

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

while True:
    s = collatz(s)

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

    d[s] += 1
    ans += 1

Solution (Python):
s = int(input())

c=1

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

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

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

Solution (Python):
s = int(input())
l = [False for _ in range(10**6)]
for i in range(1, 10**5 + 1):
  if l[s]:
    print(i)
    exit()
  l[s] = True
  if s % 2 == 0:
    s = s // 2
  else:
    s = 3 * s + 1

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

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

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

Solution (Python):


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

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

ans = i
print(ans)

Solution (Python):
s = int(input())

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

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

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

Solution (Python):
import math


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

    print(count + 2)


if __name__ == "__main__":
    func()

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

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

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

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

Solution (Python):
s = int(input())

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

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

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

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

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

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

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


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

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

Solution (Python):
s = int(input())

a_1 = s
a_2 = 0
i = 2

dict = {}
dict[s] = 1
while(1000000):
  if a_1 % 2 == 0:
    a_2 = int(a_1 / 2)
  else:
    a_2 = 3 * a_1 + 1

  if a_2 in dict:
    print(i)
    break
  else:
    dict[a_2] = i
  i += 1
  a_1 = a_2

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

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

print(len(l)+1)

Solution (Python):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *

from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

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

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

    print(res+3)

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

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

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

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

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


if __name__ == '__main__':
    slove()

Solution (Python):
import sys
input = sys.stdin.readline


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

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


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

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

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

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

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

print(m)

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

Solution (Python):
s = int(input())

exist_set = set()
index = 1

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

print(index)

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

Solution (Python):
fn = int(input())

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

Solution (Python):


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

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

    
    for val in l:
        if val == s:
            keepCheck = False

    l.append(s)

print counter

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

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

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

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

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

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

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

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

Solution (Python):
s = int(input())

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

Solution (Python):
s = int(input())

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

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

    log.add(s)

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

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

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

Solution (Python):
s = int(input())
def f(n):
  if n%2 == 0:
    return n//2
  else:
    return 3*n+1
a = [s]
i=1
while(1):
  i+=1
  x=f(a[-1])
  if (x in a):
    print(i)
    exit()
  a.append(x)

Solution (Python):
s=int(input())
def f(x):
  if x%2==0:
    return x/2
  else:
    return 3*x+1
  
counter=1
nums=[s]
temp=f(s)
while any([temp==nums[i] for i in range(counter)])==False:
  nums.append(temp)
  counter+=1
  temp=f(temp)
  
print(counter+1)

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

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

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

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

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

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

    elif tmp in number:
        print(output)
        break

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

Solution (Python):
import sys
n = int(input())
def calc(x):
    if x%2 == 0:
        return int(x/2)
    else:
        return 3*x+1
li = [n]
flg = 0
ans = n
count = 1
while flg == 0:
    ans = calc(ans)
    if ans in li:
        print(count+1)
        flg += 1
        sys.exit()
    else:
        li.append(ans)
        count += 1

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