#P1573. 栈的操作
栈的操作
Description
There are four stacks. The first three are empty, and the fourth stack contains, from top to bottom, . Each stack supports only one operation: pop and push. This means popping the top element from some stack A and immediately pushing it onto any stack B. However, such an operation is allowed only if the following rules are satisfied.
- Rule : Stack A must be non-empty.
- Rule : Stack B is empty, or is smaller than the top of stack B.
Given , find the minimal number of operations needed to move all elements from the fourth stack to the first stack.
Since the minimal number of operations can be very large, output the answer modulo .
Input Format
One line containing an integer .
Output Format
One line containing a positive integer, the value of the minimal number of operations .
2
3
Hint
- For 30% of the testdata, .
- For 60% of the testdata, .
- For 100% of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号