Art Exhibition

Choose a subset of artworks maximizing the sum of values minus the difference between the largest and smallest sizes in the subset.

Medium5SortingPrefix sumGreedyInterviewNo attempts yetTime limit1sMemory limit256 MB

Problem

Seungwon owns NN artworks, numbered from 1 to NN. Artwork ii has size AiA_i and value BiB_i.

Today Seungwon wants to exhibit some of the artworks on the first floor of his mansion. He chooses the artworks to exhibit under the following condition.

  • Let AmaxA_{max} be the largest size and AminA_{min} the smallest size among the exhibited artworks, and let SS be the sum of their values.
  • The quantity S(AmaxAmin)S - (A_{max} - A_{min}) must be as large as possible.

At least one artwork is exhibited. Given the sizes and values of the NN artworks, write a program that finds the maximum possible value of S(AmaxAmin)S - (A_{max} - A_{min}).

Input

The first line contains the number of artworks NN (2N500,0002 \le N \le 500{,}000).

Each of the next NN lines contains the size AiA_i and the value BiB_i of one artwork, in order from artwork 1 to artwork NN. (1Ai1,000,000,000,000,000=10151 \le A_i \le 1{,}000{,}000{,}000{,}000{,}000 = 10^{15}, 1Bi1,000,000,0001 \le B_i \le 1{,}000{,}000{,}000)

Output

Print the maximum value of S(AmaxAmin)S - (A_{max} - A_{min}) on the first line.

Hint

In the first sample, Seungwon owns 3 artworks with the following sizes and values.

  • Artwork 1 has size 2 and value 3.
  • Artwork 2 has size 11 and value 2.
  • Artwork 3 has size 4 and value 5.

Exhibiting artworks 1 and 3 gives S(AmaxAmin)=6S - (A_{max} - A_{min}) = 6, which is the largest possible value.

  • The largest exhibited artwork is artwork 3, so Amax=4A_{max} = 4.
  • The smallest exhibited artwork is artwork 1, so Amin=2A_{min} = 2.
  • The sum of the exhibited values is 3+5=83 + 5 = 8.

Therefore S=8S = 8 and S(AmaxAmin)S - (A_{max} - A_{min}) is 6.