This page is still under construction.

Parts of this page are still being built. What you see may change.

The Cat of Bitland

Time limit1sMemory limit1024 MB

Summary
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 NN 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 NN, the number of rooms in each dormitory. Each of the next two lines describes one dormitory with NN characters; the ii-th character tells whether the student living in room ii 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.

Constraints

  • 1≤N≤1,000,0001 \le N \le 1{,}000{,}000

Examples2

  1. Example 1

    Input
    6
    KAKKAA
    AAAAKK
    
    Expected output
    4
    
  2. Example 2

    Input
    6
    KKAKKA
    KAAAAK
    
    Expected output
    4