Input
Copy
10
codeforces
dodivthree
Output
Copy
5
7 8
4 9
2 2
9 10
3 1
Input
Copy
7
abaca?b
zabbbcc
Output
Copy
5
6 5
2 3
4 6
7 4
1 2
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <memory.h>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
vector<int> l[26],r[26],ql,qr;
int n;
char dl[200100],dr[200100];
struct p{
int il,ir;
}tm;
p gen(int il,int ir){
p t;
t.il=il;
t.ir=ir;
return t;
}
queue<p>q;
int main(){
scanf("%d",&n);
scanf("%s%s",dl,dr);
for(int i=0;i<n;i++){
if(dl[i]=='?')ql.push_back(i);
else l[dl[i]-'a'].push_back(i);
if(dr[i]=='?')qr.push_back(i);
else r[dr[i]-'a'].push_back(i);
}
for(int i=0;i<26;i++){
while((!l[i].empty())&&(!r[i].empty())){
q.push(gen(l[i].back(),r[i].back()));
l[i].pop_back();
r[i].pop_back();
}
while((!l[i].empty())&&(!qr.empty())){
q.push(gen(l[i].back(),qr.back()));
l[i].pop_back();
qr.pop_back();
}
while((!r[i].empty())&&(!ql.empty())){
q.push(gen(ql.back(),r[i].back()));
r[i].pop_back();
ql.pop_back();
}
}
while((!ql.empty())&&(!qr.empty())){
q.push(gen(ql.back(),qr.back()));
ql.pop_back();
qr.pop_back();
}
printf("%d\n",q.size());
while(!q.empty()){
tm=q.front();
printf("%d %d\n",tm.il+1,tm.ir+1);
q.pop();
}
}