#P7513. [2017年杭电多校]Mystery

[2017年杭电多校]Mystery

Mystery

Problem Description

HazelHazel would like to find out everything about the binary tree. She has a full binary tree ,each point has different labels. regarding each point of tree ,HazelHazel defines its height hih_i being the number of points which the shortest path from this point to a leaf has. each point has weight AiA_i which be defined as XhiX^{h_i}. HazelHazel wants to paint every points by color BiB_i,Observing the following rules:  iT,BiN\bullet\ \forall i\in T,B_i\in N  iT,BiBfai\bullet\ \forall i\in T,B_i\ge B_{fa_i} $\bullet\ Y\ge 2\times \sum_{i\in leaf} B_i-\sum_{i\in T}B_i$ (define Bfaroot=0B_{fa_{root}}=0 ) HazelHazel defines the contribution of the tree SS as iTAi×Bi\sum_{i\in T}A_i\times B_i. She wants to know how many legal methods can she paint the tree,which cause SS is multiple of PP. You need to print ans mod(109+7)ans \ mod (10^9+7).

Input

4 positive integerHH,XX,YY,PP(1H10181\le H\le 10^{18},1X5001\le X\le 500,0Y100\le Y\le 10,1P5001\le P\le 500,PP is a prime number). HHmeans the tree has2H12^H-1 points.

Output

an integer showing ans mod(109+7)ans \ mod (10^9+7).

Sample Input

2

8 10 7 11

34819237827249996 146 5 349

Sample Output

630072624

673102984

Source

2017 Multi-University Training Contest - Team 7

https://acm.hdu.edu.cn/showproblem.php?pid=6132