#P2837. [USACO08FEB] Dining Cows B

[USACO08FEB] Dining Cows B

Description

To avoid overcrowding in the dining hall, FJ requires the cows to eat in 22 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 22 stand at the end of the line, while the front part of the line is occupied by cows designated as batch 11.

Since the cows do not understand FJ’s arrangement, lining up before dinner has become a big hassle. Cow ii holds a card that indicates her dining batch DiD_i. Although all NN 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, 112222112222 or 111122111122. Sometimes, FJ will even make the entire line consist of only 11 group (for example, 11111111 or 222222).

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 NN (1N3×1041 \le N \le 3 \times 10 ^ 4).

Lines 22 to N+1N + 1 each contain 11 integer, the dining batch DiD_i of the ii-th cow (1Di21 \le D_i \le 2).

Output Format

Output 11 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: 1N3×1041 \le N \le 3 \times 10 ^ 4.

Translated by ChatGPT 5