Not East Two in This Match! 1
Time limit1sMemory limit1024 MB
Count the ways to pick 14 of the N drawn tiles that split into 1 pair and 4 sets, or into 7 distinct pairs.
- Level
Medium5 of 10
- Topics
- Combinatorics, Backtracking, Implementation
- Solved
- No attempts yet
Rules
Mahjong is a game where you collect tiles to make a dragon. To make a dragon, you need to understand tiles, pairs, and sets.
- Tile: Mahjong has tiles for each number from to .
- Pair: Two tiles with the same number.
- Set: Three tiles with consecutive numbers that differ by , or three tiles with the same number. The order of the tiles does not matter.
The table below shows which combinations are pairs or sets and which are not.
To make a dragon, you must arrange tiles into pair and sets, or into different pairs.
The examples below show a dragon and a non-dragon.
Input
The first line contains the number of tiles in the wall.
The second line contains separated by spaces. No tile type appears more than times.
Output
Print the number of ways to draw tiles from the wall so that they form a dragon.
Hints
- Two draws that produce the same numbers but use tiles at different positions are counted as different ways.
- If a set of tiles can form a dragon in several ways, it is counted once.