Fibonacci-like sequences

Inspired by the Fibonacci sequence $F_0 = 0, F_1 = 1, F_n = F_{n-1} + F_{n-2} \mbox{\, for \,} n \ge 2$, Xavier defined his own sequence of numbers: $$X_0 = 0, X_1 = 1, X_n = X_{X_{n-1}} + X_{X_{n-2}} \mbox{\, for \,} n \ge 2 .$$ Max also wanted his own sequence of numbers, so he modified Xavier’s definition a bit: $$M_0 = 1, M_1 = 0, M_n = M_{M_{n-1}} + M_{M_{n-2}} \mbox{\, for \,} n \ge 2 .$$ Can you compute the nn-th term of any of these two new sequences?

Input

Input consists of several cases, each with a character cc, which is ‘X’ or ‘M’, and a natural nn between 0 and 10910^9.

Output

For each case, print XnX_n or MnM_n depending on cc.

Problem information

Author: Félix Moreno

Generation: 2026-01-25T11:35:11.622Z

© Jutge.org, 2006–2026.
https://jutge.org