Domino rectangles

You have 4n4n identical 3-3 domino pieces, and you must cover with them a 3×3n3 \times 3n rectangle. As you can see in the picture below, the positions (2,2),(2,5),,(2,3n1)(2, 2), (2, 5), \dots, (2, 3n - 1) of the rectangle must be left empty. Depending on nn, how many different rectangles are possible?

For instance, these are the two only possible rectangles for n=1n = 1, two of the six possible rectangles for n=2n = 2, and a possible rectangle for n=7n = 7:

image

Input

Input consists of several cases, each with two integer numbers nn and mm. You can assume 0n10120 \le n \le 10^{12} and 2m1062 \le m \le 10^6.

Output

For every case, print the number of 3×3n3 \times 3n rectangles modulo mm.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T12:11:09.468Z

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