- Time limit: 1.00 s
- Memory limit: 512 MB
You are given a binary tree with nodes numbered . The root of the tree is node . Your task is to determine how many ways there are to pair connected nodes so that each node is paired up with at most one another node.
As the number of ways may be large, output the result modulo .
Input
The first line of the input contains a single number, , the number of nodes in the tree.
Next lines each contain two integers, and , describing the left and right child of node. is the index of left child of node and is the index of right child of node. Index means that no node is connected as a child.
Output
A single line, result modulo .
Limits
Example
Input:
7 5 6 0 0 4 0 2 0 3 7 0 0 0 0
Output:
19
Explanation: