Under construction

Still being built. Things may change

Lamps

Time limit1sMemory limit256 MB

Summary
Given two binary strings A and B of length N, find the fewest range set-to-0, set-to-1, or flip operations that turn A into B.
Level

Medium6 of 10

Topics
String, Greedy
Solved
No attempts yet

Problem

A long hallway has NN lamps in a row. The lamps are numbered 1 through NN from left to right. Each lamp is either off or on.

A special mechanism changes the lamp states. In one operation you can do one of the following three things.

  • Choose integers pp and qq with 1≤p≤q≤N1 \le p \le q \le N, and turn off lamps pp, p+1p+1, ⋯\cdots, qq.
  • Choose integers pp and qq with 1≤p≤q≤N1 \le p \le q \le N, and turn on lamps pp, p+1p+1, ⋯\cdots, qq.
  • Choose integers pp and qq with 1≤p≤q≤N1 \le p \le q \le N, and flip lamps pp, p+1p+1, ⋯\cdots, qq (off becomes on, on becomes off).

The initial lamp states are given as a string AA of length NN. The ii-th character (1≤i≤N1 \le i \le N) of AA is 0 if lamp ii is off and 1 if it is on. The desired states are given as a string BB of length NN, encoded the same way. You want to reach the states in BB using as few operations as possible.

Given NN, AA, and BB, print the minimum number of operations needed to reach the desired states.

Input

The first line contains NN. The second line contains AA. The third line contains BB.

Output

Print one line containing the minimum number of operations needed to reach the desired lamp states.

Constraints

  • 1≤N≤1 000 0001 \le N \le 1\ 000\ 000.
  • AA and BB are strings of length NN.
  • The characters of AA and BB are 0 or 1.

Examples3

  1. Example 1

    Input
    8
    11011100
    01101001
    
    Expected output
    4
    
  2. Example 2

    Input
    13
    1010010010100
    0000111001011
    
    Expected output
    3
    
  3. Example 3

    Input
    18
    001100010010000110
    110110001000100101
    
    Expected output
    5