Tommy has an unrooted tree of nodes numbered . He wishes to assign weights to all nodes on some nonempty path on this tree such that the weight of a node on this path satisfies for given . Tommy has a positive integer and further requests that the maximum absolute difference of the weight of any two nodes on this path is less than or equal to .
- How many such assignments satisfy these constraints?
- What is the sum of the sum of the weights over all such assignments?
Output the answer modulo .
Constraints
of points are awarded for the first question and of points are awarded for the second question.
Test | Properties | ||
---|---|---|---|
1 | None | ||
2-3 | None | ||
4 | None | ||
5-6 | None | ||
7-8 | For , there is an edge between and . | ||
9-10 | None |
Input Specification
The first line contains two integers .
The -th of the following lines contains two integers .
The following lines describe the edges of the tree.
Output Specification
On the first line, output the answer for the first question.
On the second line, output the answer for the second question.
Please output exactly two integers, as otherwise your submission could be graded as Presentation Error.
Sample Input
3 1
2 3
3 5
4 6
1 2
1 3
Sample Output
14
78
Comments