<p>You are given two positive integers <code>x</code> and <code>y</code>.</p>

<p>In one operation, you can do one of the four following operations:</p>

<ol>
	<li>Divide <code>x</code> by <code>11</code> if <code>x</code> is a multiple of <code>11</code>.</li>
	<li>Divide <code>x</code> by <code>5</code> if <code>x</code> is a multiple of <code>5</code>.</li>
	<li>Decrement <code>x</code> by <code>1</code>.</li>
	<li>Increment <code>x</code> by <code>1</code>.</li>
</ol>

<p>Return <em>the <strong>minimum</strong> number of operations required to make </em> <code>x</code> <i>and</i> <code>y</code> equal.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> x = 26, y = 1
<strong>Output:</strong> 3
<strong>Explanation:</strong> We can make 26 equal to 1 by applying the following operations: 
1. Decrement x by 1
2. Divide x by 5
3. Divide x by 5
It can be shown that 3 is the minimum number of operations required to make 26 equal to 1.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> x = 54, y = 2
<strong>Output:</strong> 4
<strong>Explanation:</strong> We can make 54 equal to 2 by applying the following operations: 
1. Increment x by 1
2. Divide x by 11 
3. Divide x by 5
4. Increment x by 1
It can be shown that 4 is the minimum number of operations required to make 54 equal to 2.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> x = 25, y = 30
<strong>Output:</strong> 5
<strong>Explanation:</strong> We can make 25 equal to 30 by applying the following operations: 
1. Increment x by 1
2. Increment x by 1
3. Increment x by 1
4. Increment x by 1
5. Increment x by 1
It can be shown that 5 is the minimum number of operations required to make 25 equal to 30.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= x, y &lt;= 10<sup>4</sup></code></li>
</ul>

class Solution:
    def minimumOperationsToMakeEqual(self, x: int, y: int) -> int:
        q = deque([[x, 0]])
        visited = set()

        while q:
            cur, depth = q.popleft()
            if cur in visited:
                continue
            visited.add(cur)
            if cur == y:
                return depth
            if cur % 11 == 0:
                q.append([cur // 11, depth + 1])
            if cur % 5 == 0:
                q.append([cur // 5, depth + 1])
            q.append([cur + 1, depth + 1])
            q.append([cur - 1, depth + 1])
        return -1


"""
class Solution:
    def minimumOperationsToMakeEqual(self, x: int, y: int) -> int:
        # BFS 탐색을 위한 큐 초기화
        q = deque([(x, 0)])  # (현재 값, 연산 횟수)
        visited = {x}  # 시작 값을 방문 처리

        while q:
            current, depth = q.popleft()
            if current == y:
                return depth
            next_moves = []
            if current % 11 == 0:
                next_moves.append(current // 11)
            if current % 5 == 0:
                next_moves.append(current // 5)
            next_moves.append(current - 1)
            next_moves.append(current + 1)
            for move in next_moves:
                if move not in visited:
                    visited.add(move)
                    q.append((move, depth + 1))
        return -1  # y에 도달할 수 없는 경우
"""

102