G. Geometric Balance
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Peter's little brother Ivan likes to play with a turtle. The turtle is a special toy that lives on the plane and can execute three commands:

  • Rotate $$$a$$$ degrees counterclockwise.
  • Draw $$$d$$$ units in the direction it is facing while dispensing ink. No segment of the plane will be covered by ink more than once.
  • Move $$$d$$$ units in the direction it is facing without drawing.

Ivan just learned about the compass, so he will only rotate his turtle so it faces one of eight cardinal or ordinal directions (angles $$$a$$$ in rotate commands are always divisible by 45). Also, he will perform at least one draw command.

Peter has noted all the commands Ivan has given to his turtle. He thinks that the image drawn by the turtle is adorable. Now Peter wonders about the smallest positive angle $$$b$$$ such that he can perform the following operations: move the turtle to a point of his choosing, rotate it by $$$b$$$ degrees, and execute all the commands in the same order. These operations should produce the same image as the original one. Can you help Peter?

Note, two images are considered the same if the sets of points covered by ink on the plane are the same in both of the images.

Input

The first line of the input contains a single integer $$$n\;(1 \le n \le 50000)$$$ — the number of commands Ivan has given.

The next $$$n$$$ lines contain commands. Each command is one of:

  • "rotate $$$a$$$" ($$$45 \le a \le 360$$$) where $$$a$$$ is divisible by $$$45$$$;
  • "draw $$$d$$$" ($$$1 \le d \le 10^9$$$);
  • "move $$$d$$$" ($$$1 \le d \le 10^9$$$).

At least one and at most 2000 of the commands are draw. It is guaranteed that no segment of the plane will be covered by ink more than once.

Output

Output a single number, the answer to the question. The answer always exists.

Examples
Input
1
draw 10
Output
180
Input
7
draw 1
rotate 90
draw 1
rotate 90
draw 1
rotate 90
draw 1
Output
90
Input
3
draw 1
move 1
draw 2
Output
360