P2625 Luxury Cruise Ship

Description

There is a luxury cruise ship (actually just a small wooden boat). This ship can execute $4$ types of commands: `right X`: where $X$ is an integer from $1$ to $719$. This command rotates the ship clockwise by $X$ degrees. `left X`: where $X$ is an integer from $1$ to $719$. This command rotates the ship counterclockwise by $X$ degrees. `forward X`: where $X$ is an integer ($1$ to $1000$). This command moves the ship $X$ units straight ahead along its current heading. `backward X`: where $X$ is an integer ($1$ to $1000$). This command moves the ship $X$ units straight backward along its current heading. You are given $n$ 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 (1 \leq n \leq 50)$, representing the number of given commands. The next $n$ lines each contain one command.

Output Format

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

Explanation/Hint

Translated by ChatGPT 5