Hide

Problem C
Router

In woodworking, a router is a versatile tool that can be used in joinery, detailing, and edging. In this problem, we will consider using a handheld router that can be moved across a flat wooden surface to create grooves.

To do this, you first insert the spinning routing bit into some place on the surface of the wood and then simply move the router along a path to carve out the groove. It has been a while since you used this tool, so you start by following a simple pattern that only has you moving the router up, down, left, or right.

Before trying this on your project, you plan to practice on a rectangular piece of scrap wood. So you might as well use the smallest piece of wood possible. To stay safe, the router should stay 20mm from the edge of the board at all times. Also, you will align the wood so that each instruction moves in parallel with one of the sides of the wood.

Your job is to find the minimum width and minimum height that is required for a piece of scrap wood that would allow you to safely practice routing the design.

\includegraphics[width=0.6\textwidth ]{router.pdf}
Figure 1: Illustration of the sample cases. The dashed lines delimit the 20mm buffer between the routing pattern and the edges of the board.

Input

The first line of input contains one integer $N$ ($1 \leq N \leq 100$) indicating the number of instructions. The next $N$ lines describe the sequence of instructions. The $i$’th instruction contains a single character $c_i$ (either U, D, L, or R) and then a single integer $d_i$ ($1 \leq d_i \leq 1000$). The character indicates if the instruction is to move the router up, down, left, or right (respectively) and the integer indicates we should move the router exactly $d_i$ millimeters in that direction.

Output

Output a single line with two integers $W$ and $H$ where $W$ is the minimum required width and $H$ is the minimum required height as described above.

Sample Input 1 Sample Output 1
4
U 20
R 10
L 30
D 5
70 60
Sample Input 2 Sample Output 2
4
U 10
R 20
D 10
L 20
60 50

Please log in to submit a solution to this problem

Log in