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:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
S = int(input())

lis = [0,S]

for i in range(2,1000000+1):
    if lis[i-1]%2==0:
        num = lis[i-1]//2
    if not lis[i-1]%2==0:
        num = 3*lis[i-1]+1
    if num in lis:
        ans = i
        break
    lis.append(num)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

a = [s]
i = 0

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

    if a[i+1] in a[:i+1]:
        print(i+2)
        break

    i += 1

Submission status: Accepted

Solution code:
s = int(input())

mem = [s]
cnt = 1
while -1:
  cnt += 1
  s = s // 2 if s % 2 == 0 else 3 * s + 1

  if s in mem:
    break
  
  mem.append(s)

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

l = [int(input())]
c = 2

while True:
    i = f(l[c-2])
    if i in l:
        print(c)
        exit()
    l += [i]
    c += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
d = {s: 1}
i = 1

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
	s =II()
	dic = defaultdict(lambda : False)
	idx = 1
	while(True):
		if idx!=1:
			if s%2==0:
				s/=2
			else:
				s=3*s+1
		if dic[s]:
			print(idx)
			exit()
		else:
			dic[s]=True
		idx+=1


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:

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

print(ans)

Submission status: Accepted

Solution code:
s = int(input())
l = [s]
x = 1
y = 0

while y == 0:
  if s%2 == 0:
    s = int(s//2)
  else:
    s = 3*s+1

  if s in l:
    print(x+1)
    y = 1
  else:
    l.append(s)
    x += 1

Submission status: Accepted

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

def myAnswer(s:int) -> int:
   i = 1
   a = [s]
   hantei = False
   while True:
      tmp = f(a[i - 1])
      if(tmp == 1):
         if(hantei == True):
            a.append(tmp)
            break
         else:
            hantei = True
      a.append(tmp)
      i+=1
   ans = 10**9
   while len(a) != 0:
      n = len(a)
      m = a.pop(-1)
      if(m in a):
         ans = min(ans,n)
   return ans



def modelAnswer():
   tmp=1
def main():
   s = int(input())
   print(myAnswer(s))

if __name__ == '__main__':
   main()

Submission status: Accepted

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

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

if s == 4 or s == 2 or s == 1:
    print(4)
else:
    while lst[-1] != 1:
        lst.append(gold(int(lst[-1])))
    print(len(lst) + 1 )

Submission status: Accepted

Solution code:
s = int(input())

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

a = [s]
for i in range(1000000):
    value = func(a[i])
    if value in a:
        print(i+2)
        break
    a.append(func(a[i]))

Submission status: Accepted

Solution code:
s = int(input())
A = [s]
ans = 1

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

Submission status: Accepted

Solution code:
n=int(input())
a=[]
m=1
while True:
  a.append(n)
  n = n/2*((n+1)%2) + (3*n+1)*(n%2)
  m=m+1
  if n in a:
    break

print(m)

Submission status: Accepted

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

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

i = 1
while 1:
    i += 1
    s = f(s)
    if s in num_set:
        print(i)
        break
    num_set.add(s)

Submission status: Accepted

Solution code:
s = int(input())


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


i = 1
A = {s}
while True:
    s = f(s)
    i += 1
    if (s in A):
        break
    A.add(s)
print(i)

Submission status: Accepted

Solution code:
H=[int(input())];i=0
while True:
    B=H[i]
    A=[B//2,3*B+1][B%2>0]
    i+=1
    if A in H:
        break
    else:
        H.append(A)
print(i+1)

Submission status: Accepted

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

Submission status: Accepted

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

    sl.append(new_sl)

Submission status: Accepted

Solution code:
s = int(input())
a = [False for i in range(1000000)]
num = 0

while True:
    num += 1
    if a[s] == True:
        print(num)
        break
    
    a[s] = True
    s = s // 2 if s % 2 == 0 else s * 3 + 1

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

s = int(input())

a = [s, ]

set_a = set()
i = 1
while True:
    c = a.pop()

    if c in set_a:
        print(i)
        break
    
    set_a.add(c)

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

    a.append(n_c)

    i += 1

Submission status: Accepted

Solution code:
s = int(input())
ans = [s]
fr = 0
for i in range(1,10**4):
    if s == 1:
        print(4)
        break
    if s  == 2:
        print(4)
        break
    if fr > 0:
        break
    if ans[i-1] % 2 == 0:
        for j in ans:
            if j == ans[i-1]/2:
                print(i)
                fr += 1
                break
        ans.append(ans[i-1]//2)
    else:
        for j in ans:
            if j == ans[i-1]/2:
                print(i)
                fr += 1
                break
        ans.append(3*ans[i-1]+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=int(input())
S=[]
x=0
y=0
z=0
m=0
if s==1 or s==2 or s==4:
    while True:
        if s%2==0:
            s=s//2
            x+=1
            if s==4:
                y+=1
            elif s==2:
                z+=1
            elif s==1:
                m+=1
        else:
            s=3*s+1
            x+=1
            if s==4:
                y+=1
            elif s==2:
                z+=1
            elif s==1:
                m+=1
        if y==2 or z==2 or m==2:
            break
    print(x)

else:
    while True:
        if s%2==0:
            s=s//2
            x+=1
            if s==4:
                y+=1
            elif s==2:
                z+=1
            elif s==1:
                m+=1
        else:
            s=3*s+1
            x+=1
            if s==4:
                y+=1
            elif s==2:
                z+=1
            elif s==1:
                m+=1
        if y==2 or z==2 or m==2:
            break
    print(x+1)

Submission status: Accepted

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

    a.append(a_next)

Submission status: Accepted

Solution code:
s=int(input())

def f(n):
    if n%2==0:
        return n//2
    return 3*n+1
ans=[s]

while True:
    x=ans.pop()
    ans.append(x)
    check=f(x)
    if check in ans:
        ans.append(check)
        print(len(ans))
        break
    else:
        ans.append(check)

Submission status: Accepted

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

s=int(input())
a=[]
a.append(s)
for i in range(1,100000):
    b = f(a[i-1])
    if b in a:
        print(i+1)
        break
    else:
        a.append(b)

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    s = II()
    a = s
    aset = set([a])
    cnt = 1
    while True:
        if a%2==0: a=a//2
        else: a=3*a+1
        if a in aset: break
        else: aset.add(a)
        cnt += 1
    print(cnt+1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = int(input())
a = set([s])
p = s
n = 0
cnt = 1
while True:
  if n in a:
    print(cnt)
    exit()
  a.add(n)
  if p&1:
    n = 3*p +1
  else:
    n = p//2
  cnt += 1
  p = n

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
n = int(input())

counter = [0]*1000000
counter[n-1] += 1

m = 1

while True:
  if n % 2 == 0:
    n = n//2
    counter[n-1] += 1
    if counter[n-1] == 2:
      break
  else:
    n = 3 * n + 1
    counter[n-1] += 1
    if counter[n-1] == 2:
      break
  m += 1
  
print(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 = [s]
for i in range(1000000):
    a_nxt = f(a[i])
    if a_nxt in a:
        print(i+2)
        break
    a.append(a_nxt)

Submission status: Accepted

Solution code:
s = int(input())


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


V = set([s])
prev = s
for i in range(1, 1000000 + 1):
    a = f(prev)
    if a in V:
        print(i + 1)
        exit()
    else:
        V.add(a)
        prev = a
print(V)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    ans = [N]
    cnt = 0
    while True:
        q = func(ans[cnt])
        if q in ans:
            print(len(ans) + 1)
            exit()
        else:
            ans.append(q)
            cnt += 1


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#ABC-117-B
s = int(input())
memo = {s:None}
ans = 1000000

for i in range(1, 1000001): 
    if s % 2 == 0:
        s = s / 2
        if s in memo:
            ans = i
            break
        else:
            memo[s] = None
    else:
        s = 3*s + 1
        if s in memo:
            ans = i
            break
        else:
            memo[s] = None
            
print(ans+1)

Submission status: Accepted

Solution code:
import sys

s = int(input())

res = [s]
c = 0
while True:
    if(res[c]%2 == 0):
        tmp = res[c]//2
    if(res[c]%2 == 1):
        tmp = res[c]*3+1
    res.append(tmp)
    if(len(set(res)) != len(res)):
        print(c+2)
        sys.exit()
    c+=1

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


def func(x):
    global cnt
    cnt += 1
    if x % 2:
        if f[3*x+1]: 
            print(cnt)
            quit()
        else:
            f[3*x+1] = 1
            func(3*x+1)
    else:
        if f[x//2]:
            print(cnt)
            quit()
        else:
            f[x//2] = 1
            func(x//2)


s = I()
f = defaultdict(int)
f[s] = 1
cnt = 1
func(s)

Submission status: Accepted

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

def func(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n+1
 
while func(s) !=1:
    s = func(s)
    lis.append(s)

if S == "1":
    print(4)
elif S == "2":
    print(4)
elif S == "4":
    print(4)
else:
    print(len(lis)+2)

Submission status: Accepted

Solution code:
s = int(input())
ans = 1

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

print(ans)

Submission status: Accepted

Solution code:
def main():
  s = int(input())
  #s = input()
  #s = input().split()
  #s = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 2
  lis = []
  if s == 1 or s == 2:
    print(4)
    exit()
  while s > 1:
    if s % 2 == 0:
      s //= 2
    else:
      s = s*3 + 1
    count += 1
  print(count)

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
s = int(input())


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


pre = s
result = set([s])
for i in range(1000005):
    current = f(pre)
    if current in result:
        print(i+2)
        break
    result.add(current)
    pre = current

Submission status: Accepted

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

Submission status: Accepted

Solution code:
li = [int(input())]
for i in range(1, 10 ** 6):

    n = li[i - 1]
    if n % 2 == 0:
        fn = n / 2
    else:
        fn = 3 * n + 1
    if fn in li:
        print(i + 1)
        exit()
    li.append(fn)

Submission status: Accepted

Solution code:
s = int(input())

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

A = [s]
ans = 1

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

Submission status: Accepted

Solution code:
def main():
    s = int(input())
    ak = s
    k = 1

    history = set([ak])
    while True:
        k += 1
        if ak%2 == 0:
            ak = ak//2
        else:
            ak = ak*3 + 1

        if ak in history:
            print(k)
            break
        else:
            history = history | set([ak])

main()

Submission status: Accepted

Solution code:
s = int(input())

tmp_list = [0]*1000000

for i in range(1000000):
    if i == 0:
        tmp = s
        tmp_list[tmp] = 1

    else:
        #print(tmp)
        if tmp % 2 == 0:
            tmp = tmp//2
        else:
            tmp = 3*tmp+1
        
        if tmp_list[tmp] == 0:
            #print('tmp_list')
            #print(tmp_list[tmp])
            tmp_list[tmp] = 1

        elif tmp_list[tmp] == 1:
            #print('break')
            print(i+1)
            break

Submission status: Accepted

Solution code:
s = int(input())
a = set()

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

print(len(a) + 1)

Submission status: Accepted

Solution code:
s = int(input())
l = [s]
a = 0
cnt = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

def fx(s):
    if s % 2 == 1:
        return 3*s + 1
    else:
        return s//2

a = [s]
b0 = a[0]

ans = 1
while fx(b0) not in a:
    a.append(fx(b0))
    b0 = a[-1]
    ans += 1

print(ans+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())
l = [s]
i = s
while s:
    if i % 2 == 0:
        l.append(i // 2)
        i //= 2
    else:
        l.append(i * 3 + 1)
        i = i * 3 + 1
    if l.count(i) == 2:
        l2 = [j for j, x in enumerate(l) if x == i]
        print(l2[1] + 1)
        exit()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    
    a_list = [n]

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

    print(len(a_list)+1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

s = int(input())
a = {s}
n = s
for i in range(2, 1000000):
    n = f(n)
    if n not in a:
        a.add(n)
    else:
        print(i)
        break

Submission status: Accepted

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

s = int(input())
a = {s}
n = s
for i, _ in enumerate(range(1000000), 2):
    n = f(n)
    if n not in a:
        a.add(n)
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
n=int(input())
ans=[]
ans.append(n)
tf=True
while tf:
    if n%2==0:
        n//=2
        ans.append(n)
    else:
        n=3*n+1
        ans.append(n)
    for i in range(len(ans)-1):
        for j in range(i+1,len(ans)):
            if ans[i]==ans[j]:
                print(len(ans))
                tf=False

Submission status: Accepted

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


s = int(input())
i = 1
k = 0
old = [s]

while 1:
    k = f(s) if i == 1 else f(k)
    if k in old:
        break
    else:
        old.append(k)
        i += 1

print(i+1)

Submission status: Accepted

Solution code:
s=int(input())

def func(n):
    if n%2==0:
        return n//2
    else:
        return 3*n+1
series=[s]
for i in range(2,10**6):
    s=func(s)
    if s in series:
        print(i)
        break
    series.append(s)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
k = input().split()
a = int(k[0])

def b(n):
    return int(n/2)
def c(n):
    return int((3*n)+1)

Counter = 0

flag = True
IntSet = set()
IntSet.add(a)
Buffer = int(a)
for i in range(1,1000000+1):
    if Buffer%2 == 0:
        Buffer = b(Buffer)
        Counter+=1
    else:
        Buffer = c(Buffer)
        Counter+=1
    if Buffer in IntSet:
        print(Counter+1)
        break
    else:
        IntSet.add(Buffer)

Submission status: Accepted

Solution code:

import math
import itertools
import statistics
#import collections

#n =  list(map(int, input().split()))
s = int(input())

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

count1 = 0

a = [s]
while count1<2:
    s = calc_f(s)
    a.append(s)
    if s==1:
        count1+=1
 
for i in range(len(a)):
    for j in range(i+1, len(a)):
        if a[i]==a[j]:
            print(j+1)
            exit()

Submission status: Accepted

Solution code:
s = int(input())
co = []
ans = 1

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

Submission status: Accepted

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

def sample(s):
    if s % 2 is 0:
    	  s2 = int(s / 2)
    else:
    	  s2 = int(s * 3 + 1)

    if s2 in arr:
        print(arr.index(s) + 2)
        return
    
    arr.append(s2)
    sample(s2)

sample(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

an = 0
list = []

for i in range(1, 1000001):
    if i == 1:
        an = s
        list.append(an)

    elif an % 2 == 0:
        an = an/2
        list.append(an)

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

    for j in range(len(list)-1):
        if list[j] == an:
            print(i)
            break
        else:
            continue
    else:
        continue
    break

Submission status: Accepted

Solution code:
s = int(input())

ar = []
ar.append(s)
flag = 0
count = 0

while flag == 0:
	count = count +1
	if s % 2 == 0:
		s = s//2
	else:
		s = 3* s +1
	if s in ar:
		flag = 1
	else:
		ar.append(s)
#		print(s)

print(count+1)

Submission status: Accepted

Solution code:
import sys
INF = 10 ** 10
MOD = 10 ** 9 + 7
from functools import lru_cache
sys.setrecursionlimit(100000000)

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

def main():
    s = int(input())
    a = set()
    a.add(s)
    x = s
    i = 2
    while True:
        y = f(x)
        if y in a:
            break
        a.add(y)
        x = y
        i += 1
    
    print(i)

if __name__ =='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def main():
    s = int(input())
    seen = set()
    i = 1
    while True:
        if s in seen:
            print(i)
            return
        seen.add(s)
        if s % 2 == 0:
            s /= 2
        else:
            s = s * 3 + 1
        i += 1


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = int(input())

num_list = []
count = 0

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

print(count+1)

Submission status: Accepted

Solution code:
s=int(input())
from collections import Counter
cc=Counter()
cc[s]=1
cnt=1
while True:
    if s%2==0:
        s=s/2
    else:
        s=3*s+1
    cnt+=1
    if cc[s]>0:
        print(cnt)
        import sys
        sys.exit()
    cc[s]+=1

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=INT()
    aset=set()
    aset.add(s)
    ct=1
    while True:
        ct+=1
        if s%2==0:
            s=int(s/2)
        else:
            s=3*s+1
        aset.add(s)
        if len(aset)!=ct:
            break
    print(ct)
        
if __name__ == '__main__':
    do()

Submission status: Accepted

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

def next(i:int):
    if l[i-1]%2 == 0:
        return l[i-1]//2
    else:
        return (3*l[i-1])+1

i = 0
while True:
    i += 1
    if next(i) in l:
        print (i+1)
        exit ()
    else:
        l.append(next(i))

Submission status: Accepted

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

Submission status: Accepted

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

a = int(input())

if a==4 or a==2 or a==1:
    print(4)
else:
    count = 0
    i=0
    while(count!=2):
        i+=1
        # print("{}".format(a),end=",")
        if a==4:
            count+=1
        a = int(f(a))
    print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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