#P2625. 豪华游轮

豪华游轮

Description

There is a luxury cruise ship (actually just a small wooden boat). This ship can execute 44 types of commands:

right X: where XX is an integer from 11 to 719719. This command rotates the ship clockwise by XX degrees.

left X: where XX is an integer from 11 to 719719. This command rotates the ship counterclockwise by XX degrees.

forward X: where XX is an integer (11 to 10001000). This command moves the ship XX units straight ahead along its current heading.

backward X: where XX is an integer (11 to 10001000). This command moves the ship XX units straight backward along its current heading.

You are given nn commands written in arbitrary order. Find a way to arrange these commands so that the ship’s final position is as far from the starting point as possible.

Input Format

The first line contains an integer n(1n50)n (1 \leq n \leq 50), representing the number of given commands.

The next nn lines each contain one command.

Output Format

Output a floating-point number: the maximum achievable distance, rounded to 66 decimal places.

3
forward 100
backward 100
left 90
141.421356

Hint

Translated by ChatGPT 5