LOGO | 프로그래밍의 벗 PivotOJ
PivotOJ

LOGO

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2009 National Competition #1 - JuniorsBOJ 3108

문제

Competition tasks for the programming language LOGO often involve drawing rectangles on the screen. Drawing in LOGO is done by moving a turtle-shaped cursor. 

The turtle is defined by its position and angle. It holds in its mouth a pencil that can be raised or lowered. When the pencil is lowered, moving the turtle causes the pencil to leave a trail on the screen. 

The turtle is initially at coordinates (0, 0) facing in the direction of increasing y coordinates, pencil lowered. We can manipulate the turtle with the following set of commands: 

  1. FD x – move the turtle x units forward. 
  2. LT α – turn the turtle α degrees counter-clockwise.
  3. RT α – turn the turtle α degrees clockwise. 
  4. PU – raise the pencil. 
  5. PD – lower the pencil. 

Your program will be given a set of rectangles (with sides parallel to coordinate axes) that need to be drawn on the screen. The turtle may go over the same segment with its pencil lowered multiple times, but it is not allowed to draw anything other than the given rectangles. 

Write a program that calculates the smallest number of times the pencil must be raised in order to draw all the rectangles. 

입력

The first line contains an integer N (1 ≤ N ≤ 1000), the number of rectangles. 

Each of the following N lines contains for integers x1, y1, x2 and y2 (−500 ≤ x1 < x2 ≤ 500), (−500 ≤ y1 < y2 ≤ 500) separated by a space. The points (x1, y1) and (x2, y2) are diagonally opposite corners of a rectangle. 

출력

Output the smallest number of times the pencil must be raised to draw the rectangles. 

 

예제

예제 1

입력
1
0 0 10 10
출력
0

예제 2

입력
1
-5 -5 5 5
출력
1

예제 3

입력
5
1 1 4 4
3 3 6 6
4 4 5 5
5 0 8 3
6 1 7 2
출력
2
코드를 제출하려면 로그인하세요.