Closeness
Time limit1sMemory limit1024 MB
Decide whether two strings can be made equal by cyclically shifting adjacent letter pairs, after each of Q single-letter updates to one string.
- Level
Medium5 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
One spring, on an unusually warm evening, two men appeared at the Patriarch's Ponds in M*skva. The first was the editor Mihail Aleksandrovič Berlioz. The second was a young poet called Bezdomni. Each of them had a string of length .
Soon the mysterious black magic specialist, Professor Woland, joined them and said:
"Gentlemen, you have very interesting strings, and I can tell at a glance whether they are close or not!"
One move picks two consecutive letters of one string and shifts both of them forward one step in the alphabet, cyclically. For example, the pair ab becomes bc, and the pair qz becomes ra. Two strings are close if applying moves to both of them can make them equal.
"Surely you are talking nonsense, Professor. Deciding whether two strings are close is notoriously hard."
"No, Mihail Aleksandrovič, you are wrong, and I will prove it! I will tell you whether your strings are close, and then you will make changes to your string. After each change, I will tell you whether your strings are close."
"Very bold, Professor, truly very bold. Let us begin!"
Input
The first line contains the natural numbers and , the length of the strings and the number of changes.
The second line contains the string of length that belongs to Berlioz.
The third line contains the string of length that belongs to Bezdomni.
Each of the next lines contains a number and a character . This means that in the -th change, Berlioz changed the -th letter to .
Output
On the first line, print da if the initial strings are close, and ne if they are not.
On each of the next lines, print whether the strings are close after the -th change to Berlioz's string.
Hint
In the first sample, after the change, the words are close by the following moves: abc → bcc → cdc → dec → dfd, and ced → dfd.