Two Strings Swaps

You are given two strings aa and bb consisting of lowercase English letters, both of length n. The characters of both strings have indices from 1 to n, 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⌉a⌈n2⌉ with a⌈n2⌉a⌈n2⌉ (and the same with the string bb) 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≤n1≤i≤n), any character cc and set ai:=cai:=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 bb or make any preprocess moves after the first change is made.

Input

The first line of the input contains one integer nn (1≤n≤1051≤n≤105) — the length of strings aa and bb.

The second line contains the string aa consisting of exactly nn lowercase English letters.

The third line contains the string bb consisting of exactly nn 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 aa equal to string bb with a sequence of changes from the list above.

Examples

Input

7
abacaba
bacabaa

Output

4

Input

5
zcabd
dbacz

Output

0

Note

In the first example preprocess moves are as follows: a1:=a1:='b', a3:=a3:='c', a4:=a4:='a' and a5:=a5:='b'. Afterwards, a=a="bbcabba". Then we can obtain equal strings by the following sequence of changes: swap(a2,b2)swap(a2,b2) and swap(a2,a6)swap(a2,a6). 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 aa and bb equal: swap(b1,b5)swap(b1,b5), swap(a2,a4)swap(a2,a4).

emmm... 我打的第一场cf上的原题,结果昨天我根本就没看这道题....

题意:有两个字符串a,b,可以进行   a[i]和a[n-i-1]交换  或  b[i]和b[n-i-1]交换  或a[i]和b[i]交换。求刚开始最少对 a进行修改多少个字符才能使两个字符串可以通过上述三种交换方式得到两个相同的字符串。

三种交换方式:

思路:根据三种交换方式我们可以知道,这四个字符是可以在这四个位置任意交换的。那么最少的预处理次数就是要看每对(四个字符)里面的字符匹配情况了。

情况一:四个字符都相等,那么就不需要进行操作就可以达到目标状态(a,b字符串上下位置对应相等)。

情况二:四个字符中有两种字符。

             1.如果是(2,2)的话,是可以通过交换转换达到目的状态的;

             2.如果是(1,3)的话,肯定需要改变任意一个字符,达到(2,2)或者是 情况一;

情况三:四个字符中有三种字符。

             1.如果是a[i]==a[n-i-1],那么就可以推出 b[i]!=b[n-i-1]!=(a[i]==a[n-i-1]),又因为只能改变a,那么是必须要改变a中的两个字                 符的(先改变,后交换)。

             2.反之,只需要改变一个即可。

情况四:四个字符又四种字符。因此改变任意两个即可。

情况五:整个字符串的长度是奇数,那么中间就肯定剩下两个字符没有处理,如果这两个字符不相等,就必须改变一个了。

代码如下:

#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
char s[100010],t[100010];
int main()
{
    int n,i,j;
    scanf("%d",&n);
    scanf("%s%s",s,t);
    int ans=0;
    for(i=0; i<n/2; i++)
    {
        map<char,int>v;  //判断有几种字符,并记录各自个数
        v[s[i]]++;
        v[t[i]]++;
        v[s[n-i-1]]++;
        v[t[n-i-1]]++;
        if(v.size()>=2)
        {
            if(v.size()==2) //有两种字符
            {
                if(v[s[i]]!=2)  //(1,3)情况
                    ans++;
            }
            else if(v.size()==3)  //有三种字符
            {
                if(s[i]==s[n-i-1])  // 因为是先改变再交换,且只能改变s字符串,所以这种情况下要改变两个
                    ans+=2;
                else                //反之,改变一个
                    ans++;
            }
            else          //有四种字符
                ans+=2;
        }
    }
    if(n%2)  //奇数
        if(s[n/2]!=t[n/2])//判断中间的两个字符是否相等
            ans++;
    printf("%d\n",ans);
}

猜你喜欢

转载自blog.csdn.net/qq_41890797/article/details/81364365