## Jason's Theorem

View as PDF

Points: 10 (partial)
Time limit: 0.5s
Memory limit: 64M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Baba Jason was playing around with his slide rules one morning and discovered an important mathematical property: Jason brought the discovery to Nathan, his math professor. Nathan was so impressed by the discovery that he convinced Jason to co-publish it in arXiv. Before Jason could publish the paper, Nathan informs him that mathematicians are very skeptical people, and will want to see more iterations in the sequence before they accept it.

The sequence is written in a markdown language known as , and the sequences are as such

(0) x=x
(1) x=x_{x}^{x}
(2) x=x_{x_{x}^{x}}^{x_{x}^{x}}
(3) x=x_{x_{x_{x}^{x}}^{x_{x}^{x}}}^{x_{x_{x}^{x}}^{x_{x}^{x}}}
(4) x=x_{x_{x_{x_{x}^{x}}^{x_{x}^{x}}}^{x_{x_{x}^{x}}^{x_{x}^{x}}}}^{x_{x_{x_{x}^{x}}^{x_{x}^{x}}}^{x_{x_{x}^{x}}^{x_{x}^{x}}}}
.
.

Jason quickly realizes that this will take a really long time to type, so he asks you how many keystrokes it will take to complete the iteration. Please help him!

#### Input Specification

A single integer .

#### Output Specification

Print the number of keystrokes Jason needs to type modulo .

#### Constraints #### Sample Input 1

0

#### Sample Output 1

3

#### Sample Input 2

1

#### Sample Output 2

11

#### Sample Input 3

2

#### Sample Output 3

27

#### Sample Input 4

3

#### Sample Output 4

59

#### Sample Input 5

4

#### Sample Output 5

123

#### Sample Explanations

The examples are given in the problem description.