C. Swap Letters

C. Swap Letters

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Monocarp has got two strings ss and tt having equal length. Both strings consist of lowercase Latin letters "a" and "b".

Monocarp wants to make these two strings ss and tt equal to each other. He can do the following operation any number of times: choose an index pos1pos1 in the string ss, choose an index pos2pos2 in the string tt, and swap spos1spos1 with tpos2tpos2.

You have to determine the minimum number of operations Monocarp has to perform to make ss and tt 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 nn (1≤n≤2⋅105)(1≤n≤2⋅105) — the length of ss and tt.

The second line contains one string ss consisting of nn characters "a" and "b".

The third line contains one string tt consisting of nn characters "a" and "b".

Output

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

Otherwise, in the first line print kk — the minimum number of operations required to make the strings equal. In each of the next kk lines print two integers — the index in the string ss and the index in the string tt 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 ss with the third letter in tt. Then s=s= "abbb", t=t= "aaab". Then swap the third letter in ss and the second letter in tt. Then both ss and tt are equal to "abab".

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

=========================================================================

首先不匹配有两种情况

a b

b a

如果两种情况都是偶数,那么一定能够置换成功,且只需要对单个情况每两个进行两两组合即可

如果两个都是奇数,那么两个各剩下一个,单独耗费两次(参考样例1)

如果一奇一偶,那么显然是不可以的

# include <stdio.h>
#include<iostream>
# include<cstring>
# include<vector>
# include<queue>
# include<algorithm>
using namespace std;
typedef long long int ll;

vector<int>v1,v2;

int main()
{


    int n;

    cin>>n;

    string a,b;
    cin>>a>>b;

    for(int i=0; i<n; i++)
    {
        if(a[i]=='a'&&b[i]=='b')
            v1.push_back(i+1);
        else if(a[i]=='b'&&b[i]=='a')
            v2.push_back(i+1);
    }

    if((v1.size()+v2.size())%2)
    {
        cout<<-1;
    }
    else
    {

        if(v1.size()%2==0&&v2.size()%2==0)
        {


            cout<<(v1.size()+v2.size())/2<<endl;

            if(v1.size())
            {
                for(int i=0; i<v1.size(); i+=2)
                {
                    cout<<v1[i]<<" "<<v1[i+1]<<endl;
                }


            }


            if(v2.size())
            {
                for(int i=0; i<v2.size(); i+=2)
                {
                    cout<<v2[i]<<" "<<v2[i+1]<<endl;
                }


            }
        }
        else if(v1.size()%2&&v2.size()%2)
        {


            cout<<(v1.size()+v2.size()-2)/2+2<<endl;

            if(v1.size())
            {
                for(int i=0; i+1<v1.size(); i+=2)
                {
                    cout<<v1[i]<<" "<<v1[i+1]<<endl;
                }


            }


            if(v2.size())
            {
                for(int i=0; i+1<v2.size(); i+=2)
                {
                    cout<<v2[i]<<" "<<v2[i+1]<<endl;
                }


            }

            cout<<v1[v1.size()-1]<<" "<<v1[v1.size()-1]<<endl;

            cout<<v1[v1.size()-1]<<" "<<v2[v2.size()-1]<<endl;

        }
    }

    return  0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值