Under construction

Still being built. Things may change

Lines

Time limit10sMemory limit256 MB

Summary
Count n by n O/X boards where no row, column, or main diagonal is monochromatic, modulo a prime p.
Level

Medium7 of 10

Topics
Combinatorics, Math, Implementation
Solved
No attempts yet

Problem

Johnny has learned to play tic-tac-toe. He likes the game so much that he decided to generalize it to larger boards. He clearly does not know gomoku, because in his generalization you win by filling a whole line (vertical, horizontal, or one of the two main diagonals) with your symbol. Designing a strategy for his game looks difficult, so Johnny decided to handle a simpler problem: how many tie boards of size n×nn \times n are there, that is, boards completely filled with O and X such that no line (vertical, horizontal, or one of the two main diagonals) is filled with a single symbol. Johnny wants to solve the most basic variant of the problem, so he allows any proportion of O and X and does not treat boards that can be obtained by rotation or reflection as the same. Even in this basic variant the problem seems difficult, so help Johnny solve it!

Input

The first and only line contains two integers nn and pp (1≤n≤3001 \le n \le 300, 2≤p≤109+92 \le p \le 10^9+9), separated by a single space. nn is the size of Johnny's board and pp is a prime number.

Output

Print one integer on the first and only line: the remainder modulo pp of the number of all n×nn \times n boards completely filled with O and X in which no line (horizontal, vertical, or one of the two main diagonals) is filled with a single symbol.

Examples2

  1. Example 1

    Input
    3 101
    
    Expected output
    32
    
  2. Example 2

    Input
    4 3
    
    Expected output
    2