Dinosaurs lived in nests, numbered from to . The roads between the nests formed a tree.
Starting on night , consider the nests that have not yet been evacuated. Every such nest with roads directly connecting it to at most one other such nest is evacuated. These evacuations happen simultaneously, using the nests remaining at the start of the night.
The map has been lost. You are given an array , where is the night on which nest was evacuated.
For each test case, compute , the number of different maps consistent with this information, modulo . If no consistent map exists, the answer is . Two maps are different if their sets of roads are different. A road is an undirected edge between two distinct nests.