Before you can give the destination to the captain, you realize that the actual action meanings were printed on the back of the instructions the whole time.

Almost all of the actions indicate how to move a waypoint which is relative to the ship’s position:

The waypoint starts 10 units east and 1 unit north relative to the ship. The waypoint is relative to the ship; that is, if the ship moves, the waypoint moves with it.

For example, using the same instructions as before:

After these operations, the ship’s Manhattan distance from its starting position is 214 + 72 = 286.

Assignment

Figure out where the navigation instructions actually lead. What is the Manhattan distance between that location and the ship’s starting position? Determine this in the following way:

This static function must be located in the class Submission.

Example

In this interactive session we assume the text file instructions.txt1 to be located in the current directory.

> Submission.distance("instructions.txt")
286