P4907 A Swap B problem
Background
The fairy and Xiao Ben made a deal: to get the magic medicine, he must beat her in a card game.
Description
They are about to start playing cards. However, Xiao Ben, who has obsessive-compulsive tendencies, feels very unhappy when looking at the cards in his hand. The reason is that he sorts cards by suit (are you kidding me), and he also hopes that the cards of the same suit are consecutive ($A-2-3-4-5-6-7-8-9-10-J-Q-K$).
Having had enough, Xiao Ben starts swapping cards with the other players (cheating???). He wants to swap as few cards as possible to meet his requirement (assume any card can be swapped).
Swap rule: you can only swap cards with the same rank.
Everyone: Can you just play properly?! We give you 1 second to finish swapping, or we will tell the fairy!
Input Format
The first line contains a positive integer $N$, meaning Xiao Ben has $N$ cards.
The next $N$ lines each contain two positive integers, representing the suit and the rank of a card.
Output Format
There are two lines in total:
The first line is a judgment: if it can be completed, output `Yes`, otherwise output `No`.
The second line outputs the minimum number of swaps, or the minimum number of cards needed.
Explanation/Hint
Sample 1: achievable. Swap $2$ $3$ to $1$ $3$, and swap $4$ $J$ to $3$ $J$.
Sample 2: achievable. Swap $2$ $3$ to $1$ $3$, and swap $3$ $Q$ to $4$ $Q$.
(The above answers are for reference only. There may be multiple solutions, but the output is definitely unique. ~~Do not ask me why~~.)
For $10\%$ of the testdata: it is sample $2$.
For $100\%$ of the testdata: $N \leq 52$, meaning the data is guaranteed to be within one deck of cards.
Translated by ChatGPT 5