Moving Logs
시간 제한0.5초메모리 제한1024 MB
서로 교차하지 않는 n개의 통나무가 주어질 때, 오른쪽으로 이동 경로를 막는 통나무가 없어야 빼낼 수 있다는 규칙 아래 모든 통나무를 빼내는 최소 시간을 구한다.
문제
There are logs placed in a rectangular warehouse. The logs do not intersect or overlap each other. The right wall of the warehouse is open, through which logs can be dragged out to the right. A log is only moved parallel in the positive -axis direction. A log can only be pulled out if there are no other logs in the space through which it will move. In Figure G.1, the movement space of log 3 is grayed out. Log 3 cannot be pulled out until logs 1 and 5 have been removed.
Multiple logs can be pulled out simultaneously if there are no other logs in the space through which they will move. Suppose that it takes 1 unit of time to pull out a log. Your task is to pull out all the logs of the warehouse as quickly as possible.
In Figure G.1, in order to pull out all five logs, you have to pull out the logs one by one in the order of 1-5-3- 2-4. Therefore, it takes 5 units of time to complete the task. Note that since the end point of log 1 is located in the movement space of log 5, it is not possible to pull out log 5 first.
Consider an example shown in Figure G.2. Logs 2 and 4 can be pulled out at the same time. After that, you can pull out logs 1 and 3 at the same time. Finally, you can pull out log 5. Therefore, it takes 3 units time.
Given the locations of logs, write a program to find the minimum time required to pull out all the logs.
입력
Your program is to read from standard input. The input starts with a line containing an integer (), where is the number of logs. The logs are numbered from to . In the following lines, the -th line contains four integers, , , , and , where and are the coordinates of both end points of the -th log and all the integers are between and . The length of a log is more than and no two logs intersect each other at any point.
출력
Your program is to write to standard output. Print exactly one line. The line should contain an integer representing the minimum units of time to pull out all the logs.

