Dragon curve
Time limit1sMemory limit256 MB
Report the cursor position after the Xth drawn segment of the order N dragon curve generated by the given rewriting rules.
- Level
Medium7 of 10
- Topics
- Recursion, Divide and conquer, Geometry, Simulation
- Solved
- No attempts yet
Problem
is the string Fa. For , build by rewriting every character of :
abecomesaRbFR.bbecomesLFaLb.F,L, andRstay as they are.
So is Fa, is FaRbFR, and is FaRbFRRLFaLbFR.

Read the string as drawing commands. F means move one unit forward along the current heading and draw the segment, L means turn 90 degrees left, and R means turn 90 degrees right. a and b do nothing. The cursor starts at facing . The picture drawn by running all of is the dragon curve of order , and the image above is .
One F counts as one step. Run the commands of from the beginning and report where the cursor is once it has finished step .
Input
The input holds several test cases. Each line has two integers and separated by one space, and the input ends at end of file.
and . never exceeds the number of F characters in . If is 0, the cursor has not moved yet.
Output
For each test case, print the coordinate and the coordinate of the cursor on one line, separated by one space.