#P9085. [PA 2018] Wielokąty
[PA 2018] Wielokąty
Problem Description
This problem is translated from PA 2018 Round 5 Wielokąty.
You are asked to count the number of polygons that satisfy the following conditions:
- Let the -th vertex of the polygon be . Then and , .
- Any edge of the polygon (excluding its endpoints) must not pass through any lattice point (i.e., a point whose both coordinates are integers).
- The length of every edge of the polygon is an integer not greater than .
- The polygon is convex and must not be degenerate (no three collinear points, no self-intersection, and no angle ).
- Every edge of the polygon is a line segment.
Since the number of such polygons is too large, you only need to output the value modulo .
The figure below shows three invalid polygons. The first polygon has an edge passing through a lattice point, the second polygon is degenerate, and the third polygon is not convex. Also, in the first and third polygons, some edge lengths are not integers.

We consider two polygons to be different if and only if they have at least one vertex that is different.
Input Format
The input contains only one line with three positive integers .
Output Format
Output one integer in one line: the number of polygons that satisfy the conditions modulo .
6 5 5
42
Hint
Explanation for Sample 1
The figure below shows one of the valid polygons.
It can be verified that this polygon satisfies every condition.

Constraints
This problem uses bundled testdata.
For of the data, and .
Translated by ChatGPT 5