#P9950. [USACO20FEB] Mad Scientist B

[USACO20FEB] Mad Scientist B

Problem Description

Farmer John's distant relative Ben is a mad scientist. This usually causes a lot of friction at family gatherings, but it can sometimes be helpful, especially when Farmer John finds himself facing a unique and unusual problem involving his cows.

Farmer John is currently facing a unique and unusual problem involving his cows. He recently ordered NN cows (1N10001 \le N \le 1000) consisting of two different breeds: Holsteins and Guernseys. In his order, he specified the cows using a string of length NN, where each character is either H (meaning Holstein) or G (meaning Guernsey). Unfortunately, when the cows arrived at his farm and he lined them up, the resulting string of breeds was different from what he originally ordered.

We call these two strings AA and BB, where AA is the breed string Farmer John originally wanted, and BB is the breed string of the cows as they arrived. Farmer John did not simply check whether reordering the cows in BB could produce AA; instead, he asked his distant relative Ben to use his scientific talent to solve this problem.

After months of research, Ben invented an unusual machine: the Cow Breed Flipper 3000. It can choose any substring of cows and flip their breeds: every H in the substring becomes G, and every G becomes H. Farmer John wants to find the minimum number of times this machine must be used to transform his current sequence BB into the desired sequence AA. However, Ben's mad scientist skills do not handle anything other than building strange machines, so you need to help Farmer John solve this computational problem.

Input Format

The first line of input contains NN. The next two lines contain strings AA and BB. Each string contains NN characters, each of which is either H or G.

Output Format

Output the minimum number of uses of the machine needed to transform BB into AA.

7
GHHHGHH
HHGGGHH
2

Hint

Sample Explanation 1

First, FJ can flip the substring consisting of only the first character, turning BB into GHGGGHH. Then, he can flip the substring consisting of the third and fourth characters to obtain AA. Of course, there are other valid ways to perform two operations.

Translated by ChatGPT 5