#P2593. Super Mahjong Winning Hand
Super Mahjong Winning Hand
Super Mahjong Winning Hand
This problem is about a variant of Mahjong called Super Mahjong. In Super Mahjong, there is no distinction between suits. Each tile is a number in the range \(1\sim100\) and there are 100 copies of each tile. A player may hold any number of tiles. A winning hand is defined as follows:
- The tiles can be partitioned into a combination of one pair and several "melds".
- A pair is two identical tiles.
- A meld can be any one of the following:
- A sequence: three consecutive numbers \((x, x+1, x+2)\) (each used exactly once).
- A triplet: three identical tiles.
- A quadruplet: four identical tiles (which counts as one meld).
In other words, given a hand of \(n\) tiles, if there exists an integer \(k \ge 1\) and nonnegative integer \(y\) such that the tiles can be partitioned into one pair (using 2 tiles) plus \(x\) melds of 3 tiles (for sequences or triplets) and \(y\) melds of 4 tiles (quadruplets), satisfying
[ n = 2 + 3x + 4y, ]
then the hand is a winning hand.
Your task is to determine whether a given hand is a winning hand.
inputFormat
The input consists of two lines. The first line contains an integer \(n\) representing the number of tiles. The second line contains \(n\) space-separated integers, each between 1 and 100, representing the tile values.
outputFormat
Output a single line containing either Yes
if the hand is a winning hand, or No
otherwise.
sample
12
1 1 2 3 4 5 5 5 7 7 7 7
Yes