Zbunjenost
시간 제한5초메모리 제한1024 MB
볼록 다각형의 삼각분할이 주어질 때 그래프에 있는 단순 사이클의 개수를 10^9+7로 나눈 나머지를 구한다.
문제
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 streets reminded him of a triangulation! More precisely, the city consists of interesting locations numbered from to connected by streets. Locations are connected in that order to form a convex polygon with sides. Remaining streets connect locations in such a way that no two streets cross, except maybe at their ends.
While walking the streets of this country’s capital Mr. Malnar found himself at the location where he started from without visiting any location more than once. A bit confused he came to the realization that this is completely normal and came up with a measure of confusion as the number of simple closed loops. Simple closed walk is a sequence of locations such that is connected via street with location for every and that location is connected with . Two walks are equivalent if one can be obtained by a cyclic rotation of the other, or by reversing the other. For example, walk is equivalent to the walk . Simple closed loop is a set of equivalent walks. Mr. Malnar now asks for your help in calculating the confusion of this city!
입력
In the first line is an integer (), number of interesting locations.
In the next lines are integers , (), labels of locations connected by -th street.
출력
In the first and only line output the confusion of the given city modulo .