Codeforces Round #585 (Div. 2) C. Swap Letters

Monocarp has got two strings s and t

having equal length. Both strings consist of lowercase Latin letters "a" and "b".

Monocarp wants to make these two strings s

and t equal to each other. He can do the following operation any number of times: choose an index pos1 in the string s, choose an index pos2 in the string t, and swap spos1 with tpos2

.

You have to determine the minimum number of operations Monocarp has to perform to make s

and t

equal, and print any optimal sequence of operations — or say that it is impossible to make these strings equal.

Input

The first line contains one integer n

(1≤n≤2⋅105) — the length of s and t

.

The second line contains one string s

consisting of n

characters "a" and "b".

The third line contains one string t

consisting of n

characters "a" and "b".

Output

If it is impossible to make these strings equal, print −1

.

Otherwise, in the first line print k

— the minimum number of operations required to make the strings equal. In each of the next k lines print two integers — the index in the string s and the index in the string t

that should be used in the corresponding swap operation.

Examples

Input

Copy

4
abab
aabb

Output

Copy

2
3 3
3 2

Input

Copy

1
a
b

Output

Copy

-1

Input

Copy

8
babbaabb
abababaa

Output

Copy

3
2 6
1 3
7 8

Note

In the first example two operations are enough. For example, you can swap the third letter in s

with the third letter in t. Then s= "abbb", t= "aaab". Then swap the third letter in s and the second letter in t. Then both s and t

are equal to "abab".

In the second example it's impossible to make two strings equal.

题意:给你两个长度都为n的只有ab两个字母组成的字符串,你每次操作都可以把一个第一个字符串中的一个字符和第二个字符串中的一个字符交换,问最少多少次可以让两个字符串相同

思路:((a,b)指一个在上一个在下),如果是(a,b),那么和另一个(a,b)交换成一样要一次,和(b,a)交换要两次,所以所有(a,b),(b,a)都先和自己相同的交换,如果都剩下了,那剩下的交换,(a,a)(b,b)这种已经相同的不用动,如果最后发现单独的(a,b)或(b,a)被剩下了,输出-1

#include
#include
#include
using namespace std;
#define mod 1000000007
#define maxn 205000
char a[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",a+1);
    int x1=0,x2=0,y1=0,y2=0;
    for(int i=1;i<=n/2;i++)
    {
        if(a[i]=='?') x2++;
        else x1+=a[i]-'0';
    }
    for(int i=n/2+1;i<=n;i++)
    {
        if(a[i]=='?') y2++;
        else y1+=a[i]-'0';
    }
    //printf("x1=%d y1=%d x2=%d y2=%d\n",x1,y1,x2,y2);
    if(x1==y1)
    {
        if(x2==y2) printf("Bicarp\n");
        else printf("Monocarp\n");
    }
    else if((x1>y1&&x2>=y2)||(x1y1&&x2y2))
    {
        int x=abs(x1-y1),y=abs(x2-y2);
        if(x%9==0&&x/9==(y+1)/2)
        {
            printf("Bicarp\n");
        }
        else printf("Monocarp\n");
    }
}

 

你可能感兴趣的:(1000篇,思维)