Almost Video Game III

Time limit: 2.6s Memory limit: 256MB Input: Output:

In Video Game II: Almost Video Game III, you control a character which has KK abilities, numbered from 00 to K1K-1. The objective of this game is to defeat NN bosses, which are numbered from 00 to N1N-1, in the order you have to beat them.

At the beginning of a playthrough, none of the KK abilities has been researched yet. Before facing each boss, you can research a (possibly empty) subset of the KK abilities. Once an ability is researched, it will stay available for the rest of the playthrough and you do not have to research it again.

After beating all bosses, the score of the playthrough is equal to b2b^2, where bb is the number of bosses where your character had all KK abilities researched.

Let’s consider the following playthrough for N=4N = 4 and K=3K = 3:

  • Before fighting boss 00, you research ability 22.
  • You fight boss 00 with 11 ability researched.
  • Before fighting boss 11, you don’t research any new abilities.
  • You fight boss 11 with 11 ability (ability 22) researched.
  • Before fighting boss 22, you research abilities 00 and 11.
  • You fight boss 22 with all K=3K = 3 abilities researched.
  • Before fighting boss 33, you don’t research any new abilities.
  • You fight boss 33 with all K=3K = 3 abilities researched.

Since you fought bosses 33 and 44 with all K=3K = 3 abilities researched, bb is equal to 22 and the score of this playthrough is b2=4b^2 = 4.

Task

What is the sum of the scores of all possible playthroughs? Two playthroughs are considered different if there exists a boss ii (0i<N0 \le i < N) that you fight having a different subset of abilities researched.

Since the answer can be large, print its remainder modulo MODMOD, where MODMOD is a prime number given in the input.

Input data

The first line of input contains three integers NN, KK and MODMOD: the number of bosses, the number of abilities, and the modulo.

Output data

Print one integer, the sum of the scores of all possible playthroughs modulo MODMOD.

Constraints and clarifications

  • 1N10181 \le N \le 10^{18}
  • 1K1 000 0001 \leq K \leq 1 \ 000 \ 000
  • 108MOD109+710^8 \le MOD \le 10^9+7 and MODMOD is a prime number.
# Points Constraints
1 0 Examples
2 9 N,K100N,K \leq 100
3 5 N,K1 500N,K \leq 1 \ 500
4 8 N1 000 000N \leq 1 \ 000 \ 000
5 7 K2K \leq 2
6 15 K5K \leq 5
7 29 K100K \leq 100
8 18 K1 500K \leq 1 \ 500
9 9 No additional constraints

Example 1

stdin

3 2 100000007

stdout

26

Explanation

In this sample case, there are N=3N = 3 bosses and K=2K = 2 abilities.

A playthrough is denoted as a sequence of N=3N = 3 sets s0s1s2s_0 \subseteq s_1 \subseteq s_2, where:

  • s0{0,1}s_0 \subseteq \{0,1\} is the subset of the abilities researched before facing boss 00;
  • s1{0,1}s_1 \subseteq \{0,1\} is the subset of the abilities researched before facing boss 11;
  • s2{0,1}s_2 \subseteq \{0,1\} is the subset of the abilities researched before facing boss 22.

In total, there are 1616 different playthroughs:

  • [{},{},{}][\{\},\{\},\{\}], with a score of 02=00^2=0.
  • [{},{},{0}][\{\},\{\},\{0\}], with a score of 02=00^2=0.
  • [{},{0},{0}][\{\},\{0\},\{0\}], with a score of 02=00^2=0.
  • [{0},{0},{0}][\{0\},\{0\},\{0\}], with a score of 02=00^2=0.
  • [{},{},{1}][\{\},\{\},\{1\}], with a score of 02=00^2=0.
  • [{},{1},{1}][\{\},\{1\},\{1\}], with a score of 02=00^2=0.
  • [{1},{1},{1}][\{1\},\{1\},\{1\}], with a score of 02=00^2=0.
  • [{},{},{0,1}][\{\},\{\},\{0,1\}], with a score of 12=11^2=1.
  • [{},{0},{0,1}][\{\},\{0\},\{0,1\}], with a score of 12=11^2=1.
  • [{0},{0},{0,1}][\{0\},\{0\},\{0,1\}], with a score of 12=11^2=1.
  • [{},{1},{0,1}][\{\},\{1\},\{0,1\}], with a score of 12=11^2=1.
  • [{1},{1},{0,1}][\{1\},\{1\},\{0,1\}], with a score of 12=11^2=1.
  • [{},{0,1},{0,1}][\{\},\{0,1\},\{0,1\}], with a score of 22=42^2=4.
  • [{0},{0,1},{0,1}][\{0\},\{0,1\},\{0,1\}], with a score of 22=42^2=4.
  • [{1},{0,1},{0,1}][\{1\},\{0,1\},\{0,1\}], with a score of 22=42^2=4.
  • [{0,1},{0,1},{0,1}][\{0,1\},\{0,1\},\{0,1\}], with a score of 32=93^2=9.

The sum of the scores across all possible playthroughs is 07+15+34+9=0+5+12+9=260 \cdot 7 + 1 \cdot 5 + 3 \cdot 4 + 9 = 0 + 5 + 12 + 9 = 26.

Example 2

stdin

5 3 998244353

stdout

517

Example 3

stdin

999013 97 998244853

stdout

116848898

Example 4

stdin

958613246711292682 1000000 1000000007

stdout

112173097

Log in or sign up to be able to send submissions!