#P9950. Cow Breed Transformation

    ID: 23094 Type: Default 1000ms 256MiB

Cow Breed Transformation

Cow Breed Transformation

Farmer John ordered \(N\) cows consisting of two breeds: Holstein (denoted by H) and Guernsey (denoted by G). He intended to have the breeds arranged in a string \(A\). However, when the cows arrived, they were lined up in a different order represented by string \(B\).

Using the innovative "Cow Breed Flipper 3000", which can select any contiguous substring and flip the breed of each cow (i.e. convert \(H\) to \(G\) and \(G\) to \(H\)), determine the minimum number of operations required to transform string \(B\) into string \(A\).

Hint: The minimum number of operations is equal to the number of contiguous segments in which \(A\) and \(B\) differ, since you can flip each segment in one operation.

inputFormat

The input consists of three lines:

  1. An integer \(N\) (\(1 \leq N \leq 1000\)), representing the number of cows.
  2. A string \(A\) of length \(N\), representing Farmer John's intended breed order.
  3. A string \(B\) of length \(N\), representing the breed order of the cows as they arrived.

outputFormat

Output a single integer, the minimum number of operations required to transform string \(B\) into string \(A\) using the flipping machine.

sample

3
HHH
GGG
1