Kevin and the Remote Car
InterviewTime limit2sMemory limit1024 MB
Given two digit strings, decide whether the first can be reduced to the second by repeatedly replacing adjacent digits with their sum modulo 10.
Problem
Mrs. Hess gave Kevin a remote-controlled car as a thank-you for helping shovel snow. She had picked it up by mistake at the airport.
After playing with it for a while, Kevin wanted to see what was inside. Taking it apart turned out to be harder than he expected. Inside were a tricky electronic lock and two strings of digits. The instructions said he had to solve a difficult puzzle to open the case. The lock lets him choose any two adjacent digits in the first string and replace them with a single digit equal to the remainder of their sum divided by ten. If the first string ends up exactly equal to the second string, the lock opens. Each operation shortens the first number, and there is no way to undo a step, so Kevin gets only one attempt.
Help Kevin figure out whether the lock can be opened, at least in theory.
Input
The first line contains a string (), the first number. The second line contains a string (), the second number. Both strings may contain leading zeros.
Output
Print YES if the first number can be turned into the second, and NO otherwise.