Problem:
Score : 1400 points

Problem Statement

Snuke is having another barbeque party.

This time, he will make one serving of Skewer Meal.

He has a stock of N Skewer Meal Packs. The i-th Skewer Meal Pack contains one skewer, A_i pieces of beef and B_i pieces of green pepper.
All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.

To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper.
(Remaining Skewer Meal Packs will not be used.)
Then, all those pieces of food are threaded onto both skewers, one by one, in any order.

(See the image in the Sample section for better understanding.)

In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different.
Since this number can be extremely large, find it modulo 10^9+7.

Constraints

2≦N≦200,000

1≦A_i≦2000, 1≦B_i≦2000

Input

The input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
:
A_N B_N

Output

Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo 10^9+7.

Sample Input 1

3
1 1
1 1
2 1

Sample Output 1

26

The 26 ways of making a Skewer Meal are shown below.
Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer.
Brown and green rectangles represent pieces of beef and green pepper, respectively.

Solution in Rust (1.15.1) (judge verdict: Time Limit Exceeded)

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { parse(&get_word()) }

const MOD: i64 = 1_000_000_007;
const BIAS: usize = 2010;
const W: usize = 4001;

fn inv(t: i64) -> i64 {
    let mut sum = 1;
    let mut cur = t;
    let mut e = MOD - 2;
    while e > 0 {
        if e % 2 == 1 {
            sum = sum * cur % MOD;
        }
        cur = cur * cur % MOD;
        e /= 2;
    }
    sum
}

fn main() {
    let n: usize = get();
    let mut tbl: Vec<Vec<i64>> = vec![Vec::new(); W];
    for i in 0 .. W {
        tbl[i] = vec![0; i + 1];
        let mut t = 1;
        for j in 0 .. (i + 1) {
            tbl[i][j] = t;
            t = t * (i - j) as i64 % MOD;
            t = t * inv(j as i64 + 1) % MOD;
        }
    }
    let mut f = vec![0_i64; 2 * BIAS];
    let mut dbl = 0_i64;
    for _ in 0 .. n {
        let a: usize = get();
        let b: usize = get();
        for i in 0 .. a + b + 1 {
            f[i + BIAS - a] += tbl[a + b][i];
        }
        dbl += tbl[2 * a + 2 * b][2 * a];
        dbl %= MOD;
    }
    for v in &mut f {
        *v %= MOD;
    }
    // squaring
    let mut f2 = vec![0_i64; 4 * BIAS];
    for i in 0 .. 2 * BIAS {
        for j in 0 .. 2 * BIAS {
            let t: i64 = f[i];
            f2[i + j] += t * f[j];
            f2[i + j] %= MOD;
        }
    }
    let mut r = (f2[2 * BIAS] - dbl + MOD) % MOD;
    r *= (MOD + 1) / 2;
    r %= MOD;
    println!("{}", r);
}