Tung Tung Sahur
Tung is hard at work helping out with the ACPC committee when he realises he messed up the simple task he was assigned. He was meant to be sorting a pile of cards into a specific order for a game, but now he can't remember what order they are in.
To make matters worse, Tung is stressing out now so he can't think clearly! He has a stack of cards in some order he forgot, and he can only take cards from the top of that deck, and place them either onto the final presentation table, or a side table. He wants them to end up in sorted order, with the biggest number on the top, on the presentation table, but he can place them into a pile on the side table and retrieve the most recently added card from the side table to place on the presentation table at any time to help him out.
Can you help Tung fix his mistakes, or will he end up losing his friends and being booted from the committee?
Input
The first line contains a single integer
, the number of cards in Tung's deck.
The next line contains space-separated integers. Each card is labelled
through
and appears once in the input. The first inputted number represents the top of the pile (i.e., the one that can be accessed first).
Output
If you can end up with the cards in sorted order on the presentation by always either taking the top card from the input and placing it on the top of the presentation table or side table, or taking the top card from the side table and placing it on top of the presentation table, print "Tung Tung Tung" on a line. If you can't, print "Mamma Mia!"
Example
Input 1
5
4 2 1 3 5
Output 1
Tung Tung Tung
It is possible to place all the cards in sorted order on the presentation table. First, we place on the side table, then we place
on the side table. Then, we place
on the presentation table. Next, we retrieve
from the side table onto the presentation table, and place
on the presentation table. Finally, we place
from the side table onto the presentation table and top it off with
. The presentation table contains
with
at the top so we were successful.
Input 2
5
1 3 4 2 5
Output 2
Mamma Mia!
In this case, it is impossible to get sorted order on the presentation table. We can place 1 onto the presentation table, and 3 and 4 onto the side table. Then, we can place 2 onto the presentaion table. However, the next required card is , and the cards at the top of the input and side table stacks are
and
, so we cannot proceed.
Comments