All problems

Problem 955

4 Keys Keyboard

Medium · 20 pts · Math, Dynamic Programming

Problem

A keyboard has four keys: A prints one A, Ctrl-A selects everything, Ctrl-C copies the selection, and Ctrl-V pastes the copied text. With exactly N key presses, print the largest number of A's that can be on the screen. Let best[i] be the answer for i presses: either press A (best[i - 1] + 1), or at some point j do Ctrl-A, Ctrl-C and then paste i - j - 2 times, giving best[j - 1] × (i - j). The numbers in this problem can be larger than a 32-bit int can hold (about 2.1 × 10^9), so use a 64-bit integer type: long long in C++, long in Java (Python needs nothing special).

Input

A single integer N.

Output

Print the maximum number of A's.

Constraints

1 <= N <= 90

Example input

7

Example output

9

Explanation

With 7 presses: A, A, A, Ctrl-A, Ctrl-C, Ctrl-V, Ctrl-V gives 3 + 3 + 3 = 9 A's, the best possible.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: 2 Keys Keyboard Next: Number of Ways to Form a Target String Given a Dictionary