Building Spanning Trees#11268

Building Spanning Trees

1 secondo
128 megabyte
Difficile

Consider an undirected, complete, simple graph on vertices. The vertices of are labeled from to . Specifically, each pair of distinct vertices is connected by a single undirected edge, so there are precisely n \cdot (n - 1) / 2 edges in this graph.

You are given a set that consists of n - 3 edges of this graph . More precisely, you are given two arrays and with n - 3 elements each. For each valid , (x_i, y_i) is one of the edges in .

A spanning tree of is a subset of exactly n - 1 edges of such that the edges connect all vertices. You may note that the edges of a spanning tree do indeed form a tree that is a subgraph of and spans all its vertices.

We are interested in spanning trees that contain all of the edges in the provided set . Find the number of such spanning trees modulo . Two spanning trees are different if there is an edge of that is in one of them but not in the other.

Input

The first line contains number n~(4 \le n \le 1000). The second and the third lines contain arrays and y~(1 \le x_i, y_i \le n) of length n - 3 each.

Output

Print the number of spanning trees modulo .

Esempi

Esempio 1

Loading
Loading

Esempio 2

Loading
Loading

Esempio 3

Loading
Loading