Under construction

Still being built. Things may change

Gathering Red-Black Fruits

Time limit2sMemory limit512 MB

Summary
Count how many distinct rankings of N children can arise from scoring each red fruit r and black fruit b for some positive integers r, b.
Level

Hard8 of 10

Topics
Geometry, Sorting, Math, Combinatorics
Solved
No attempts yet

Problem

It is harvest time at Farmer Fred's orchard of red-black trees. Fred is too old to climb the trees, so he brought all his grandchildren to the orchard for a fruit gathering competition. Whoever collects the most fruit wins jars of red-black jam.

Red-black trees are special because one tree gives two kinds of fruit: red fruit and black fruit. That leaves Fred with a problem: how should he rank children who collected equal amounts of different fruits? For instance, if Abby picked two red fruits and three black fruits, and Bruce picked three red fruits and two black fruits, who should rank higher? How many points should each fruit be worth?

To settle this, Fred decided that each red fruit is worth (r) points and each black fruit is worth (b) points, where (r) and (b) are both positive integers. He ranks the children by their total points, and breaks ties arbitrarily.

All that remains is to choose the values of (r) and (b). Fred grew curious, and now he wants to know in how many ways he can rank his grandchildren under these rules. Two rankings are different if and only if some child has a different position in them.

Input

The first line contains an integer (N), the number of Fred's grandchildren. ((2 \le N \le 1000))

Each of the next (N) lines describes the fruits one grandchild gathered, given as two integers (R) and (B): the numbers of red fruits and black fruits that child gathered. ((0 \le R, B \le 10^4))

Output

Print one line with the number of different possible rankings under these rules, modulo (10^9 + 7).

Examples3

  1. Example 1

    Input
    3
    0 2
    1 2
    2 1
    
    Expected output
    3
    
  2. Example 2

    Input
    4
    1 0
    1 3
    2 2
    1 3
    
    Expected output
    6
    
  3. Example 3

    Input
    4
    0 0
    3 1
    0 0
    0 0
    
    Expected output
    6