This page is still under construction.

Parts of this page are still being built. What you see may change.

Kontringsattack

Time limit4sMemory limit1024 MB

Summary
Choose the smallest K so that counting matches with |F-S|<=K as ties maximizes Friberg's wins minus Skog's wins.
Level

Medium6 of 10

Topics
Sorting, Greedy, Array, Math
Solved
No attempts yet

Problem

Friberg and Skog often play the computer game Kontringsattack together. In each match, a score is awarded that shows how well the player performed during the match. Sometimes Skog claims he is better than Friberg at Kontringsattack, because he scored more points than Friberg in a number of matches. Friberg counters by claiming that if the difference between Friberg's and Skog's scores in a match is less than or equal to some number K≥0K\ge 0, then it is impossible to determine who was better in that match. More formally: if Friberg scored FF points and Skog scored SS points, then they are considered equally good when ∣F−S∣≤K|F - S| \le K, otherwise the player with the higher score is better.

Of course, it is Friberg who decides the number KK. Given a number of matches and Friberg's and Skog's scores in them, what value should Friberg set for KK so that the difference between the number of matches where Friberg is better and the number of matches where Skog is better becomes as large as possible? If there are several such values, find the smallest one.

Input

  • The first line contains an integer NN (1≤N≤100 0001 \le N \le 100\,000).
  • The following NN lines contain two integers FF, SS (0≤F,S≤1 000 0000 \le F, S \le 1\,000\,000), Friberg's score and Skog's score respectively.

Output

One line with the integer KK.

Examples3

  1. Example 1

    Input
    3
    5 6
    6 8
    7 2
    
    Expected output
    2
    
  2. Example 2

    Input
    1
    3 5
    
    Expected output
    2
    
  3. Example 3

    Input
    3
    4 6
    6 4
    3 3
    
    Expected output
    0