time limit per test: 0.25 sec. memory limit per test: 4096 KB
input: standard output: standard
You are to write a simple text editor. This editor must supply next commands:
english lowercase letters or spaces: insert this letter in the current position of the cursor.
L: move cursor one position left. If current position in the beginning of the line, cursor mustn't move.
R: move cursor one position right. If the current position if after the end of the line, cursor must go beyond this end. If an english lowercase letter or space follows in command line, additional spaces must be added to the text.
U: move cursor a line up. If the current line is the first, cursor mustn't move.
D: move cursor a line down. If the current line is last, cursor mustn't move.
N: a new line must be added after the current. The part of the current line, which goes after the cursor position, must go on the new line. The cursor must go on the first position of the new line.
E: a cursor must move to a position after the end of the curent line.
H: a cursor must move to the first position of the current line.
X: current symbol must be deleted. The remaining part of the line must shift left. If the current position is after the end of the current line, additional spaces must be added to the current line and the next line must be attached to the current line; if the current position is after the end of the last line, nothing must happen.
B: the symbol before the the cursor must be deleted and the remaining part of the line must shift left. If the current position if after the end of the line, cursor must shift left one position. If the current symbol is the first of the line, then current line must be attached to the previous and remaining part must shift up; if the current symbol is the first symbol of the first line, nothing must happen.
Q: the editor must finish the work.
The editor starts from the blank file.
It is guaranted that in any moment while working length of each string does not exceed 1000 chars, and total number of commands does not exceed 20480.
Input
On the input there is the only line --- the list of commands of the editor.
Output
Write to the output the result of working of the editor. The EOLn (symbols with ASCII numbers 13 and 10) chars must be only between lines generated by editor (NOT after the last string!)
Sample test(s)
Input
lineRoUNLLLLline dDDDNline tline cLLLLLLNEUULLXRRRBXHBBHBBBBQsome left output