F - Two Strings Swaps CodeForces - 1006D

You are given two strings aa and bb 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 ii (1≤i≤n1≤i≤n) and swap characters aiai and bibi;
  • Choose any index ii (1≤i≤n1≤i≤n) and swap characters aiai and an−i+1;
  • Choose any index ii (1≤i≤n1≤i≤n) and swap characters bibi and bn−i+1bn−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).

题目大意:就是两个字符串通过各种操作来使两个字符串相同,

1 将a [i]和b[i]互换

2 将 a[i] 和 a[n-i+1]互换

3 将 b[i] 和 b[n-i+1]互换

在这之前你可以经行预处理既将某个字符替换掉,之后只能用这三种操作,问最少的预处理次数

思路就是分裂类处理,如过能在相应的位置能经行三操作就不需要与预处理,其他的看要替换几个就可以,如果是奇数的话还要看一下中间的数是否相等,不相等的话就加一。

代码如下:

#include <stdio.h>
#include <string.h>
#include<algorithm>
using namespace std;
char  a[120000],b[120000];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        getchar();
        scanf("%s",a);
        scanf("%s",b);
        int sum = 0;
        for(int i=0; i<n/2; i++)
        {
            int l = i, r = n - i - 1;
            if((a[l] == b[l] && a[r] == b[r]) || (a[l] == b[r] && a[r] == b[l]) || (a[l] == a[r] && b[l] == b[r])) //能通过移动相等,不需要加
                continue;
            else if(a[l] == b[l] || a[r] == b[r] || a[l] == b[r] || a[r] == b[l] || b[l] == b[r])   //替换一个就可以相等
                sum++;
            else
                sum += 2;
        }
        int m=n/2;
        if(n % 2 == 1 && a[m] != b[m])
            sum++;
        printf("%d\n",sum);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/TANG3223/article/details/81367777
今日推荐