cho.sh
Notes
Loading...

Appointments

Time limit

2s

Memory limit

128 MB

Problem

N wizards made appointments with Muggles to better understand Muggle culture. Each wizard will meet exactly one Muggle. Because a wizard may arrive earlier or later than the appointment time, they want to adjust every appointment by the same integer T.

The waiting time for one appointment is the time that the person who arrives first waits until the other person arrives. The original appointment times are A_1, A_2, ..., A_N, and the wizards' arrival times are B_1, B_2, ..., B_N. If every appointment time is shifted by T, the total waiting time becomes the sum of |A_i + T - B_i|.

Find the number of distinct integers T that minimize the total waiting time.

Input

The first line contains N.

Each of the next N lines contains two integers A_i and B_i.

Output

Print the number of distinct integers T that minimize the total waiting time.

Constraints

  • 1 <= N <= 50
  • 1 <= A_i, B_i <= 10^9