logo AlgoBeat OnlineJudge
登录 注册

#212193. [NERC2024] Geometric Balance

内存限制:1024 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 degrees counterclockwise.
  • Draw units in the direction it is facing while dispensing ink. No segment of the plane will be covered by ink more than once.
  • Move 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 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 such that he can perform the following operations: move the turtle to a point of his choosing, rotate it by 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 if the sets of points covered by ink on the plane are the same in both of the images.

输入格式

The first line of the input contains a single integer --- the number of commands Ivan has given.

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

  • () where is divisible by ;
  • ();
  • ().

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

输出格式

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

样例

样例输入 1

1
draw 10

样例输出 1

180

样例输入 2

7
draw 1
rotate 90
draw 1
rotate 90
draw 1
rotate 90
draw 1

样例输出 2

90

样例输入 3

3
draw 1
move 1
draw 2

样例输出 3

360