Time Limit: 2 Seconds
Memory Limit: 65536 KB
Koumakan's daily life is peace as usual, but Izayoi Sakuya feels a little bored.So she assembles his friends to play mahjong.But she soon finds that not only Scarlet sisters,Patchouli is also very good at mahjong. Among the table, there is a only one green hand:herself. After losing for times, her mood boils. She wants to win, even cheating by using magic. Her magic could help her to change the tile to she wants. But If it was found, she would lose the game again directly, the more times she uses magic, the higher possibility of being found cheating. Now, you have known the cards you have, please help Izayoi to find the minimum steps to get the ready hand.
Mahjong is a game of skill, strategy and calculation and involves a certain degree of chance. In this problem, we concentrate on Japanese Mahjong, a variation of mahjong. For brief, all of the word mahjong mentioned following refer to Japanese Mahjong.
Japanese mahjong is usually played with 136 tiles, which can be organized into several categories:
A winning hand consists of fourteen tiles, which is made of four melds (a specific pattern of three pieces) and the eyes (a pair of two identical pieces). The definition of melds and eyes is given as followed:
In this problem, we introduce two abnormal kinds of winning hand different from the normal winning hand, which consist of four melds and one eyes.
When a hand is one tile short of winning, the hand is said to be a ready hand, or more figuratively, "on the pot".
1111M doesn't mean two pairs.And you can't get the same 5-th tile to win.
For example: you have 1111M and you want 1M to win, it doesn't mean the ready hand.
1 - 7Z stands for East, South, West, North, Red, Green and White
P, S, M stands for The circle, The bamboo, The character
Izayoi and her friend will play many times.Her tiles' number is always 13.She will tell you her hand.
You need to tell her the number that the minimum magic she make.