Logo is an educational programming language where a turtle robot draws pictures by following commands.
The turtle is represented by a point on the coordinate plane and a facing direction. It may hold its pencil up or down. When it moves with the pencil down, it draws a line along its path. When it moves with the pencil up, it moves without drawing.
Initially, the turtle is at (0, 0), faces the direction of increasing y-coordinate, and has its pencil down.
The turtle can be controlled with the following five commands.
FD x: move the turtle forward by x.LT a: rotate the turtle counterclockwise by a degrees.RT a: rotate the turtle clockwise by a degrees.PU: lift the pencil.PD: put the pencil down.You are given the boundaries of N axis-aligned rectangles. Find the minimum number of PU commands needed to draw all of these boundaries.
The turtle may draw the same segment more than once. However, it must not draw any line other than the boundaries of the given rectangles. The turtle is so small that it can be treated as a point on the coordinate plane.
The first line contains the number of rectangles N. (1 <= N <= 1000)
Each of the next N lines contains four integers x1, y1, x2, y2 for one rectangle. (-500 <= x1 < x2 <= 500), (-500 <= y1 < y2 <= 500). The points (x1, y1) and (x2, y2) are opposite corners of the rectangle.
Print the minimum number of PU commands needed to draw the boundaries of all N rectangles.