Railroad

Given n intervals with distinct endpoint positions, find the maximum number of intervals fully contained in some segment of fixed length d.

Medium6SortingSliding windowTwo pointersIntervalsInterviewNo attempts yetTime limit1sMemory limit512 MB

Problem

There are nn people who commute between home and office. Each person's home and office sit at two different points on a horizontal line. For any two people AA and BB, the position of AA's home or office may coincide with the position of BB's home or office.

To help the commuters, a railroad is laid between two points on that line and a train runs along it. The budget is limited, so the length of the railroad is fixed at dd. Place the railroad so that the number of people whose home and office both lie on it is as large as possible.

You are given a positive integer dd and nn integer pairs (hi,oi)(h_i, o_i) for 1in1 \le i \le n, where hih_i is the home position of person ii and oio_i is the office position. Over all segments LL of length dd, find the largest number of people whose home and office are both contained in LL. A segment contains its two endpoints.

Figure 1. Home and office positions of eight people

Figure 1 shows the home and office positions of eight people. With d=30d = 30, the red segment from position 10 to position 40 is one of the segments that contain the homes and offices of the most people, and that count is 4.

Input

Input is read from standard input. The first line has a positive integer nn (1n100,0001 \le n \le 100{,}000), the number of people. Each of the next nn lines has an integer pair hih_i and oio_i separated by a space. Both hih_i and oio_i lie between 100,000,000-100{,}000{,}000 and 100,000,000100{,}000{,}000, and they differ from each other. The last line has an integer dd (1d200,000,0001 \le d \le 200{,}000{,}000), the length of the railroad.

Output

Output is written to standard output. Print on one line the largest number of people whose home and office both lie inside a segment of length dd.