ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

УрКОП 2020

About     Problems     Submit solution     Judge status     Standings
Contest is over

C. Mahjong

Time limit: 1.0 second
Memory limit: 256 MB
Recently Keikumusume started to play Riichi Mahjong. Despite the strange and complicated rules, the biggest problem is to quickly determine the state of the hand.
The game consists of multiple tiles. Each tile has a suit (letter a, b or c) and a number (from 1 to 9), a hand contains 14 randomly drawn tiles. The hand is considered winning if it contains 4 triples and one pair; it’s considered ready if one tile needs to be replaced for the hand to become winning. If the above-mentioned conditions are not met, the hand is considered not ready. It is also important to note that a tile used in a pair or a triple cannot be used for any other pair or triple.
A pair is 2 identical tiles, for example (1a, 1a).
There are two types of triples:
  • Triplet — 3 identical tiles, for example (1a, 1a, 1a) is a correct triplet, but (1a, 1b, 1c) is not.
  • Sequence — 3 tiles with the same suit and consecutive numbers (forming a progression with step 1). For example (1a, 2a, 3a) or (4c, 5c, 6c) are correct sequential triples; while (1a, 2a, 4a), (1a, 2b, 3c) or (1c, 3c, 5c) are not.
Make Keikumusume’s life easier by writing a program that will determine the state of the hand.

Input

There is exactly one line with descriptions of 14 tiles, separated by spaces. Each tile is described with a pair of characters (a number from 1 to 9 and a suit a, b or c). It is guaranteed that the hand has no more than 4 tiles of each type (however, in the case of a ready hand, it is allowed to have 5 tiles of the same type after a replacement).

Output

Output a single line — state of the given hand, described with one of the following words: “Tsumo” (winning), “Tenpai” (ready) or “Noten” (not ready).

Samples

inputoutput
1a 2a 3a 6a 7a 8a 5b 5b 5b 9c 8c 7c 1c 1c
Tsumo
1a 2a 3a 6a 7a 8a 5b 5b 5b 9c 8c 7c 1c 1b
Tenpai

Notes

In the first test, we can make three sequential triples (1a, 2a, 3a), (6a, 7a, 8a), (7c, 8c, 9c), one triplet (5b, 5b, 5b) and a pair (1c, 1c). In total, we will get exactly 4 triples and one pair, so the hand is considered winning.
In the second example, for the hand to become winning, we need to replace a tile 1c with a tile 1b or vice versa, so the hand is considered ready.
Problem Author: Ivan Sychev
Problem Source: Ural School Programming Contest 2020
To submit the solution for this problem go to the Problem set: 2151. Mahjong