Double Attendance
면접 대비시간 제한3초메모리 제한1024 MB
두 강의실의 열린 슬라이드 구간들과 강의실 사이 이동 시간 K가 주어질 때, 1번 강의실에서 시작해 볼 수 있는 서로 다른 슬라이드의 최대 개수를 구한다.
문제
Due to a rather ambitious school schedule, two of your classes are about to be held starting at exactly the same time, in two different classrooms! You can only be in one place at a time, so the best you can hope for is catching the important bits of both, even if that means sneaking back and forth between the two.
The two classrooms are numbered and . In classroom , the teacher will show different slides during the class, with the slide shown throughout the exclusive time interval where and are times elapsed since the start of class measured in seconds. In both classes, there does not exist a point in time at which multiple slides are simultaneously being shown. For example, a class may have slides spanning the pair of intervals and , or the pair and , but not the pair and .
You begin the day in classroom with both classes starting at time . Following that, at any point in time (not necessarily after an integral number of seconds), you may move from your current classroom to the other one in seconds. You consider yourself to have seen a slide if you spend a positive amount of time in its classroom strictly within the time interval during which it's being shown. When moving between the two classrooms, you're not considered to be inside either of them for seconds and are thus unable to see any slides.
For example, if classroom has a slide being shown for the time interval , classroom has a slide being shown for the time interval , and , then you'll get to see both slides if you move from classroom to classroom at time seconds (arriving at time seconds). On the other hand, if you leave classroom at time seconds (arriving at time seconds), then you'll enter classroom just after its slide stops being shown and will therefore miss it.
What's the maximum number of distinct slides which you can see at least once?
입력
The first line contains three space-separated integers , , and .
The next lines each contain two space-separated integers and .
The next lines each contain two space-separated integers, and .
출력
Output one integer which is the maximum number of distinct slides which you can see.