The Cat of Bitland
Time limit1sMemory limit1024 MB
Two rows of K (friendly) and A (allergic) students; the cat moves right in a row or jumps to any later room in the other row, and we want the most rooms it can visit.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Array, Greedy, Implementation
- Solved
- No attempts yet
Problem

In Bitland there lives a Cat who loves cheering people up by paying them a visit.
When spring came, the Cat grew worried about the students of Bitland University, who were studying hard for their exams. Every student at this university is either not allergic to cats — and happily pets them — or allergic to them. Naturally, the Cat will not visit an allergic student.
The students live in two long dormitories that face each other across a street. Both dormitories are single-story and each has identical rooms. The rooms of a dormitory are lined up one after another from left to right.
The Cat visits the students from left to right in the following way:
- First, the Cat appears out of nowhere at the door of any room in either dormitory.
- After meeting the student of a room, the Cat may either move to the immediately adjacent room on the right in the same dormitory (provided that room holds no allergic student), or cross the street to any room of the other dormitory that lies farther to the right and holds no allergic student.
- While visiting students the Cat may cross the street any number of times.
- The Cat keeps visiting students this way for as long as it can.
- Then the Cat uses its magical powers and simply vanishes in its own cat-like fashion.
Determine the greatest number of students the Cat can cheer up.
Input
The first line contains , the number of rooms in each dormitory. Each of the next two lines describes one dormitory with characters; the -th character tells whether the student living in room of that dormitory is allergic:
K— the student is not allergic to cats;A— the student is allergic to cats.
Output
Output a single integer — the maximum number of rooms the Cat can visit.