Two Strings Swaps

                                                     Two Strings Swaps

原题链接 http://codeforces.com/problemset/problem/1006/D

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

You are allowed to do the following changes:

  • Choose any index i (1≤i≤n) and swap characters ai and bi;
  • Choose any index i (1≤i≤n) and swap characters ai and an−i+1;
  • Choose any index i (1≤i≤n) and swap characters bi and bn−i+1.

Note that if nn is odd, you are formally allowed to swap a⌈n2⌉ with a⌈n2⌉ (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 aa with another character. In other words, in a single preprocess move you can choose any index ii (1≤i≤n), any character cc 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 aa and bb 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 (1≤n≤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:='b', a3:='c', a4:='a' and a5:='b'. Afterwards, a="bbcabba". Then we can obtain equal strings by the following sequence of changes: swap(a2,b2) and swap(a2,a6)。 There is no way to use fewer than 44preprocess 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 aa and bb equal: swap(b1,b5), swap(a2,a4).

 利用map容器记录当前位置的字符种类,枚举每一种情况即可。

以下是AC代码

#include
#include
#include
#include
using namespace std;

char a[100010],t[100010];

int main()
{
    int n,sum=0;
    scanf("%d",&n);
    scanf("%s%s",a,t);
    for(int i=0; imapp;
        mapp[a[i]]++;
        mapp[t[i]]++;
        mapp[a[n-i-1]]++;
        mapp[t[n-i-1]]++;
        if(mapp.size()>=2)
        {
            if(mapp.size()==2)
            {
                if(mapp[a[i]]!=2)
                {
                    sum++;
                }
            }
            else if(mapp.size()==3)
            {
                if(a[i]==a[n-i-1])
                {
                    sum+=2;
                }
                else
                {
                    sum++;
                }
            }
            else
            {
                sum+=2;
            }
        }
    }
    if(n%2)
    {
        if(a[n/2]!=t[n/2])
        {
            sum++;
        }
    }
    printf("%d\n",sum);
    return 0;
}

 

你可能感兴趣的:(Two Strings Swaps)