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: Wrong Answer

Solution code:
def A():
    ab, bc, ca = map(int, input().split())
    print(int(bc * ab / 2))
#A()

def B():
    s = int(input())
    f_data = [s]
    i = 1
    a = [s]
    tmp = [0 for i in range(1000000)]
    def f(n):
        if n % 2 == 0:
            return n // 2
        else:
            return 3 * n + 1

    while True:
        key = f(f_data[-1])
        f_data.append(key)
        if tmp[key] == 1:
            ans = i + 1
            break
        tmp[key] = 1
        i += 1
    print(ans)
B()

Submission status: Wrong Answer

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

for i in range(20):
    if s % 2 == 0:
        s //= 2
        ans.append(s)
    else:
        s = 3*s + 1
        ans.append(s)

check = []

for i in range(len(ans)):
    if ans[i] not in check:
        check.append(ans[i])
    else:
        print(i+1)
        break

Submission status: Wrong Answer

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

while 1 == 1:
  if s % 2 == 1:
    a_ = 3 * s + 1
    
  else:
    a_ = s / 2
  
  i += 1
  if a_ in a:
    print(i)
    break
  
  a.append(a_)
  s = a_

Submission status: Wrong Answer

Solution code:
a = int(input())

for i in range(1,1000001):
    if a == 4:
        print(str(i+3))
        exit()
    if a % 2 == 0:
        a = a // 2
    else:
        a = 3 * a + 1

Submission status: Wrong Answer

Solution code:
a=int(input())
if a==1:
    print(4)
elif a==2:
    print(4)
else:
    for i in range(1000000):
        if a%2==0:
            a=a//2
        else:
            a=3*a+1
        if a==4:
            print(i+5)
            break

Submission status: Wrong Answer

Solution code:
s = int(input())

a = [s]

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

print(len(a)+3)

Submission status: Wrong Answer

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


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


def main():
    """Function."""
    s = int(input())

    check_dic = {}
    check = set()

    old = s
    counter = 1

    while old not in check:
        print(old,counter)
        check.add(old)
        check_dic[old] = counter

        counter += 1
        old = fn(old)

    print("!!!!!!!!!!!")
    print(counter)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
now = int(input())
ans = 0
for i in range(1000000):
    if now == 4:
        ans = i + 4
        break
    if now % 2 == 0:
        now = now // 2
    else:
        now = 3 * now + 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = int(input())

a=[]
memo = {}
a.append(s)
memo[s] = s

memo = {}
for i in range(1000000):
  if s%2==0:
    s = s//2
    if s in memo:
      print(i+2)
      break
    a.append(s)
    memo[s] = 1
  else:
    s = 3*s+1
    if s in memo:
      print(i+2)
      break
    a.append(s)
    memo[s] = 1

Submission status: Wrong Answer

Solution code:
def A():
    ab, bc, ca = map(int, input().split())
    print(int(bc * ab / 2))
#A()

def B():
    s = int(input())
    f_data = [s]
    i = 1
    a = [s]
    tmp = [0 for i in range(1000000)]
    def f(n):
        if n % 2 == 0:
            return n // 2
        else:
            return 3 * n + 1

    while True:
        key = f(f_data[-1])
        f_data.append(key)
        if tmp[key] == 1:
            ans = i + 1
            break
        tmp[key] = 1
        if key > 1000000:
            break
        i += 1
    print(ans)
B()

Submission status: Wrong Answer

Solution code:
s = int(input())

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())

flag = 0
i = 2

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

    if n == 4:
        flag += 1
    i += 1

print(i-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = int(input())
#h = [int(i) for i in input().split()]

a = s
count = 0
i = 0
while count < 2:
    i += 1
    if a % 2 == 0:
        a = int(a / 2)
    else:
        a = 3 * a + 1
    if a == 4:
        count += 1
#    print(a)


print(i+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = int(input())

res = s
i = 1
while True:
    if res == 1:
        print(i+1)
        break
    if res % 2 == 0:
        res = res // 2
        i = i+1
    else:
        res = res * 3 + 1
        i = i+1

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()

u = set()
cnt = 2
while True:
    if n % 2:
        n = 3 * n + 1
    else:
        n //= 2
    if n in u:
        print(cnt)
        exit()
    u.add(n)
    cnt += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = int(input())

ss = set()
for k in range(100000000000):
    if s%2 == 0:
        s = s/2
    else:
        s = 3*s + 1
    s = int(s)
    if s in ss:
#         print(s,s)
        break
    ss.add(s)
#     print(s)
print(k+2)

Submission status: Wrong Answer

Solution code:
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

x = ip()                              #入力整数1つ
#x,y= (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#x = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意
a = []
num =1
while True:
    num+=1
    if x%2:
        x = 3*x+1
    else: x//=2
    if x in a:
        print(num)
        exit(0)
    a.append(x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# N = input()   # 単純な入力
# input = list(input()) # ひとかたまりの文字列をリスト化
N = int(input())  # 整数一つ
# input = input().split()   # スペース区切りを文字としてリスト化
# X,Y = map(int,input().split())  # ２個や３個の整数をそれぞれ取得
# input = list(map(int,input().split()))

cnt = 0

while N !=1:
    if N%2==0:
        N = N//2
    else:
        N =3*N+1
    cnt += 1

print(cnt+2)

Submission status: Wrong Answer

Solution code:
s = int(input())

ss = set()
for k in range(100000):
    if s%2 == 0:
        s = s/2
    else:
        s = 3*s + 1
    s = int(s)
    if s in ss:
#         print(s,s)
        break
    ss.add(s)
#     print(s)
print(k+2)

Submission status: Wrong Answer

Solution code:
# N = input()   # 単純な入力
# input = list(input()) # ひとかたまりの文字列をリスト化
N = int(input())  # 整数一つ
# input = input().split()   # スペース区切りを文字としてリスト化
# X,Y = map(int,input().split())  # ２個や３個の整数をそれぞれ取得
# input = list(map(int,input().split()))

cnt = 0

while N !=4:
    if N%2==0:
        N = N//2
    else:
        N =3*N+1
    cnt += 1

print(cnt+4)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s=int(input())
ans=2
while(s>1):
    s=f(s)
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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)
  a.append(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    s = int(input())
    ans = [s]
    count = 0
    while s != 4:
        if ans[count]%2 == 0:
            ans.append(ans[count]/2)
        else:
            ans.append(ans[count]+3)
        count += 1
        if ans[count] < 1:
            ans[count] = ans[count-1]
    print(count+4)
resolve()

Submission status: Time Limit Exceeded

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

arr.append(s)

while s <= 5:
    if s % 2 == 0:
        s = s // 2
        arr.append(s)
    else:
        s = 3 * s + 1
        arr.append(s)

while s > 4:
    if s % 2 == 0:
        s = s // 2
        arr.append(s)
    else:
        s = 3 * s + 1
        arr.append(s)

print(len(arr) + 3)

Submission status: Time Limit Exceeded

Solution code:
# input
s = int(input())

# check
fn = {1: s}
lim = 1000001
fs = None
for m in range(2, lim):
    if m % 2 == 0:
        fn[m] = fn[m - 1] // 2
    else:
        fn[m] = 3 * fn[m - 1] + 1

    print(m, fn[m])

    if not fs and m == s: 
        fs = fn[m]
    
    if fs in [fn[k] for k in fn.keys() if k != s]:
        print(m)
        break

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
a = {s}
ai = s
i = 2
while True:
  if ai % 2 == 0:
    ai /= 2
  else:
    ai = 3 * ai + 1
  if ai in a:
    print(i)
    break
  else:
    i += 1

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
a = int(input())
idxs = defaultdict(int)
idxs[a] = 1
i = 1
ans = None
while True:
  i += 1
  if a % 2 == 0:
    a //= 2
  else:
    a = 3 * a + 1
    
  if not idxs[a]:
    idxs[a] = i
  else:
    ans = i

print(ans)

Submission status: Time Limit Exceeded

Solution code:

import numpy as np
import sys

input = sys.stdin.readline

s = int(input())

ans = 1

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


print(ans+3)

Submission status: Time Limit Exceeded

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

ary1 = [None]*1000001
ary1[1] = s

for i in range(2,1000001):
  fn = f(ary1[i-1])
  if fn in ary1:
    print(i)
    break
  else:
    ary1[i] = fn

Submission status: Time Limit Exceeded

Solution code:
s=int(input())
a=[-12345]*1000000
for i in range(1000000):
    
    a[i]=s
    if s%2==1:
        s=s*3+1
    else:
        s=s/2

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = int(input())

t = [False] * 1000000

while True:
  if s > 1000000:
    continue
  if t[s] == True:
    break
  if s % 2 == 0:
    s = s // 2
  else:
    s = 3 * s + 1

print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
result = []
ans = []
for i in range(1000000):
    if i == 0:
        result.append(s)
    elif result[i-1] % 2 == 0:
        aim = result[i - 1] // 2
        result.append(aim)
    else:
        aim = result[i - 1] * 3 + 1
        result.append(aim)
for j in range(len(result)):
    for k in range(len(result)):
        if result[j] == result[k] and j > k:
            ans.append(j)
            
print(ans[0] + 1)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
count = 1
while True:
  dic = {s:1}
  if s % 2 == 0:
    s //= 2
  else:
    s = 3 * s + 1
  count += 1
  if s in dic.keys():
    dic[s] += 1
    print(count)
    break
  else:
    dic[s] = 1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

else:
    print(len(a)+4)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
an = int(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while 1:
  if s %2 == 0:
    l.append(s/2)
    s = s/2
  else:
    l.append(3*s + 1)
    s = 3*s+1
  
  if any(l.count(i) >= 2 for i in range(1000001)):
    print(len(l))
    break

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
 
ans=0
 
def f(n):
  if (n % 2 == 0):
    return n / 2
  else:
    return 3*n + 1
  
while (True):
  a_n = [s]
  for i in range(len(a_n)):
    a_i  = f(a_n.pop(-1))
    a_n.append(a_i)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
 
ans=0
 
def f(n):
  if (n % 2 == 0):
    return n / 2
  else:
    return 3*n + 1
  
while (True):
  a_n = [s]
  for i in range(len(a_n)):
    if (a_n.count(4) != 2):
      a_i = f(a_n.pop(-1))
      a_n.append(a_i)
    else:
      index = a_n.index(4)
      ans = a_n[index+3]
      break
    
print(ans)

Submission status: Time Limit Exceeded

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

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

# print(l[:100])
for i, v in enumerate(l):
    for j in range(i + 1, len(l) - i):
        if l[j] == v:
            print(j + 1)
            exit()

Submission status: Time Limit Exceeded

Solution code:

s = int(input())

val = s
mp = {}
i= 0
while True:
  i+=1
  if val%2==0:
    val = val//2
  else:
    val = 2*val+1
  
  if val in mp:
    print(i)
    break
  else:
    mp[val] = 1

Submission status: Time Limit Exceeded

Solution code:
s = int(input())

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

a = [s]
i = 0
flg = 1

while(flg):
    a.append(func(a[i]))
    #print(a)
    for k in range(len(a)):
        for l in range(1, len(a)-k): 
            if a[k] == a[k+l]:
                print(k+l+1)
                break
        else:
            continue
        break   
        
    i += 1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

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

    if later in temp:
        print(idx)
        break

Submission status: Time Limit Exceeded

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

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


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

# print(a)
# print(cp_a)

Submission status: Time Limit Exceeded

Solution code:
def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

s = int(input())
ls = [s]
for i in range(1, 1000050, 1):
  if ls[-1]%2 == 1:
    ls.append(int(ls[-1]*3+1))
  else:
    ls.append(int(ls[-1]/2))
#print(ls)

for j in range(len(ls)):
  #print(ls[j:])
  #print(ls[j+1:].index(ls[j]))
  num = my_index(ls[j+1:], ls[j])
  if num >0:
    break
print(num+j+2)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
N=int(stdin.readline().rstrip())
a=[N]+[0]*10000000
for i in range(10000000):
    if i !=0:
        if a[i-1]%2==0:
            a[i]=int((a[i-1]/2))
        else:
            a[i]=int((3*a[i-1]+1))
cnt=1
tmp=[]
for j in a:
    if str(j) in tmp:
        break
    else:
        tmp.append(str(j))
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

s = int(input())
a = [s]
done = False
while not done:
    for i in range(len(a)):
        if a[i] != f(a[-1]):
            a.append(f(a[-1]))

        else:
            print(i)
            done = True
            break

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
ls = [s]
for i in range(1, 1000010, 1):
  if ls[-1]%2 == 1:
    ls.append(int(ls[-1]*3+1))
  else:
    ls.append(int(ls[-1]/2))
#print(ls)
cnt = False
for j in range(len(ls)):
  for k in range(j+1, len(ls)):
    if ls[j] == ls[k]:
      cnt = True
      #print("itti", j,k)
      break
  if cnt:
    break
print(k+1)

Submission status: Time Limit Exceeded

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

for i in range(1000000):
    for j in range(i+1,1000000):
        if a[i]==a[j]:
            print(j+1)
            sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
s = input()

tag = 0
i = 1
num = [0]*1000000

while tag == 0:
    if int(s)%2 == 0:
        s = int(s)/2
    else:
        s = 3*int(s) + 1
    i += 1
    for j in range(i):
        if s == num[j]:
            tag = 1
            break
        else:
            continue

print (i)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
#!/usr/bin/env 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)





# region fastio

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

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = int(next(tokens))  # type: int
    solve(s)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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