#P2837. [USACO08FEB] Dining Cows B
[USACO08FEB] Dining Cows B
Description
To avoid overcrowding in the dining hall, FJ requires the cows to eat in batches. Every day before dinner, the cows line up in front of the dining hall to enter. According to FJ’s plan, all cows in batch stand at the end of the line, while the front part of the line is occupied by cows designated as batch .
Since the cows do not understand FJ’s arrangement, lining up before dinner has become a big hassle. Cow holds a card that indicates her dining batch . Although all cows stand in a neat line, it is obvious that the numbers on the cards are completely jumbled. After several chaotic re-lineups, FJ finds a simpler method: without moving the cows, he walks from the head to the tail of the line and changes the number on the card of any cow he believes is in the wrong batch, eventually obtaining a line in which all cows of each group stand together, for example, or . Sometimes, FJ will even make the entire line consist of only group (for example, or ).
You also know that FJ is lazy. He wants to know the minimum number of cows’ card numbers he must change to achieve his goal. None of the cows moves while FJ is changing the card numbers.
Input Format
The first line contains an integer ().
Lines to each contain integer, the dining batch of the -th cow ().
Output Format
Output integer, the minimum number of cows’ card numbers FJ must change to make the sequence match his plan.
7
2
1
1
1
2
2
1
2
5
2
2
1
2
2
1
Hint
Constraints: .
Translated by ChatGPT 5
京公网安备 11011102002149号