Rock-Paper-Scissors

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Alice and Bob are going to play the famous game "Rock-Paper-Scissors". Both of them don't like to think a lot, so both of them will use the random strategy: choose rock, paper or scissors with equal probability.

They want to play this game nn times, then they will calculate the score ss  in the following way: if Alice won aa times, Bob won bb times, and the remaining nabn - a - b games were draws, the score will be the greatest common divisor of aa and bb. If aa or bb is 00, we define the greatest common divisor of aa and bb as a+ba + b.

Calculate the expected value of s32ns \cdot 3^{2 n}.  Note that the answer is necessarily an integer. Because this integer may be very large, find its remainder modulo pp instead.

입력

The input contains two integers nn and pp (1n1051 \le n \le 10^5, 108p10910^8 \le p \le 10^9, pp is prime).

출력

Print a single line with a single integer: the answer to the problem modulo pp.