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


def answer(s: int) -> int:
    sequence_a = [s]
    while True:
        num = func(sequence_a[-1])
        if num in sequence_a:
            return len(sequence_a) + 1
        sequence_a.append(num)


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


if __name__ == '__main__':
    main()

Solution (Python):

import os
import sys
from io import BytesIO, IOBase


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


def main() -> None:
    s = int(input())

    seen = set()
    seen.add(s)
    a = [s]

    m = 2
    while True:
        latest = f(a[-1])
        if latest in seen:
            print(m)
            exit(0)
        m += 1
        a.append(latest)
        seen.add(latest)







BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self, **kwargs):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

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

Solution (Python):
s = int(input())
l = [s]
a = set(l)
for i in range(10**6):
  if l[-1] % 2 == 0:
    n = l[-1] // 2
  else:
    n = 3*l[-1] + 1
  if n not in a:
    a.add(n)
    l.append(n)
  else:
    print(len(l)+1)
    break

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

a_list=[s]


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

ans=len(a_list)+1

print(ans)

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

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

Solution (Python):
def readinput():
    s=int(input())
    return s

def main(s):
    hist=[0]*1000001
    i=1
    n=s
    hist[n]+=1
    while hist[n]<=1:
        if n%2==0:
            n=n//2
        else:
            n=3*n+1
        i+=1
        hist[n]+=1
    return i

if __name__=='__main__':
    s=readinput()
    ans=main(s)
    print(ans)

Solution (Python):
n = int(input())
data =[0]* 1000000
data[0] = n
i = 2
if n % 2 == 0:
    data[1] = n //2
else:
    data[1] = 3 * n + 1
while data[i - 1] not in data[0: i -2]:
    if data[i-1] % 2 == 0:
            data[i] = data[i - 1]//2
    else:
            data[i] = 3 * data[i - 1] + 1
    i += 1
print(i)

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

a = [0]*(10**6+1)
c = [0]*(10**6+1)
a[1] = s
c[s] = 1
for i in range(2, 10**6+1):
    v = a[i-1]//2 if a[i-1] % 2 == 0 else 3*a[i-1]+1
    a[i] = v
    if c[v] == 1:
        print(i)
        exit()
    c[v] = 1

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

for i in range(10**6):
	if a % 2 == 0:
		
		a = a//2
	else:
		
		a = 3*a + 1
	if a not in s:
		s.add(a)
	else:
		print(i+2)
		break

Solution (Python):
s = int(input())
ans = [s]
i = 1
if s == 1 or s == 2:
    ans = 4
else:
    while ans[i-1] != 4:
        if ans[i-1] % 2 ==0:
            ans.append(ans[i-1]//2)
        else:
            ans.append(ans[i-1]*3 + 1 )
        i += 1
    ans = i + 3
print(ans)

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

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

def function(n):
    if n % 2 == 0:
        return int(n/2)
    else:
        return int(n*3+1)
i = 0
count = 0
a = []
a.append(s)
while count < 2:
    a.append(function(a[i]))
    if a[i] == 4:
        count += 1
    i += 1
print(i)

Solution (Python):
s = int(input())
list_a = [None]
list_a.append(s)
ans = 0
for i in range(1, 10 ** 6 + 1):
    if list_a[i] % 2 == 0:
        list_a.append(list_a[i] // 2)
    else:
        list_a.append(3 * list_a[i] + 1)
    if list_a[i] in list_a[:i]:
        ans = i
        break
print(ans)

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

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

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

Solution (Python):
s = int(input())
DP = [s]
S = set()
S.add(s)
cnt = 1
while True:
    cnt += 1
    if DP[-1] % 2 == 0:
        x = DP[-1] // 2
    else:
        x = DP[-1] * 3 + 1
    if x in S:
        break
    S.add(x)
    DP.append(x)


print(cnt)

Solution (Python):
s = int(input())
arr = []
ans = 0
def calc(n, cnt):
    arr.append(n)

    if cnt >= 1000000:
        return n

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

    if n in arr:
        return cnt

    cnt += 1
    calc(n, cnt)
calc(s, 0)
print(len(arr) + 1)

Solution (Python):

import sys


def solve(S: int):
    s = set()
    s.add(S)
    c = 2
    while True:
        if S % 2 == 1:
            S = 3 * S + 1
        else:
            S /=  2
        if S in s:
            print(c)
            break
        s.add(S)
        c += 1

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

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

print(cnt)

Solution (Python):
a = int(input())
l = [a]
for i in range(1000000):
  if a % 2 == 0:
    a = a//2
  else:
    a = a*3 + 1
  if l.count(a)==2:
    print(1+max([i for i, x in enumerate(l) if x == a]))
    break
  else:
    l.append(a)

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

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

Solution (Python):

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

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

def func(n):
  if n % 2 == 0:
    a.append(n//2)
  elif n % 2 == 1:
    a.append(3*n + 1)
  
i = 1
while True:
  func(a[-1])
  i += 1
  if a.count(a[-1]) == 2:
    break
  else:
    pass


print(i)

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

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

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

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


if __name__ == '__main__':
    main()

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

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

coll = s
i = 1
while 1:
    if coll == 1 or coll == 2 or coll == 4:
        print(i  + 3)
        break
    coll = collatz(coll)
    i += 1

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

print(i+1)

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

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

print(i+1)

Solution (Python):
def main():
    def f(n):
        return 3 * n + 1 if n % 2 else n // 2
    s = int(input())
    a = [s]
    for i in range(1, 11**6):
        x = f(a[i-1])
        if x in a:
            return len(a) + 1; exit()
        a.append(x)


print(main())

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

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

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

print(ans + 3)

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

dp = [True]*(n*1000000)
dp[n] = False
res =1
while n <1000001:
    res +=1
    if n % 2 ==1:
        n = n*3+1
    else:
        n = n//2
    
    if dp[n]:
        dp[n] = False
    else:
        print(res)
        exit()

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

cnt=0

if s==1 or s==2:
  print('4')
  sys.exit()

while s!=4:
  if s%2!=0:
    s=3*s+1
    cnt+=1
  elif s%2==0:
    s=s//2
    cnt+=1

if s==4:
  print(cnt+4)

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

Solution (Python):
S = int(input())
s, c = S, 1
result = [s]
while True:
    if s % 2 == 0:
        s = s // 2
    elif s % 2 == 1:
        s = s * 3 + 1

    result.append(s)
    c += 1
    if len(set(result)) < len(result):
        break

print(c)

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

if s==1 or s==2:
    print(4)
else:
    while TMP[-1]!=1:
        if TMP[-1] % 2 == 0:
            TMP.append(TMP[-1]//2)
        elif TMP[-1] % 2 != 0:
            TMP.append(3 * TMP[-1] + 1)
    print(len(TMP)+1)

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

max_ = 1000000
chk = [0]*max_
a = s
i = 1
while i <= max_:
    if chk[a] == 0:
        chk[a] += 1
    else:
        print(i)
        exit()
    if a%2 == 0:
        a = int(a/2)
    else:
        a = 3*a + 1
    i += 1

Solution (Python):


a=int(input())








da=True
ap=[a]
count=1
while da:
    if a%2==0:
        a=a//2
        ap.append(a)
    elif a%2==1:
        a=3*a+1
        ap.append(a)
    count+=1
    if len(set(ap))<len(ap):
        print(count)
        da=False

Solution (Python):
import sys
import copy
s = int(input())

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

for i in range(1000000):
    if i == 0:
        a=[s]
    else:
        a.append(f(a[i-1]))
    
    if a.count(a[i]) == 2:
        print(i+1)
        sys.exit(0)

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

n = int(input())
arr = [n]
for i in range(10**6):
  nn = cor(n)
  if nn in arr:
    print(i+2)
    exit()
  else:
    arr.append(nn)
    n = nn

Solution (Python):

import sys
input=sys.stdin.readline

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

def main():
    s = int(input())
    dp=[s]
    counter=0

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

    while counter < 1000001:
        n=dp.pop()
        tmp = func(n)
        dp.append(n)
        dp.append(tmp)
        counter+=1
        if tmp==4:
            print(dp.index(tmp)+4)
            break

if __name__=="__main__":
    main()

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

def f(x):
    if x%2 == 0:
        return int(x/2)
    else:
        return 3*x + 1
i = 1
m_max = 1000000
b_s = s
b = set([s])
while i <= m_max:
    i += 1
    a = f(b_s)
    if a in b:
        break
    b.add(a)
    b_s = a
print(i)

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

Solution (Python):
import sys
s = int(input())
f = [0 for _ in range(1000005)]
f[s] = 1
n = s
for i in range(1000005):
  if(n%2==0):
    n = int(n/2)
  else:
    n = int(3*n + 1)
  if(f[n] == 1):
    print(i+2)
    sys.exit()
  else:
    f[n] = 1

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

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

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

count = 1
n = s
check = 0
list = [s]


for i in range(30000):
        if n % 2 == 0:
            n = n / 2
            list.append(n)
        else:
            n = n*3 + 1
            list.append(n)
        
        count = count + 1
        list.sort()
        for j in range(len(list) - 1):
            if list[j] ==list[j+1]:
                check = 1
                break
            
        if check == 1:
            break
        


print(count)

Solution (Python):
def resolve():
    s = int(input())
    hist = set([])
    idx = 1
    while True:
        if s in hist:
            print(idx)
            return
        hist.add(s)
        idx += 1
        if s%2==0:
            s //= 2
        else:
            s = 3*s + 1



if '__main__' == __name__:
    resolve()

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

Solution (Python):
n = int(input())
a = [n]
index = 0

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

Solution (Python):

url = "https://atcoder.jp//contests/abc116/tasks/abc116_b"

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


def main():
    s = int(input())
    ans = [s]
    while True:
        tmp = calc(ans[-1])
        ans.append(tmp)
        if ans.index(tmp) != len(ans)-1:
            print(len(ans))
            break



if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
a=int(input())
i=1
li=[a]
import copy
while True:
    if li[i-1]%2==0:
        b=li[i-1]//2
    else:
        b=3*li[i-1]+1
    if b in li:
        print(i+1)
        exit()
    li.append(b)
    i+=1

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


s = int(input())
cnt = 0
a = [s]
while True:

    temp = f(a[cnt])

    if temp in a:
        print(len(a)+1)
        exit()
    a.append(temp)
    cnt += 1

Solution (Python):

s = int(input())
a = s
S = set([s])
for i in range(2,10**6+1):
    a = a//2 if a%2==0 else 3*a+1
    if a in S:
        print(i)
        break
    S.add(a)

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

if s < 3:
  print(4)
  exit(0)

cnt = 1
val = s
while True:
  if cnt > 1 and val == 1:
    break
  
  if val % 2 == 0:
    val = val//2
  else:
    val = val*3+1
    
  cnt += 1
             
print(cnt+1)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = int(readline())
    d = dict()
    d[s] = 1

    def solve():
        cur = s
        i = 1

        while True:
            i += 1
            if cur % 2 == 0:
                cur //= 2
            else:
                cur = 3 * cur + 1
            if d.get(cur):
                return i
            else:
                d[cur] = i

    print(solve())

if __name__ == '__main__':
    main()

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

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


def main():
    a = int(input())
    a_dict = {a: 1}

    for i in range(2, 1000001):
        a = f(a)
        if a not in a_dict:
            a_dict[a] = 1
        else:
            print(i)
            break


if __name__ == "__main__":
    main()

Solution (Python):
s = int(input())
S = {s}
i = 1
while True:
  i += 1
  if s % 2 == 0:
    s //= 2
  else:
    s = 3*s + 1
  if s in S:
    break
  S.add(s)
print(i)

Solution (Python):
def func(x):
  if x%2==0:
    return x//2
  else:
    return 3*x + 1
A = [True for i in range(1000001)]
N = int(input())
count = 1
while A[N]:
  A[N] = False
  N = func(N)
  count += 1
print(count)

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

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

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

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

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

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

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

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

Solution (Python):
from sys import stdin

s = int(stdin.readline().strip())
mem = []
a = s

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

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

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

print(ans)

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

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

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

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

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

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

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

s = int(input())

seq = set()
seq.add(s)

_next = s
while True:
    if _next % 2 == 0:
        _next //= 2
    else:
        _next = _next * 3 + 1
    if _next in seq:
        break
    else:
        seq.add(_next)

print(len(seq) + 1)

Solution (Python):
def collatz_problem(s):
    a = []

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


def main():

    s = int(input())
    answer = collatz_problem(s)
    print(answer)


if __name__ == "__main__":
    main()

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

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

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

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

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

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')

s = I()
vs = set()
vs.add(s)
now = 0 + s
i = 1
while True:
    i += 1
    now = now / 2 if now % 2 == 0 else 3*now + 1
    if now in vs:
        break
    else:
        vs.add(now)

print(i)

Solution (Python):
s=int(input())
a=[0]*10**6
a[0]=s

def f(x):
  if x%2==0:
    return x//2
  else:
    return 3*x+1
t=0 
while f(a[t])>0:
  p=f(a[t])
  if p in a:
    print(t+2)
    exit()
  a[t+1]=p
  t+=1

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

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

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

while True:
  count = 0
  if S % 2 == 0:
    S = S / 2
    array.append(S)
  else:
    S = 3 * S + 1
    array.append(S)
  for i in range(len(array)):
    if S == array[i]:
      count += 1
      if count == 2:
        print(i + 1)
        exit()

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

Solution (Python):
import sys
from collections import deque

import math

def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    m = 1
    pre = s
    st = {s}
    while True:
        m += 1
        if pre%2==0:
            tmp = pre/2
        else:
            tmp = 3*pre+1
        if tmp in st:
            print(m)
            return
        pre = tmp
        st.add(tmp)
    return

if __name__=='__main__':
    s = I()
    solve()

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

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

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

print(count)

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

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

i = 1
a_set = {s}

a_prev = s
while True:
    i += 1
    if a_prev % 2 == 0:
        a = a_prev // 2
    else:
        a = 3 * a_prev + 1
    if a in a_set:
        ans = i
        break
    a_set.add(a)
    a_prev = a

print(ans)

Solution (Python):
lis=[int(input())]
for i in range(1000):
    if lis[i]%2==0:
        a=lis[i]//2
        lis.append(a)
        def has_duplicates(x):
            return len(x) != len(set(x))
        if has_duplicates(lis)==True:
            break
    else:
        a=lis[i]*3+1
        lis.append(a)
        def has_duplicates(x):
            return len(x) != len(set(x))
        if has_duplicates(lis)==True:
            break
print(len(lis))

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

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

numbers = []

for i in range(10000001):
    if i == 0:
        numbers.append(s)
    else:
        if numbers[-1] % 2 == 0:
            numbers.append(numbers[-1] // 2)
        else:
            numbers.append(3*numbers[-1]+1)
    if numbers.count(4) == 2 or numbers.count(2) ==2 or numbers.count(1) == 2:
        break

print(len(numbers))

Solution (Python):
import sys
import numpy as np
import numba
from numba import jit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@jit
def main(n):
  ans = [n]
  m = 0
  while not ans[m] in ans[:m]:
    if n%2 == 0:
      n /= 2
      ans.append(n)
    else:
      n = 3 * n + 1
      ans.append(n)
    m += 1
  return m+1
    
    
  
n = int(input())
print(main(n))

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

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

Solution (Python):
a=int(input())
if a==1:
    print(4)
    exit()
elif a==4:
    print(4)
    exit()
elif a==2:
    print(4)
    exit()

ans=1
while True:
    if a==4:
        break
    elif a%2==0:
        a=a/2
        ans+=1
    else:
        a=3*a+1
        ans+=1

print(ans+3)

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

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

def main(s):
    temp = []
    count = 0
    ans = 0
    for i in range(s, 100000000):
        if i == s:
            a = i
        else:
            a = f(temp[count-1])
        
        temp.append(a)
        count += 1

        if a == 4 or a == 2 or a == 1:
            ans = count + 3
            break
    
    print(ans)


if __name__ == "__main__":
    s = int(input())

    main(s)

Solution (Python):
def f(n):
    if n%2==0: return n//2
    else: return 3*n+1
s = int(input())
v = set()
cnt = 1
while s not in v:
    v.add(s)
    s = f(s)
    cnt += 1
print(cnt)

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

ans = [s]

while True:
    if s % 2 == 0:
        s //= 2
    else:
        s = 3 * s + 1
    if ans.count(s) != 0:
        ans.append(s)
        break
    else:
        ans.append(s)


print(len(ans))

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

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

    if used[val]:
        print(i)
        break
    else:
        used[val] = 1

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