题目描述
Problem Background
A straight flush refers to a set of poker cards that are of the same suit and have consecutive numbers.
Problem Description
I currently have $n$ poker cards, but they may not form a straight flush. I want to know the minimum number of cards I need to replace to make these $n$ cards form a straight flush.
Input Format
The first line contains an integer $n$, representing the number of poker cards.
The next $n$ lines each contain two integers $a_i$ and $b_i$. $a_i$ represents the suit of the $i$-th card, and $b_i$ represents the number of the $i$-th card.
Output Format
A single line containing an integer, representing the minimum number of cards that need to be replaced to achieve the goal.
Sample Input and Output
Sample Input #1
5
1 1
1 2
1 3
1 4
1 5
Sample Output #1
0
Sample Input #2
5
1 9
1 10
2 11
2 12
2 13
Sample Output #2
2
Notes
- For $30\%$ of the data, $n \le 10$;
- For $60\%$ of the data, $n \le 10^5$, $1 \le a_i \le 10^5$, $1 \le b_i \le n$;
- For $100\%$ of the data, $n \le 10^5$, $1 \le a_i, b_i \le 10^9$;
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分
样例输入
5
1 1
1 2
1 3
1 4
1 5
样例输出
0