#D4535. Transparent Mahjong
Transparent Mahjong
Transparent Mahjong
F: Transparent mahjong tiles
You will play mahjong against Mr. Takanosu, a gambler who is rumored to have fallen into the darkness. Mr. Takanosu has been rumored to be a natural disaster, so he has proposed a game using a bizarre mahjong tile called Takanosu tile.
Mahjong is a game in which players hold multiple tiles called hand tiles, and their hand tiles are no longer more than their opponents, and the victory is confirmed by making them into the shape of an agari. On the front side of the mahjong tile, what the tile is is drawn, and on the back side of the tile, nothing is drawn. Therefore, when you play mahjong, you should face the front side of your Tehai to your side and the back side to the player's side. This way, only you can know what your Tehai is. The real thrill of mahjong is that players read each other's arrangements and enjoy it.
However, Takanosu tiles are transparent mahjong tiles. Since the Takanosu tiles are transparent, players can know each other's hand tiles. With this, you cannot enjoy reading the arrangements.
"This is no longer a mahjong tile." If you are not convinced to use the mahjong tiles, as a result of twists and turns with Mr. Takanashi, you will play a mixture of mahjong tiles and ordinary mahjong tiles. It was.
As a starting point, you decide to predict what Takanosu's Tehai tiles are. Mr. Takanosu's hand tiles consist of Takanosu tiles and ordinary tiles. For the sake of simplicity, the Takanosu tiles and ordinary tiles shall consist of 4 tiles of 12 types from 1 to 12.
For a hand tile consisting of 3n + 2 tiles, the hand tile is agari when the following three conditions are met.
- There is one set of tiles that combines the same numbers
- The remaining 3n tiles are n groups of 3 number combinations.
- Each group is either a combination of three identical numbers or a combination of three consecutive numbers.
For example
1 1 1 3 3 3 5 5 5 7 7 7 8 9
All 14 tiles like this are made up of Takanosu tiles. In this case, one combination of two tiles and four groups can be made as follows, which is Agari.
(1 1 1) (3 3 3) (5 5 5) (7 7) (7 8 9)
Next, we will give an example of a hand tile that is a mixture of ordinary tiles and Takanosu tiles.
1 1 1 3 3 3 5 5 5 7 7 7 * *
14 tiles like this are composed of 12 Takanosu tiles and 2 ordinary tiles (*). In this case, two ordinary tiles may be 8 and 9, so one combination of two tiles and four groups can be made, which may be agari.
(1 1 1) (3 3 3) (5 5 5) (7 7) (7 [8] [9])
For the same example, two ordinary tiles may be 8 and 8 as follows, so it may be an agari of the form:
(1 1 1) (3 3 3) (5 5 5) (7 7 7) ([8] [8])
However, since the same tile of 7 can only be used up to 4 tiles, it is not an agari of the following shape.
(1 1 1) (3 3 3) (5 5 5) (7 7 7) ([7] [7])
When Mr. Takanashi's 3n + 1 hand tile is given as an input, consider adding one tile to Mr. Takanashi's hand tile to make 3n + 2 hand tiles. At this time, find all the additional tiles (Agari tiles) that can turn 3n + 2 hand tiles into Agari.
Input
The input is given in the following format.
n Tile 1 Tile 2 ... Tile 3n + 1
The input data satisfies the following conditions, and n satisfies 0 <= n <= 15. Each tile is a Takanosu tile or an ordinary tile. In the case of Takanosu tiles, it is represented by an integer of 1 or more and 12 or less, and in the case of ordinary tiles, it is represented by the character *.
Output
Output the list of tiles in ascending order. Output a line break each time you output one tile. If you don't have a tile, display -1 on one line.
Sample Input 1
Four 1 1 1 3 3 3 5 5 5 7 7 7 9
Sample Output 1
8 9
Sample Input 2
Four 1 2 2 3 3 4 5 6 7 8 8 8 9
Sample Output 2
1 Four 7 9 Ten
Sample Input 3
Four 1 1 1 4 4 4 7 7 7 8 8 9 *
Sample Output 3
6 7 8 9 Ten 11
Sample Input 4
Four 1 * * * * * * * * * * * *
Sample Output 4
1 2 3 Four Five 6 7 8 9 Ten 11 12
Sample Input 5
1 3 * 1 4
Sample Output 5
1 2 Four Five
Example
Input
4 1 1 1 3 3 3 5 5 5 7 7 7 9
Output
8 9
inputFormat
input, consider adding one tile to Mr. Takanashi's hand tile to make 3n + 2 hand tiles. At this time, find all the additional tiles (Agari tiles) that can turn 3n + 2 hand tiles into Agari.
Input
The input is given in the following format.
n Tile 1 Tile 2 ... Tile 3n + 1
The input data satisfies the following conditions, and n satisfies 0 <= n <= 15. Each tile is a Takanosu tile or an ordinary tile. In the case of Takanosu tiles, it is represented by an integer of 1 or more and 12 or less, and in the case of ordinary tiles, it is represented by the character *.
outputFormat
Output
Output the list of tiles in ascending order. Output a line break each time you output one tile. If you don't have a tile, display -1 on one line.
Sample Input 1
Four 1 1 1 3 3 3 5 5 5 7 7 7 9
Sample Output 1
8 9
Sample Input 2
Four 1 2 2 3 3 4 5 6 7 8 8 8 9
Sample Output 2
1 Four 7 9 Ten
Sample Input 3
Four 1 1 1 4 4 4 7 7 7 8 8 9 *
Sample Output 3
6 7 8 9 Ten 11
Sample Input 4
Four 1 * * * * * * * * * * * *
Sample Output 4
1 2 3 Four Five 6 7 8 9 Ten 11 12
Sample Input 5
1 3 * 1 4
Sample Output 5
1 2 Four Five
Example
Input
4 1 1 1 3 3 3 5 5 5 7 7 7 9
Output
8 9
样例
4
1 1 1 3 3 3 5 5 5 7 7 7 9
8
9
</p>