#P6454. Determine Ting Tiles in a Strange Mahjong Hand
Determine Ting Tiles in a Strange Mahjong Hand
Determine Ting Tiles in a Strange Mahjong Hand
In this problem, you are given a strange set of Mahjong tiles. There are only one type of numbered tiles from 1 to \(n\), and there are infinitely many copies of each tile.
We define a Pair (雀头) as two identical tiles (e.g. \(2,2\), \(7,7\)); a Pung (刻子) as three identical tiles (e.g. \(1,1,1\), \(4,4,4\)); and a Chow (顺子) as three consecutive numbered tiles (e.g. \(1,2,3\), \(9,10,11\); note that \(1\) and \(n\) are not consecutive). Both a Pung and a Chow are called a Meld (面子).
A hand is considered winning (和牌) if the tiles can be divided in one of the following two ways:
- All tiles form pairs (note: the pairs may be identical).
- The tiles can be partitioned into one pair and several melds (each meld is either a Pung or a Chow). The pair and melds can be identical as well.
Suppose you have drawn \(k\) tiles randomly. A tile \(x\) (where \(1\le x\le n\)) is called a ting tile if by adding one copy of \(x\) to your hand, the new hand can form a winning hand as described above.
Your task is to determine all the ting tiles.
inputFormat
The first line contains two integers \(n\) and \(k\) (\(1\leq n\leq 100\), \(1\leq k\leq 100\)), where \(n\) is the maximum number on a tile and \(k\) is the number of tiles drawn.
The second line contains \(k\) integers, each between 1 and \(n\), representing the drawn tiles.
outputFormat
Print all the ting tile numbers in ascending order separated by a single space. If there is no such tile, print -1.
sample
9 13
1 1 2 2 3 3 4 4 5 5 6 6 7
7