#P7657. [BalticOI 2007] Connected Points (Day 2)
[BalticOI 2007] Connected Points (Day 2)
Description
Consider a regular grid with points. Each point in the grid has at most eight adjacent points (see Figure ).

We are interested in counting the number of different ways to connect the grid points to form a polygon that satisfies the following conditions:
- The set of vertices of the polygon consists of all points.
- Adjacent vertices of the polygon are adjacent points in the grid.
- Each polygon must be simple, i.e., it must not have any self-intersections.
Two possible polygons when are shown in Figure .

Write a program that, for a given , computes the number of possible ways to connect the points. Output the answer modulo .
Input Format
The only line contains a positive integer .
Output Format
The only line contains one integer: the number of ways to connect these points modulo .
3
8
4
40
Hint
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, .
Notes
This problem comes from Baltic Olympiad in Informatics 2007, Day 2:points.
Translated and整理 (zhěng lǐ, organized) by @求学的企鹅.
Input Format
Output Format
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号