CF BUDDY
← Problems·

1949G · Scooter

2300 · graphs, greedy

Problem: The Czech Technical University campus consists of nn buildings, indexed from 11 to nn. In each building, there can be a math class scheduled, or a computer science class, or neither (but not both). Additionally, in each building, there is at most one professor, and each professor is either an expert in mathematics or in computer science.

As an intern at University Express Inc., your job is to quickly transport the professors to their classes. For this, you have been granted a brand new two-person scooter, able to accommodate yourself, plus at most one passenger.

Initially, you are the only person on the scooter. When you arrive at a building, you may drop off or pick up professors to/from that building. However, in order to improve the efficiency of your task, you are allowed to drive to each of the nn buildings at most once, in the order of your choice (you can also decide where to start the itinerary).

After the end of your itinerary, in each building where a math class is scheduled, there must be a professor expert in math, and in each building where a computer science class is scheduled, there must be a professor expert in computer science.

Devise an itinerary that makes it possible to teach all classes.

Input Format: The first line contains an integer nn (1n20001\le n \le 2000) — the number of buildings in the campus.

The second line contains a string of cc of length nn consisting of the characters -\texttt{-}, C\texttt{C}, M\texttt{M} — the ii-th character denotes the subject of the class scheduled in the ii-th building. C\texttt{C} stands for computer science, M\texttt{M} stands for mathematics, while -\texttt{-} means that there is no class scheduled in the ii-th building.

The third line contains a string pp of length nn consisting of the characters -\texttt{-}, C\texttt{C}, M\texttt{M} — the ii-th character denotes the expertise of the professor in the ii-th building (if there is a professor). C\texttt{C} stands for computer science, M\texttt{M} stands for mathematics, while -\texttt{-} means that there is no professor in the ii-th building.

It is guaranteed that, for all tests given to your program, there exists a valid itinerary.

Output Format: In the first line print an integer ll — the number of operations in your chosen itinerary.

The ii-th (1il1 \leq i \leq l) of the next ll lines must contain one of three commands:

  1. DRIVE x\texttt{DRIVE } x — go to the building with the number xx (1xn1 \leq x \leq n);
  2. PICKUP\texttt{PICKUP} — pick up the professor which was initially at the current building;
  3. DROPOFF\texttt{DROPOFF} — drop off the passenger professor at the current building.

In order for the itinerary to be valid, the following conditions must hold:

  1. No two DRIVE\texttt{DRIVE} instructions should go to the same building;
  2. At most one DROPOFF\texttt{DROPOFF} and one PICKUP\texttt{PICKUP} instruction in this order should be issued at each specific building;
  3. For all PICKUP\texttt{PICKUP} instructions, there must be a professor initially at the building, as well as no one already riding along on the scooter;
  4. For all DROPOFF\texttt{DROPOFF} instructions, there must be a professor riding along at the time of the command;
  5. After the itinerary, in each building, if there is a class in that building, there must be a professor expert in the class' subject (either initially, or because they were dropped off there).

Note that, in particular, you cannot pick up a professor that you just dropped off for an itinerary to be valid.

Note: In the first sample, You start by driving to building number 33. You then pick up the mathematics professor. After dropping him off at building number 22, where a mathematics class is being held, you pick up the computer science professor from there, and drop her off at building number 11, finishing your itinerary.

Sample Cases

Case 1

Input

3
CM-
-CM

Output

7
DRIVE 3
PICKUP
DRIVE 2
DROPOFF
PICKUP
DRIVE 1
DROPOFF

Case 2

Input

1
C
C

Output

0

Case 3

Input

2
-M
MC

Output

4
DRIVE 1
PICKUP
DRIVE 2
DROPOFF

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback