Олимпиадный тренинг

Задача 38387. Treasure


Finding a treasure buried by pirates is easy: all you need is – this is a map. As you know, pirates usually draw maps by hand and describe the algorithm for finding the treasure as follows: “Stand near a lonely palm tree. Walk thirty steps towards the forest, then seventeen steps towards the lake, …, finally ten steps towards the large boulder. The treasure is under it. Most of these directions simply come down to walking a certain number of steps in one of eight directions (1 – north, 2 – northeast, 3 – east, 4 – southeast, 5 – south, 6 &ndash ; southwest, 7 – west, 8 – northwest) (see fig.). The stride length in any direction is 1.
    Traveling along this path is usually a great way to see the surroundings, but in this time of constant rush, no one has time for this. Therefore, treasure hunters want to go directly to the point where the treasure is buried. For example, instead of walking three steps north, one step east, one step north, three steps east, two steps south, and one step west, one can walk directly using about 3.6 steps (see pic) .


You need to write a program that, according to the instructions of the pirates, determines the point where the treasure is buried.
 Input data format
    First line  contains the number N – number of indications (1≤N≤40). The next N lines contain the – the direction number (an integer from 1 to 8) and the number of steps (an integer from 1 to 1000). Numbers are separated by spaces.
Output data format
    Print the X and Y coordinates of the point (two real numbers separated by a space) where the treasure is buried, assuming that the Ox axis is directed to the east and the Oy axis – on North. At the beginning, the treasure hunter must stand at the origin. The coordinates must be displayed with an error of no more than 10-3.
 
Examples
# Input Output
1 6
1 3
3 1
1 1
3 3
5 2
7 1
3.000 2.000
2 1
8 10
-7.071 7.071