H - Hurrying Back Home

Languages: C, C++, Java, Python, Kotlin, C#
Time & Memory limits: (details)

The cute robot WALL-E is collecting trash on planet Earth, which we will represent as a 2D cartesian plane.

Initially, WALL-E is sitting in his base station at coordinate $(0, 0)$, facing north, ie, towards the positive Y-axis. In its routine tasks of locating garbage, WALL-E executes a number of operations of the following types:

  • $L$: Turn left 90 degrees
  • $R$: Turn right 90 degrees
  • $F$ $x$: Advance forward $x$ units of distance in the direction that he's facing

After executing those operations, WALL-E finally finds a piece of garbage and now he must return back to the base station. As his energy level is quite low, WALL-E must return to the base station using the minimum number of operations. In particular, the operation of type "$F$ $x$" counts as a single operation regardless of the distance $x$ that WALL-E travels under such an operation. In addition, the final orientation that WALL-E reaches coordinate $(0, 0)$ does not matter.


The first line in the input contains an integer $N$ $(1 \le N \le 100)$, the number of operations that WALL-E executes before finding a piece of garbage.

The next $N$ lines contain the operations that WALL-E executes in chronological order. These lines are formatted as described above. For the operation of type "$F$ $x$", $x$ is an integer in the range $1$ to $100$.


Print the minimum number of operations that WALL-E requires to reach the base at $(0,0)$.

Sample test(s)

1 F 10
7 F 10 L F 10 L F 10 L F 10