#include using namespace std; using ll = long long; const ll INF = 1e18; template using graph = vector>; int n; const int N = 3000; int used[N]; int cnt[N]; graph g(N); int cur = 0; string s; string t; vector> ans; vectorres; void dfs(int v) { auto x = g[v]; for (int to: x) { if(g[v].find(to)!=g[v].end()) { g[v].erase(g[v].find(to)); dfs(to); } } res.push_back(v); } int cnt1[N]; void solve(string s, string t) { n = s.size(); // cin >> n; // cin >> s >> t; string init = t; map mp; // for (int i = 0; i < n; i++) { // if (s[i] == t[i]) continue; // mp[s[i]]++; // mp[t[i]]--; // } for (int i = 0; i < n; i++) { if (s[i] == t[i]) continue; if (s[i] == '-') g[0].insert(i + 3); if (s[i] == 'C') g[1].insert(i + 3); if (s[i] == 'M') g[2].insert(i + 3); if (t[i] == '-') g[i + 3].insert(0); if (t[i] == 'C') g[i + 3].insert(1); if (t[i] == 'M') g[i + 3].insert(2); } for (int i = 0; i < n + 3; i++) { for (auto to : g[i]) cnt1[to]++; } for (int i = 1; i < n + 3; i++) { int x = cnt1[i] - g[i].size(); for (int j = 0; j < x; j++) { g[i].insert(0); } } cnt[0] = g[0].size(); cnt[1] = g[1].size(); cnt[2] = g[2].size(); dfs(0); reverse(res.begin(), res.end()); // for (auto i : res) // cout << i << " "; // while (res.back() != 0) // { // res.pop_back(); // } // cout << endl; // for (auto i : res) // cout << i << " "; int cur = 0; string R = t; char last = 0; bool has_z = 0; for (auto i : res) { if (i <= 2) continue; // if (i == 0) // has_z = 1; // if (!has_z) continue; ans.push_back({"DRIVE", i - 2}); if (cur) { ans.push_back({"DROPOFF", -1}); cur--; } if (t[i - 3] != '-') { ans.push_back({"PICKUP", -1}); last = init[i - 3]; init[i - 3] = '-'; cur++; } } // cout<<"------------------"< order; int n = s.size(); for (int i = 0; i < n; i++) { order.push_back(i); } do { bool good = 1; char cur = 0; for (auto i : order) { if (s[i] == t[i]) continue; if (s[i] != cur) { good = 0; break; } cur = t[i]; } if (good) return 1; } while(next_permutation(order.begin(), order.end())); return false; } pair test(int n) { string s(n, '-'); string t(n, '-'); for (int i = 0; i < n; i++) { int r = rand() % 3; if (r == 0) continue; if (r == 1) s[i] = 'C'; else s[i] = 'M'; } for (int i = 0; i < n; i++) { int r = rand() % 3; if (r == 0) continue; if (r == 1) t[i] = 'C'; else t[i] = 'M'; } return {s, t}; } int32_t main() { int t = 1; // cin >> t; while (t--) { int n; string s, t; cin >> n >> s >> t; solve(s, t); } }