#include using namespace std; bool DIR = true; struct EulerWalk { int n; vector>> graph; vector cap, walk, buf, deg; EulerWalk(int n): n(n), graph(n + 1), deg(n + 1) {} int AddEdge(int a, int b, int c = 1) { int ret = cap.size(); graph[b].emplace_back(a, ret); if(!DIR) graph[a].emplace_back(b, ret); cap.push_back(c); deg[a] += c; deg[b] -= c; if(!DIR) deg[a] %= 2, deg[b] %= 2; return ret; } void dfs(int node) { while(graph[node].size()) { auto [vec, ei] = graph[node].back(); if(!cap[ei]) graph[node].pop_back(); else --cap[ei], dfs(vec); } walk.push_back(node); } template void Go(CB&& cb) { for(int i = 0; i <= n; ++i) { if(deg[i] < 0) AddEdge(i, n, -deg[i]); if(deg[i] > 0) AddEdge(n, i, +deg[i]); assert(deg[i] == 0); } for(int i = n; i >= 0; --i) { dfs(i), walk.push_back(n); } for(int i = 0, j = 0; i < (int)walk.size(); i = j + 1) { for(j = i; walk[j] < n; ++j); if(j - i > 1) cb(walk.begin() + i, walk.begin() + j); } } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string arrive, depart; cin >> depart; cin >> arrive; vector>> graph(3); unordered_map char_to_pos; char_to_pos['M'] = 0; char_to_pos['C'] = 1; char_to_pos['-'] = 2; EulerWalk ew(3); vector> ids(9); for(int i = 0; i < n; i++) { if(arrive[i] == depart[i])continue; ew.AddEdge(char_to_pos[arrive[i]], char_to_pos[depart[i]]); ids[char_to_pos[arrive[i]] * 3 + char_to_pos[depart[i]]].push_back(i); } int count = 0; ostringstream answer; ew.Go([&] (vector::iterator begin, vector::iterator end) { vector walk; for(auto it = begin, nit = next(it); nit != end; it++, nit++) { walk.push_back(ids[*it * 3 + *nit].back()); ids[*it * 3 + *nit].pop_back(); } reverse(walk.begin(), walk.end()); for(int i = 0; i < (int)walk.size(); i++) { count += 1; answer << "DRIVE " << walk[i] + 1 << "\n"; if(depart[walk[i]] != '-') { count += 1; answer << "DROPOFF\n"; } if(arrive[walk[i]] != '-') { count += 1; answer << "PICKUP\n"; } } }); cout << count << "\n"; cout << answer.str(); return 0; }