1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>     // std::cout
#include <algorithm>    // std::next_permutation, std::sort
#include <vector>
using namespace std;

int tab[12][5];

int main()
{
  int n, m;
  long long p;
  cin>> n >> m >> p;
  
  tab[2][1] = 2;
  tab[3][1] = 4;
  tab[3][2] = 2;
  tab[4][1] = 8; tab[4][2] = 16;
  tab[5][1] = 16; tab[5][2] = 100; tab[5][3] = 4;
  tab[6][1] = 32; tab[6][2] = 616; tab[6][3] = 72;
  tab[7][1] = 64; tab[7][2] = 4024; tab[7][3] = 952;
  tab[8][1] = 128; tab[8][2]= 28512; tab[8][3] = 11680;
  tab[9][1] = 256; tab[9][2] = 219664; tab[9][3] = 142800; tab[9][4] = 160;
  tab[10][1] = 512; tab[10][2] = 1831712; tab[10][3] = 1788896; tab[10][4] = 7680;
  tab[11][1] = 1024; tab[11][2] = 16429152; tab[11][3] = 23252832; tab[11][4] = 233792;

  long long result = tab[n][m]; 

  cout << result % p;

  return 0;
}