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

USU Championship 2006

About     Problems     Submit solution     Judge status     Standings
Contest is over

I. ACM Poker

Time limit: 1.0 second
Memory limit: 64 MB
On the train back from Petrozavodsk, Dima and Sasha decided to play poker. Artyom came from a neighboring compartment and volunteered to be the dealer. The most popular type of poker among students of the Department of Mathematics and Mechanics is the ACM poker, which is similar to the three-card poker. The rules are very simple. A pack of 52 cards is used. The players receive from the dealer three cards each and make bets according to their estimates of their winning chances. After that, they open the cards. The player with the best combination of cards wins.
Sasha plays fairly and Dima, of course, cheats. He sits on an upper berth and can see Sasha's cards. Also, he has in his sleeve two additional cards and can replace one or two of his cards by the cards in the sleeve without anybody seeing it. Naturally, he will not use for the replacement a card that he or Sasha already have, otherwise suspicions may arise when two identical cards are discovered. Before making a bet, Dima tries to imagine all possible cases and determine precisely whether he can win. You should try to do this for him.
Combinations of cards (or hands) are ranked as follows. A combination of three 3s is the best. Then there go (in the descending order) “straight flush”, which contains three cards of the same suit in sequence (for example, 9, 10, and Jack of Spades); “three of a kind”, which contains three cards of the same rank; “straight”, which contains cards of sequential rank; “flush”, in which the cards are of the same suit; and “two of a kind”, which contains two cards of the same rank. If the players have equal hands or if no player has any of the above-listed combinations, then the hands are compared according to the ranks of their best cards. Individual cards are ranked as follows (in the descending order): Ace, King, Queen, Jack, 10, 9, …, 2. If the best cards are equal, then the next highest ranking cards are compared; if those are equal, then the third cards are compared; if they are equal, then there is a tie and the pot goes to the dealer. If both players have “two of a kind”, then the ranks of paired cards are compared first, and if they are equal, then the ranks of the thirds cards are compared. Hands containing A, 2, and 3 or K, A and 2 are not considered to be straights. If Dima cannot win, he prefers a tie to a defeat.


The input contains several tests separated by an empty line. The first line of each test describes Sasha's cards, the second line describes Dima's cards, and the third line describes the two cards in Dima's sleeve. Artyom has fairly dealt out cards from one pack, so the first six cards are different. Each card is described by its rank and suit given together. The suits are denoted by the letters S for Spades, C for Clubs, D for Diamonds, and H for Hearts. There are no Jokers in this game.


If Dima can win, then output “Dima”. If he cannot win, but can arrange a tie, then output “Artyom”. Otherwise, output “Sasha”.


4C AC 2C
4S KD 6H

8C 8D 10H
8H 10H

10D 8D 9D
3D 3C 3H

2C 3D 4H
2D 3H 4S
Problem Author: Vladimir Yakovlev
Problem Source: The XIth USU Programing Championship, October 7, 2006
To submit the solution for this problem go to the Problem set: 1488. ACM Poker