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

        # if y is larger than x, we can only increase to get there
        if y >= x: 
            return y - x
        else: 
            # non trivial case, there are more ways to get to y 
            # the largest bound is x - y though (only decrementing by 1)
            minOps = x - y 

            # while some given x (we are mining) is greater than y, 
            # we can make it smaller so it can become closer to y
            m = set()
            w = [(x, 0)]

            while(w != []):
                n = w[0][0]
                cost = w[0][1]
                w.pop(0)
                
                # print(w, minOps, n, cost)
                if n == y and cost < minOps: 
                    minOps = cost

                if n >= y and cost < minOps: # do not compute over again 
                    if n > y:
                        if n % 11 == 0: 
                            # n = n // 11
                            if n // 11 not in m: 
                                w.append((n // 11, cost + 1))
                                m.add(n//11)
                            else:
                                m.add(n//11)

                        if n % 5 == 0: 
                            # n = n // 5 
                            if n // 5 not in m: 
                                w.append((n // 5, cost + 1))
                                m.add(n//5)
                            else: 
                                m.add(n//5)
                
                        if n - 1 not in m:
                            w.append((n - 1, cost + 1))
                            m.add(n - 1)
                        else: 
                            m.add(n - 1)

                        if n + 1 not in m: 
                            w.append((n + 1, cost + 1))
                            m.add(n + 1)
                        else: 
                            m.add(n + 1)

                if n < y and cost < minOps: 
                    # print("john travolta", n, cost)
                    if y not in m:
                        w.append((y, cost + (y - n)))
                        # m.add(n)
                    else: 
                        m.add(n)
                
                
                # print("------ below is latter output")
                # print(w, m)
                # print("------")
                
            return minOps
46