Codeforces Beta Round 82 (Div. 2)
A
Card Game
Codeforces
1000
原题
←B →
翻译中…

There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.

翻译中…

To play durak you need a pack of $36$ cards. Each card has a suit ("S", "H", "D" and "C") and a rank (in the increasing order "6", "7", "8", "9", "T", "J", "Q", "K" and "A"). At the beginning of the game one suit is arbitrarily chosen as trump.

翻译中…

The players move like that: one player puts one or several of his cards on the table and the other one should beat each of them with his cards.

翻译中…

A card beats another one if both cards have similar suits and the first card has a higher rank then the second one. Besides, a trump card can beat any non-trump card whatever the cards’ ranks are. In all other cases you can not beat the second card with the first one.

翻译中…

You are given the trump suit and two different cards. Determine whether the first one beats the second one or not.

翻译中…

Input

翻译中…

The first line contains the tramp suit. It is "S", "H", "D" or "C".

翻译中…

The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the suit ("S", "H", "D" and "C").

翻译中…

Output

翻译中…

Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes).

翻译中…

样例

Input #1
H
QH 9S
Output #1
YES
InputCopy OutputCopy
Input #2
S
8D 6D
Output #2
YES
InputCopy OutputCopy
Input #3
C
7H AS
Output #3
NO
InputCopy OutputCopy
题目信息
题号
106A
时间限制
2 s
内存限制
256 MB
标签
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。