Dohyun marked N points on a sheet of paper to form a regular N-gon. The vertices are numbered 1 through N clockwise.
He then drew M−1 segments. He connected the vertices P0,P1,…,PM−1 in that order: P0 to P1, P1 to P2, and so on up to PM−2 to PM−1.
Now he wants to keep drawing so that every remaining vertex is visited exactly once and the drawing returns to P0. If the remaining vertices are visited in the order T0,T1,…,TN−M−1, he connects PM−1 to T0, T0 to T1, and so on up to TN−M−2 to TN−M−1, and finally TN−M−1 to P0. Every vertex that does not appear in P appears in T exactly once.
Every newly drawn segment must cross at least one segment that is already on the paper. The segments already on the paper include the ones drawn along P and the ones drawn earlier in this process. Two segments cross when they share a point that lies in the interior of both, so two segments that share only an endpoint do not cross.
Given N, M, and P, write a program that counts the possible orders T.