#P2837. Minimizing Card Changes for Grouped Cow Dining

    ID: 16096 Type: Default 1000ms 256MiB

Minimizing Card Changes for Grouped Cow Dining

Minimizing Card Changes for Grouped Cow Dining

FJ wants the cows to dine in two batches. Initially, the cows are lined up and each cow carries a card with a dining batch number (either \(1\) or \(2\)). Unfortunately, the cards are in completely random order. In order to avoid overcrowding, FJ intends to have all cows of one batch standing together and all cows of the other batch standing consecutively. In other words, the final order should be of the form \(111...222\) or \(222...111\); note that it is also acceptable for all cows to be in only one group (\(1111\) or \(222\)).

Since FJ is lazy, he wishes to modify as few cards as possible, while keeping the cows in their original positions. Given the current order, determine the minimum number of card modifications required to achieve an arrangement where the cows in each dining batch stand consecutively.

inputFormat

The first line contains an integer \(N\) (\(1 \le N \le 10^5\)), the number of cows.

The second line contains a string of length \(N\) consisting only of the characters 1 and 2, representing the current dining batch numbers of the cows.

outputFormat

Output a single integer representing the minimum number of card modifications needed so that the cows with the same dining batch are contiguous in the line.

sample

6
112222
0

</p>