Imagine you have a special keyboard with the following four keys:
-
Key 1 (
A
): print one
'A'
on the screen.
-
Key 2 (
Ctrl-A
): select the whole screen.
-
Key 3 (
Ctrl-C
): copy the selection to the buffer.
-
Key 4 (
Ctrl-V
): print the buffer on the screen, appending it after what has already been printed.
You can press the keyboard at most n times, using only these four keys. Return the maximum number of 'A' characters you can print on the screen.
Function Signature
def max_a_count(n: int) -> int:
Rules
-
The screen and the buffer start empty.
-
Ctrl-C
replaces the buffer with the selected text.
Ctrl-V
appends the buffer to the end of the screen and keeps the existing text, even when that text is selected.
-
Pressing fewer than
n
keys is allowed, but it never helps, because one more
A
always adds a character.
Constraints
Examples
Input: n = 3
Output: 3
A copy and a paste need three presses on top of at least one A, so with three presses the best you can do is press A three times.
Input: n = 7
Output: 9
Press A three times, then Ctrl-A, Ctrl-C, Ctrl-V, Ctrl-V. The copy puts 3 A's in the buffer and each paste adds 3 more, for 9. Seven plain A presses give 7, and A, A, Ctrl-A, Ctrl-C followed by three pastes gives 8.
Input: n = 11
Output: 27
The sequence from the previous example reaches 9 after seven presses. Then Ctrl-A, Ctrl-C and two pastes triple it to 27. Five A presses followed by Ctrl-A, Ctrl-C and four pastes gives only 25.