Algorithm


D. Two Strings Swaps
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two strings a and b consisting of lowercase English letters, both of length n. The characters of both strings have indices from 11 to n, inclusive.

You are allowed to do the following changes:

  • Choose any index i (1in1≤�≤�) and swap characters ai�� and bi��;
  • Choose any index i (1in1≤�≤�) and swap characters ai�� and ani+1��−�+1;
  • Choose any index i (1in1≤�≤�) and swap characters bi�� and bni+1��−�+1.

Note that if n is odd, you are formally allowed to swap an2�⌈�2⌉ with an2�⌈�2⌉ (and the same with the string b) but this move is useless. Also you can swap two equal characters but this operation is useless as well.

You have to make these strings equal by applying any number of changes described above, in any order. But it is obvious that it may be impossible to make two strings equal by these swaps.

In one preprocess move you can replace a character in a with another character. In other words, in a single preprocess move you can choose any index i (1in1≤�≤�), any character c and set ai:=c��:=�.

Your task is to find the minimum number of preprocess moves to apply in such a way that after them you can make strings a and b equal by applying some number of changes described in the list above.

Note that the number of changes you make after the preprocess moves does not matter. Also note that you cannot apply preprocess moves to the string b or make any preprocess moves after the first change is made.

Input

The first line of the input contains one integer n (1n1051≤�≤105) — the length of strings a and b.

The second line contains the string a consisting of exactly n lowercase English letters.

The third line contains the string b consisting of exactly n lowercase English letters.

Output

Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string a equal to string b with a sequence of changes from the list above.

Examples
input
Copy
7
abacaba
bacabaa
output
Copy
4
input
Copy
5
zcabd
dbacz
output
Copy
0
Note

In the first example preprocess moves are as follows: a1:=�1:='b', a3:=�3:='c', a4:=�4:='a' and a5:=�5:='b'. Afterwards, a=�="bbcabba". Then we can obtain equal strings by the following sequence of changesswap(a2,b2)����(�2,�2) and swap(a2,a6)����(�2,�6). There is no way to use fewer than 44 preprocess moves before a sequence of changes to make string equal, so the answer in this example is 44.

In the second example no preprocess moves are required. We can use the following sequence of changes to make a and b equal: swap(b1,b5)����(�1,�5)swap(a2,a4)����(�2,�4).

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int const N = 1e5 + 10;
char a[N], b[N];
int n;

int main() {
  scanf("%d", &n);
  scanf("%s", a + 1);
  scanf("%s", b + 1);

  int res = 0;
  for(int i = 1, j = n; i <= j; ++i, --j) {
    if(i == j) {
      if(a[i] != b[i])
        ++res;
      continue;
    }

    if(a[i] == b[j] && b[i] == a[j])
      continue;
    if(a[i] == a[j] && b[i] == b[j])
      continue;
    if(a[i] == b[i] && a[j] == b[j])
      continue;

    if(a[i] != a[j] && a[i] != b[i] && a[i] != b[j] && a[j] != b[i] && a[j] != b[j] && b[i] != b[j]) {
      res += 2;
      continue;
    }
    
    if(a[i] != a[j] && b[i] == b[j] && a[i] != b[i] && a[j] != b[i]) {
      res += 1;
      continue;
    }

    if(a[i] == a[j] && b[i] != b[j] && a[i] != b[i] && a[i] != b[j]) {
      res += 2;
      continue;
    }

    ++res;
  }

  printf("%d\n", res);

  return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
7
abacaba
bacabaa

Output

x
+
cmd
4
Advertisements

Demonstration


Codeforces Solution-D. Two Strings Swaps-Solution in C, C++, Java, Python,Two Strings Swaps,Codeforces Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+