Joining Points
Time limit1sMemory limit512 MB
Count the sets of n non-crossing arcs on a circle, each joining two same-colored points with no point of that color inside the arc.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
You are given different points on a circle. Each point is colored with one of colors, and each color appears exactly three times.
You want to draw non-intersecting arcs, with ends on the given points. For each arc, the two ends have the same color, and no other point on that arc has this color.
Note that you are drawing arcs, not chords.
Find the number of suitable drawings, modulo .
Input
The first line contains one integer (), the number of colors.
The next line contains integers (), the color of the -th point on the circle in clockwise order. It is guaranteed that each color appears exactly three times.
Output
Print one integer: the number of suitable drawings modulo .