Corrupt Election

Count pairs (X, Y) such that voiding every voter with A_i>=X or B_i>=X or A_i+B_i>=Y leaves Cheki strictly ahead of Chaka.

Medium6Brute forceImplementationSortingNo attempts yetTime limit1sMemory limit64 MB

Problem

A few months ago the country of Chex held a presidential election. Two candidates ran, Cheki and Chaka. Cheki promised to put more chocolate into Chex, the staple cereal of the country, and Chaka promised to make Chex taste like green onion.

Chex runs its elections with repeated voting. One voter casts at most 100,000 ballots in total between the two candidates. When the election ends, the candidate with more votes takes office. If both candidates receive the same number of votes, nobody takes office.

The residents liked the fresh promise from Chaka and gave Chaka more votes, yet Cheki took office. A month later an employee of the election commission reported the count as rigged. According to that report, the ballots of some voters were all thrown out by the following rule.

  • If a voter cast XX or more ballots for a single candidate, or cast YY or more ballots in total, every ballot from that voter becomes void. XX and YY are fixed integers between 1 and 100,000.

Once the void ballots are removed, Cheki takes office only when Cheki has strictly more votes than Chaka. The whistleblower does not know the values of XX and YY either, so you have to work them out. Given the voting record, count the pairs (X,Y)(X, Y) that put Cheki in office.

Input

The first line contains the number of voters NN (2N10002 \le N \le 1000).

Each of the next NN lines contains AiA_i and BiB_i, the number of ballots that voter ii cast for Cheki and for Chaka (0Ai0 \le A_i, 0Bi0 \le B_i, 1Ai+Bi1000001 \le A_i + B_i \le 100000).

The input always has the sum of BiB_i greater than the sum of AiA_i.

Output

Print the number of pairs (X,Y)(X, Y) that put Cheki in office.

Note

In the first example Cheki takes office only when X=6X = 6 and 9Y1000009 \le Y \le 100000.