Mahjong Hands
Output: Standard Output (stdout)
Memory limit: 64 megabytes
Time limit: 1.0 seconds
Mahjong is a game played with tiles. Each tile is numbered from 1 to 9, and belongs to one of three suits, PIN, BAMBOO, or CHARACTER. There are 4 tiles for each number and suit combination (so 9 \times 3 \times 4 = 108 tiles in total).
Tiles of the same suit can be formed into tile groups. Three tiles of the same suit and number is called a SET. Three tiles of the same suit in consecutive numbering is called a STRAIGHT. For example, three tiles of the PIN suit with the numbers 4, 5, 6 would be a valid tile group because it is a STRAIGHT.
When forming tile groups, the same tile cannot be used in more than one tile group. For example, four tiles of the PIN suit with the numbers 4, 5, 6, 7 would not count as two tile groups, but can only be formed into one tile group with one tile remaining unused.
A Mahjong hand contains 14 tiles. A hand is COMPLETE if the tiles can be formed into 4 tile groups as well as a remaining pair of identical tiles (that is, they have the same suit and number). However, to win a game of Mahjong, your hand must not only be COMPLETE, but must also satisfy a win condition. A Mahjong hand is SIMPLE if it contains no tiles numbered 1 and no tiles numbered 9. You win if your hand is both COMPLETE and SIMPLE.
Your job is to figure out whether a Mahjong hand is COMPLETE or SIMPLE or both.
Input
The first line will contain three space-separated integers, the number of PIN, BAMBOO, and CHARACTER tiles. The total number of tiles will always be equal to 14.
The second line will contain a sorted list of space-separated integers denoting the numbers on the PIN tiles.
The third line will contain a sorted list of space-separated integers denoting the numbers on the BAMBOO tiles.
The fourth line will contain a sorted list of space-separated integers denoting the numbers on the CHARACTER tiles.
Each list of tile numbers will appear in sorted order.
Output
Print out:
- WIN if the hand is simple and also complete.
- COMPLETE if the hand is complete but not simple.
- SIMPLE if the hand is simple but not complete.
- SAD if the hand is not simple or complete.
Subtasks
- Subtask 1 (10%): No tiles have the same suit and number.
- Subtask 2 (20%): Each suit contains 3 tiles numbered 1, with the remaining 5 tiles being numbered 2.
- Subtask 3 (30%): There are only 2 tiles in the PIN suit and they are the same number. Also, there are at most 9 tiles in a suit.
- Subtask 4 (40%): No constraints.
Explanation
In sample case 1, the PIN tiles form a straight (2, 3, 4) and the CHARACTER tiles form three SETs (2, 2, 2 and 3, 3, 3 and 4, 4, 4) and a pair (5, 5) which means the hand is COMPLETE. Since there are no tiles numbered 1 or 9, the hand is also SIMPLE. Since the hand is COMPLETE and SIMPLE, we WIN.
Alternatively, the CHARACTER tiles could form three STRAIGHTs instead of three SETs (2, 3, 4 and 2, 3, 4 and 2, 3, 4).
In sample case 2, it is impossible to form 4 tile groups with a remaining pair of identical tiles. The hand is also not SIMPLE as there are tiles numbered 1 (in the PIN suit).
-
Sample Input 1
3 0 11 2 3 4 2 2 2 3 3 3 4 4 4 5 5
Sample Output 1
WIN
-
Sample Input 2
3 3 8 1 1 1 2 2 2 3 3 3 4 5 6 7 9
Sample Output 2
SAD