<p>There is only one character <code>&#39;A&#39;</code> on the screen of a notepad. You can perform one of two operations on this notepad for each step:</p>

<ul>
	<li>Copy All: You can copy all the characters present on the screen (a partial copy is not allowed).</li>
	<li>Paste: You can paste the characters which are copied last time.</li>
</ul>

<p>Given an integer <code>n</code>, return <em>the minimum number of operations to get the character</em> <code>&#39;A&#39;</code> <em>exactly</em> <code>n</code> <em>times on the screen</em>.</p>

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

<pre>
<strong>Input:</strong> n = 3
<strong>Output:</strong> 3
<strong>Explanation:</strong> Initially, we have one character &#39;A&#39;.
In step 1, we use Copy All operation.
In step 2, we use Paste operation to get &#39;AA&#39;.
In step 3, we use Paste operation to get &#39;AAA&#39;.
</pre>

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

<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> 0
</pre>

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

<ul>
	<li><code>1 &lt;= n &lt;= 1000</code></li>
</ul>

class Solution:
    def helper(self, n, s, entire_s, best):
        if (n, s, entire_s) in best:
            return best[(n, s, entire_s)]

        if n == 0:
            return 0
        if len(s) > n or n < 0:
            return 9999
        elif len(s) == n:
            return 1
        else:
            #dont copy and paste
            temp1 = self.helper(n - len(s), s, entire_s + s, best) + 1
            if n - len(entire_s) >= 0:
                #copy and paste
                temp2 = self.helper(n - len(entire_s), entire_s, entire_s + entire_s, best) + 2
            else:
                temp2 = 9999
            res = min(temp1, temp2)
            best[(n, s, entire_s)] = res

            return res

    def minSteps(self, n: int) -> int:
        if n == 1:
            return 0
        return self.helper(n - 1, "A", "A", {}) + 1
        
20633