Problems
Twirl Around
Twirl Around
Let's think about a bar rotating clockwise as if it were a twirling baton moving on a planar surface surrounded by a polygonal wall (see \textit{\textbf{Figure 1}}).
\includegraphics{https://static.e-olymp.com/content/ba/ba0ece2a623f0c77437cdf1314601a7cf85ae1c3.jpg}
\textit{\textbf{Figure 1}}. A bar rotating in a polygon
Initially, an end of the bar (called "\textbf{end A}") is at (\textbf{0}, \textbf{0}), and the other end (called "\textbf{end B}") is at (\textbf{0}, \textbf{L}) where \textbf{L} is the length of the bar. Initially, the bar is touching the wall only at the end \textbf{A}.
The bar turns fixing a touching point as the center. The center changes as a new point touches the wall.
Your task is to calculate the coordinates of the end \textbf{A} when the bar has fully turned by the given count \textbf{R}.
\includegraphics{https://static.e-olymp.com/content/36/36fa20fba88ac68d38475da99a35a345a353d4bb.jpg}
\textit{\textbf{Figure 2}}. Examples of turning bars
In \textit{\textbf{Figure 2}}, some examples are shown. In cases (\textbf{D}) and (\textbf{E}), the bar is stuck prematurely (cannot rotate clockwise anymore with any point touching the wall as the center) before \textbf{R} rotations. In such cases, you should answer the coordinates of the end \textbf{A} in that (stuck) position.
You can assume the following: When the bar's length \textbf{L} changes by \textbf{ε} (\textbf{|ε}| < \textbf{0.00001}), the final (\textbf{x}, \textbf{y}) coordinates will not change more than \textbf{0.0005}.
\InputFile
The input consists of multiple datasets. The number of datasets is no more than \textbf{100}. The end of the input is represented by "\textbf{0 0 0}".
The format of each dataset is as follows:
\textbf{L R N}
\textbf{X_1 Y_1}
\textbf{X_2 Y_2}
\textbf{...}
\textbf{X_N Y_N}
\includegraphics{https://static.e-olymp.com/content/49/49270e28ebc371c9e6e548fe5edf6353526f0ecb.jpg}
\textbf{L} is the length of the bar. The bar rotates \textbf{2R} radians (if it is not stuck prematurely). \textbf{N} is the number of vertices which make the polygon.
The vertices of the polygon are arranged in a counter-clockwise order. You may assume that the polygon is simple, that is, its border never crosses or touches itself.
\textbf{N}, \textbf{X_i} and \textbf{Y_i} are integer numbers; \textbf{R} and \textbf{L} are decimal fractions. Ranges of those values are as follows: \textbf{1.0} ≤ \textbf{L} ≤\textbf{500.0}, \textbf{1.0} ≤ \textbf{R} ≤ \textbf{10.0}, \textbf{3} ≤ \textbf{N} ≤ \textbf{100}, \textbf{-1000} ≤ \textbf{X_i} ≤ \textbf{1000}, \textbf{-1000} ≤ \textbf{Y_i} ≤ \textbf{1000}, \textbf{X_1} ≤ \textbf{-1}, \textbf{Y_1} = \textbf{0}, \textbf{X_2} ≥ \textbf{1}, \textbf{Y_2 = 0}.
\OutputFile
For each dataset, print one line containing x- and y-coordinates of the final position of the end \textbf{A}, separated by a space. The value may contain an error less than or equal to \textbf{0.001}. You may print any number of digits after the decimal point.
Note that the above sample input corresponds to the cases in \textit{\textbf{Figure 2}}. For convenience, in \textit{\textbf{Figure 3}}, we will show an animation and corresponding photographic playback for the case (\textbf{C}).
\includegraphics{https://static.e-olymp.com/content/7b/7b13b2e55ad078ef0bf7a0d5d7037554d9381312.gif}
\includegraphics{https://static.e-olymp.com/content/1e/1e244d4685cf610b1ebf501717ded1cb8a1f0ddc.jpg}
\textit{\textbf{Figure 3}}. Animation and photographic playback for case (\textbf{C})
Input example #1
4.0 2.0 8 -1 0 5 0 5 -2 7 -2 7 0 18 0 18 6 -1 6 4.0 2.0 4 -1 0 10 0 10 12 -1 12 4.0 1.0 7 -1 0 2 0 -1 -3 -1 -8 6 -8 6 6 -1 6 4.0 2.0 6 -1 0 10 0 10 3 7 3 7 5 -1 5 5.0 2.0 6 -1 0 2 0 2 -4 6 -4 6 6 -1 6 6.0 1.0 8 -1 0 8 0 7 2 9 2 8 4 11 4 11 12 -1 12 0 0 0
Output example #1
16.0 0.0 9.999999999999998 7.4641016151377535 0.585786437626906 -5.414213562373095 8.0 0.0 6.0 0.0 9.52786404500042 4.0