#include using namespace std; #define rep(i,a,b) for(int i=a;i<(b);++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair pii; typedef vector vi; #define pb push_back #define ff first #define ss second void drive(ll i){ cout<<"DRIVE "<> &gr, int nedges, int src){ int n=sz(gr); vi D(n), its(n), eu(nedges), ret, s={src}; D[src]++; while(!s.empty()){ int x=s.back(),y , e, &it =its[x], end=sz(gr[x]); if(it==end) {ret.pb(x); s.pop_back(); continue;} tie(y, e)=gr[x][it++]; if(!eu[e]){ D[x]--; D[y]++; eu[e]=1; s.pb(y); } } for(int x: D) if(x<0 || sz(ret) !=nedges+1) return {}; return {ret.rbegin(), ret.rend()}; } void solve(){ ll n; cin>>n; string a, b; cin>>a>>b; map, vector> mapi; rep(i,0,n){ mapi[{a[i], b[i]}].pb(i); } ll m0=0, m1=0, c0=0, c1=0; /* for(char u: a){ if(u=='M') m0++; if(u=='C') c0++; } for(char u: b){ if(u=='M') m1++; if(u=='C') c1++; }*/ ll gm=0; ll gc=0; rep(i,0,n){ if(a[i]=='M' && b[i]=='C') gm++; if(a[i]=='C' && b[i]=='M') gc++; } if(gm==0 && gc==0){ cout<<0<<'\n'; return; } vector adj(3, vector()); ll cc=0; for(ll u: mapi[{'M', 'C'}]){adj[stoi('M')].pb({stoi('C'), cc}); cc++;} for(ll u: mapi[{'C', 'M'}]){adj[stoi('C')].pb({stoi('M'), cc}); cc++;} map, vector> mapi2=mapi; rep(i, 0, gm-gc){ adj[stoi('-')].pb({stoi('M'), cc}); adj[stoi('C')].pb({stoi('-'), cc+1}); cc+=2; } rep(i, 0, gc-gm){ adj[stoi('-')].pb({stoi('C'), cc}); adj[stoi('M')].pb({stoi('-'), cc+1}); cc+=2; } /* rep(i, 0, 3){ cout<> ans; /* for(ll u: h) cout<0); rep(i, 0, hh-1){ if(mapi[{itos(h[i]), itos(h[i+1])}].empty()) continue; ll u=mapi[{itos(h[i]), itos(h[i+1])}].back(); mapi[{itos(h[i]), itos(h[i+1])}].pop_back(); if(ff==0){ ans.pb({'d', u+1}); }else{ ans.pb({'p', u+1}); ans.pb({'d', u+1}); ans.pb({'m', u+1}); } ff=1; } cout<