题目描述
Problem Description
To avoid overcrowding in the dining hall, Farmer John requires his cows to dine in two shifts. Every evening before dinner, the cows line up in front of the dining hall. According to Farmer John's plan, all cows dining in the second shift are at the end of the line, while the front half is occupied by cows designated for the first shift.
Since the cows do not understand Farmer John's arrangement, the lineup before dinner becomes a big hassle. Each cow \(i\) has a card indicating her dining shift \(D_i\). Although all \(N\) cows are neatly lined up, it is clear that the numbers on the cards are completely disorganized. After several chaotic reshuffles, Farmer John finds a simpler method: the cows remain in place, and he walks from the beginning to the end of the line, changing the numbers on the cards of the cows he believes are in the wrong position. Eventually, he wants to achieve a lineup where cows of each group are together, such as \(112222\) or \(111122\). Sometimes, Farmer John might arrange the entire lineup into just one group, such as \(1111\) or \(222\).
You know that Farmer John is quite lazy. He wants to know the minimum number of card numbers he needs to change to achieve his desired lineup. All cows remain in their positions while Farmer John changes the card numbers.
Input Format
The first line of input contains an integer \(N\) (\(1 \le N \le 3 \times 10^4\)).
Lines \(2\) to \(N + 1\) each contain one integer, representing the dining shift \(D_i\) of the \(i\)-th cow (\(1 \le D_i \le 2\)).
Output Format
Output a single integer, which is the minimum number of card numbers Farmer John needs to change to achieve his desired lineup.
Sample Input and Output
Sample Input #1
7
2
1
1
1
2
2
1
Sample Output #1
2
Sample Input #2
5
2
2
1
2
2
Sample Output #2
1
Notes
\(1 \le N \le 3 \times 10^4\)
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分