Infinite Binary Embedding

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

Vasya has got himself an infinite binary tree TT, which can be formally described as follows: TT has infinitely many vertices, which are numbered starting from 11. Each vertex of TT has two children --- left son and right son. The left son of the vertex ii is the vertex 2i2 i, and the right son of the vertex ii is the vertex 2i+12 i + 1.

Also, Vasya has another binary tree GG (quite fortunately, a finite one). Every vertex of GG is either an internal vertex or a leaf. An internal vertex has a left son and a right son (and is called the parent of its children), and a leaf vertex has no children. Each vertex has exactly one parent, except for one vertex which has no parent; this vertex is called the root of the tree GG.

Vasya would like to embed the tree GG in the infinite tree TT. Formally, an embedding is defined as a function f:V(G)V(T)f: V(G) \rightarrow V(T) (here V(X)V(X) is the set of vertices of the tree XX) with the following property: if the vertex vv is a left (alternatively: right) son of the vertex uu in GG, then the vertex f(v)f(v) must lie in the subtree of the left (alternatively: right) son of the vertex f(u)f(u) in TT.

Informally, an embedding is a way to put the vertices of GG somewhere on TT so that if we draw paths between all the embedded vertices and their children, the drawing looks like GG with some of the edges possibly extended downwards (looking at the pictures for the sample cases might help to understand the notion better).

Additionally, for each leaf vertex vv Vasya has chosen a number h_vh\_v --- the height of the vertex of TT that vv should be embedded to (the height of a vertex is the number of edges between the vertex and the root of the tree). That is, height(f(v))=h_v\text{height}(f(v)) = h\_v must hold for every leaf vv of the tree GG.

Now, Vasya wants to know the number of different embeddings of GG in TT such that each leaf vv is embedded to a vertex with height h_vh\_v. As the number may be quite large, find it modulo 109+710^9 + 7.

입력

The first line contains one integer nn --- the number of vertices of GG (1n20001 \leq n \leq 2000).

The next nn lines describe the tree GG and the numbers h_vh\_v.

If the ii-th vertex is an internal vertex, then the first number in the ii-th line will be 00, followed by the numbers of its left and right sons respectively.

If the ii-th vertex is a leaf, then the first number in the ii-th line will be 11, followed by the number h_ih\_i for this leaf. All h_ih\_i satisfy 0h_i1090 \leq h\_i \leq 10^9.

It is guaranteed that the root of GG is the vertex 11.

출력

Print one integer --- the number of appropriate embeddings modulo 109+710^9 + 7.

힌트

All six possible embeddings for the first sample (note that the root of GG does not have to coincide with the root of TT):

All fourteen possible embeddings for the second sample: