Partition into Teams

n명이 각각 빨강, 파랑, 관중을 같은 확률로 고를 때, 빨강이 파랑을 이기는 경우의 수를 소수 p로 나눈 나머지를 구한다.

보통7조합론정수론수학아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

A company of nn people decided to play a game. Each person can either join red team, join blue team, or become a spectator. Each person makes a decision independently and picks one of the three options with equal probability. The team which gets more players will win the game; the game ends in a draw in case both teams have an equal number of players. Let us denote the probability of red team winning by tt. Find (t3n)modp(t \cdot 3^{n}) \bmod p, where pp is prime.

입력

The only line of the input contains two integers nn and pp (1n10181 \le n \le 10^{18}, 5p<1065 \le p < 10^{6}, pp is prime).

출력

Print one integer: the answer to the problem.