eolymp
bolt
Try our new interface for solving problems
Problems

Fun Fibonacci

Fun Fibonacci

Find the value of the function $$ f(x, y) = \begin{cases} 0, x \le 0~or~y \le 0 \\ f(x - 1, y - 2) + f(x - 2, y - 1) + F(x), x \le y \\ f(x - 2, y - 2) + F(y), x > y \end{cases} $$ where $F(n)$ is the $n$-th Fibonacci number, defined as follows: \begin{itemize} \item $F(0) = 2$, \item $F(1) = 3$, \item $F(n) = F(n-1) + F(n-2)$ \end{itemize} \InputFile Three integers $x, y, m~(0 \le x, y \le 500, m \le 10^9)$. \OutputFile Print the value of the function $f(x, y)~mod~m$.
Time limit 1 second
Memory limit 128 MiB
Input example #1
11 22 10000
Output example #1
3072