2020 BIT冬训-模拟与暴力 B - Two Strings Swaps CodeForces - 1006D

Problem Description

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 1 to n, inclusive.

You are allowed to do the following changes:

  • Choose any index i (1in) and swap characters ai and bi;
  • Choose any index i (1in) and swap characters ai and ani+1;
  • Choose any index i (1in) and swap characters bi and bni+1.

Note that if nn is odd, you are formally allowed to swap an2 with an2 (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 (1in), 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 nn (1≤n≤105) — the length of strings aa and bb.

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
7
abacaba
bacabaa
Output
4
Input
5
zcabd
dbacz
Output
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)swap(a2,b2) and swap(a2,a6)swap(a2,a6).

There is no way to use fewer than preprocess moves before a sequence of changes to make string equal, so the answer in this example is 4.

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).

 

只需要判断a[i],b[i],a[n-1-i],b[n-1-i]之间的相互关系即可。需要注意的是只有a能进行替换。所以aabc需要2次而bcaa只需要一次。

以及不要忘记如果字母数是奇数还需要对中间那个进行一次判断。

#include<stdio.h>
using namespace std;
int n,t1,t2,t3,t4,t5,t6,cnt;
char a[100005],b[100005]; 
int main(){
    scanf("%d",&n);
    scanf("%s%s",a,b);
    for(int i=0;i<n/2;i++){
        t1 = a[i]==b[i];
        t2 = a[i]==a[n-1-i];
        t3 = a[i]==b[n-1-i];
        t4 = b[i]==a[n-1-i];
        t5 = b[i]==b[n-1-i];
        t6 = a[n-1-i]==b[n-1-i];
        if(t1+t2+t3+t4+t5+t6==6)//四个一样 aaaa 
            continue;
        else if(t1+t2+t3+t4+t5+t6==3)//三个一样 aaab。改一次a 
            cnt++;
        else if(t1+t2+t3+t4+t5+t6==2)//两两相同 aabb 
            continue;
        else if(t1+t2+t3+t4+t5+t6==1){//两个一样,另两个不同 
            if(t2)//aabc。改两次a 
                cnt+=2;
            else//abac。改一次a 
                cnt++;
        }else if(t1+t2+t3+t4+t5+t6==0)//全都不一样abcd(修改成两两相同) 
            cnt+=2; 
    }
    if(n&1)
        if(a[n/2]!=b[n/2])
            cnt++;
    printf("%d",cnt); 
}

 

posted @ 2021-02-04 19:28  mikku  阅读(58)  评论(0)    收藏  举报