Under construction

Still being built. Things may change

Confusion

Time limit5sMemory limit1024 MB

Summary
Count the simple cycles in a triangulated convex polygon with N vertices, given its N-3 non-crossing diagonals, modulo 1e9+7.
Level

Medium7 of 10

Topics
Graph, Dynamic programming, Tree
Solved
No attempts yet

Problem

Mr. Malnar decided to spend his summer traveling around the world by flying randomly. After some time, he found himself in an unknown country's capital, where the streets reminded him of a triangulation. More precisely, the city consists of NN interesting locations numbered from 11 to NN, connected by 2N−32N - 3 streets. Locations 1,2,…,N1, 2, \dots , N are connected in that order to form a convex polygon with NN sides. The remaining N−3N - 3 streets connect locations so that no two streets cross, except possibly at their ends.

While walking the streets, Mr. Malnar returned to the location where he started without visiting any location more than once. He decided this is normal and defined the confusion of the city as the number of simple closed loops.

A simple closed walk is a sequence of locations V1,V2,…,VmV_1, V_2, \dots , V_m such that ViV_i is connected by a street to Vi+1V_{i+1} for every i=1,2,…,m−1i = 1, 2, \dots , m - 1, and VmV_m is connected by a street to V1V_1. Two walks are equivalent if one can be obtained from the other by a cyclic rotation or by reversing it. For example, the walk (1,2,3,4)(1, 2, 3, 4) is equivalent to the walk (2,3,4,1)(2, 3, 4, 1). A simple closed loop is a set of equivalent walks.

Mr. Malnar asks you to calculate the confusion of this city.

Input

The first line contains an integer NN (1≤N≤2⋅1051 \le N \le 2 \cdot 10^5), the number of locations.

Each of the next N−3N - 3 lines contains two integers XiX_i and YiY_i (1≤Xi,Yi≤N1 \le X_i, Y_i \le N), the labels of the locations connected by the ii-th street.

Output

Print the confusion of the city modulo 109+710^9 + 7.

Examples3

  1. Example 1

    Input
    4
    1 3
    
    Expected output
    3
    
  2. Example 2

    Input
    5
    1 3
    3 5
    
    Expected output
    6
    
  3. Example 3

    Input
    6
    2 4
    4 6
    6 2
    
    Expected output
    11