#include using namespace std; using ll = long long; using ld = long double; int main(){ int n; cin>>n; string prof; string budova; cin>>budova; cin>>prof; char current = '-'; vector> instructions; vector beginC; vector beginM; vector endC; vector endM; vector swapCforM; vector swapMforC; for(int i=0;i0 && (!swapMforC.empty() || !endC.empty())){ current='C'; instructions.push_back(pair('d',*beginC.rbegin())); instructions.push_back(pair('p',0)); beginC.pop_back(); continue; } if (beginM.size()>0 && (!swapCforM.empty() || !endM.empty())){ current='M'; instructions.push_back(pair('d',*beginM.rbegin())); instructions.push_back(pair('p',0)); beginM.pop_back(); continue; } } if (current == 'C') { if (swapMforC.size()>0){ current='-'; instructions.push_back(pair('d',*swapMforC.rbegin())); instructions.push_back(pair('o',0)); if ((!swapCforM.empty() || !endM.empty())) { instructions.push_back(pair('p',0)); current='M'; } swapMforC.pop_back(); continue; } if (endC.size()>0){ current='-'; instructions.push_back(pair('d',*endC.rbegin())); instructions.push_back(pair('o',0)); endC.pop_back(); continue; } } if (current == 'M') { if (swapCforM.size()>0){ current='-'; instructions.push_back(pair('d',*swapCforM.rbegin())); instructions.push_back(pair('o',0)); if ((!swapMforC.empty() || !endC.empty())) { instructions.push_back(pair('p',0)); current='C'; } swapCforM.pop_back(); continue; } if (endM.size()>0){ current='-'; instructions.push_back(pair('d',*endM.rbegin())); instructions.push_back(pair('o',0)); endM.pop_back(); continue; } } break; } cout<