eolymp
bolt
Try our new interface for solving problems
Problems

Correcting Curiosity

Correcting Curiosity

Curiosity is the rover that explores the Gale Crater on Mars. Recently it found an evidence of water in Martian soil, which will make it easier to plan the future manned missions. Curiosity can communicate with Earth directly at speeds up to \textbf{32} Kbit/s, but on average \textbf{14} minutes and \textbf{6} seconds will be required for signals to travel between Earth and Mars. "You have just seen a stone and applied brakes, but you know that the rover is already passing that stone" --- Matt Heverly, the rover’s driver, explains. "So we just plan the route, then write down a list of simple textual commands: move one meter ahead, turn left, make a photo and so on". Sometimes it is necessary to react very fast to some unexpected events. For example, if the cameras have seen something interesting, then you might want to change the route of the rover to make an additional photo. To do that, you send a substitution command of the form \textbf{s///g}. This replaces all occurrences of , starting with the leftmost one, to . More formally, if \textbf{A} is a non-empty string and \textbf{B} is a string, then to apply the substitution command \textbf{s/A/B/g} to a string \textbf{S}, you should do the following: \begin{enumerate} \item Find the leftmost occurrence of \textbf{A} in \textbf{S}, such that \textbf{S = SL + A + SR}. \item If there is no such occurrence, stop. Then, \textbf{S} is the answer. \item Let \textbf{R} be the result of applying \textbf{s/A/B/g} to \textbf{SR}. \item The answer is \textbf{SL + B + R}. \end{enumerate} This means that: \begin{enumerate} \item If there are two overlapping occurrences of \textbf{A} in \textbf{S}, only the leftmost one is replaced. For example, applying "\textbf{s/aba/c/g}" to "\textbf{abababa}" yields "\textbf{cbc}": after replacing the first occurrence of "\textbf{aba}" the string turns to "\textbf{cbaba}", and only the last occurrence of "\textbf{aba}" can be replaced after that. \item No substitution uses the results of previous substitutions. For example, applying "\textbf{s/a/ab/g}" to "\textbf{a}" yields "\textbf{ab}", applying "\textbf{s/a/ba/g}" to "\textbf{a}" yields "\textbf{ba}". \end{enumerate} You know that the longer is the command, the bigger is the time necessary to transmit it. So, you have to write a program that finds shortest command that transforms the initial string to the final string. \InputFile The first line contains the initial and the final strings. Both strings are non-empty and their lengths do not exceed \textbf{2000} characters. The strings contain only English letters, spaces and punctuation signs (commas, colons, semicolons and hyphens: '\textbf{,}', '\textbf{:}', '\textbf{;}', '\textbf{-}'). The given strings are not equal. \OutputFile Output the substitution command that transforms initial string to final string and has the minimum length. If there are several shortest substitution commands, output any of them.
Time limit 2 seconds
Memory limit 256 MiB
Input example #1
move left, move right; move up
move left, move down, move up
Output example #1
s/right;/down,/g
Source ACM ICPC 2013–2014, NEERC, Northern Subregional Contest, St Petersburg, October 26, 2013