P28868 [洛谷] The A to B Problem
普及+
题目描述

Background

The fairy and Xiao Ben have made an agreement that to obtain the elixir, one must win at cards against her.

Problem Description

They are about to start playing cards. However, Xiao Ben, who has obsessive-compulsive disorder, is not happy with the cards in his hand. The reason is that he organizes the cards by suit (which is unusual) and wants the cards of each suit to be in sequence ($A-2-3-4-5-6-7-8-9-10-J-Q-K$).

Unable to bear it any longer, Xiao Ben starts to swap cards with the other players (is this cheating??). He hopes to achieve his requirement with the minimum number of swaps (assuming all cards can be swapped).

Swap Rule: Only cards with the same rank can be exchanged.

The others: Can we play cards properly?! We give you 1 second to finish swapping, or we'll tell the fairy!

Input Format

The first line contains a positive integer $N$, representing the number of cards Xiao Ben has.

Lines $2$ to $N+1$ each contain the suit and rank of the $i$-th card.

Output Format

There are two lines in total.

The first line is a judgment: if it is possible to complete, output "Yes"; otherwise, output "No".

The second line outputs the minimum number of swaps or the minimum number of additional cards needed.

Sample Input and Output

Sample Input #1

10
1 A
1 2
1 4
2 3
2 5
2 6
3 9
3 10
3 Q
4 J

Sample Output #1

Yes
2

Sample Input #2

10
1 A
1 2
1 4
2 3
2 5
2 6
3 9
3 10
3 Q
4 K

Sample Output #2

Yes
2

Notes

In Sample 1, it is possible to achieve by swapping $2$ $3$ for $1$ $3$ and $4$ $J$ for $3$ $J$.

In Sample 2, it is possible to achieve by swapping $2$ $3$ for $1$ $3$ and $3$ $Q$ for $4$ $Q$.
(The above answers are for reference only and do not guarantee uniqueness, but the output is necessarily unique, don't ask me why.)

For 10% of the data: it is the same as Sample 2.

For 100% of the data: $N \leq 52$, ensuring the data is within the scope of a standard deck of cards.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
10 1 A 1 2 1 4 2 3 2 5 2 6 3 9 3 10 3 Q 4 J
样例输出
Yes 2