A group of civil engineers are trying to model what will happen to a building if it experiences natural disasters. Using rulers to model the bricks of the building, they set up a column of $$$N$$$ rulers numbered from $$$1$$$ to $$$N$$$, lined up from end to end along the positive y-axis of the coordinate plane, with the first ruler starting at the origin. Each ruler has a length $$$L_i$$$. Consecutive rulers are connected by a "joint" that can turn. Initially, the angle between each consecutive ruler is $$$180$$$ degrees, so the first ruler has endpoints at ($$$0, 0$$$) and ($$$0, L_1$$$), the second ruler has endpoints at ($$$0, L_1$$$) and ($$$0, L_1+L_2$$$), and so on.
John receives a list of $$$K$$$ instructions. Each instruction contains an integer $$$S_i$$$ and an angle of degree $$$A_i$$$, telling him to turn the joint connecting ruler $$$S_i$$$ and ruler $$$S_i+1$$$ such that ruler $$$S_i+1$$$ is counterclockwise from $$$S_i$$$ by exactly $$$A_i$$$ degrees. When he turns this joint, all rulers with index $$$S_i+1$$$ and higher turn together (their relative angles remain the same) but rulers with lower index do not. After John finishes executing all the instructions, find the location of the endpoint of the last ruler.
Line $$$1$$$: Two space separated positive integers, $$$N$$$ and $$$K$$$ ($$$1 \le N, K \le 10^5$$$), where $$$N$$$ is the number of rulers and $$$K$$$ is the number of instructions John must execute.
Line $$$2$$$: $$$N$$$ space separated integers $$$L_1, L_2,..., L_N$$$, where $$$L_i$$$ ($$$1 \le L_i \le 100$$$) is the length of the $$$i$$$th ruler.
Lines $$$3…K+2$$$: Two space-separated positive integers, $$$S_i$$$ and $$$A_i$$$, where $$$S_i$$$ ($$$0 \le S_i \lt N$$$) is the index of a ruler and $$$A_i$$$ ($$$0 \le A_i \le 360$$$) is in degrees. If $$$S_i$$$ is $$$0$$$, then you will rotating the first ruler until it is $$$A_i$$$ degrees counterclockwise of the x-axis.
Line $$$1$$$: The x-coordinate followed by the y-coordinate of the endpoint of the last ruler after all the turns have been executed. Your answer will be considered correct if it is within $$$10^{-4}$$$ of the correct answer.
3 3 2 2 3 2 180 1 270 1 0
0 -3
The coordinates of the final point may not be in integers.