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 Haskell (GHC 7.10.3) (judge verdict: Time Limit Exceeded)

{-# LANGUAGE ScopedTypeVariables, FlexibleContexts #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.Monad.RWS
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Ord
import Data.Maybe
import Data.Monoid
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  n <- getInt
  ps <- replicateM n getIntPair
  print $ solve ps

solve :: [(Z,Z)] -> Fp
solve ps = let
  amax = maximum $ map fst ps
  bmax = maximum $ map snd ps
  src = elems $ accumArray (flip (:)) [] (-amax,amax) $ map (\(a,b) -> (-a,-b)) ps
  snk = elems $ accumArray (flip (:)) [] (-amax,amax) $ ps
  dp s t = do
    let s' = elems $ accumArray (+) 0 (-bmax,bmax) $ zip s (repeat 1)
    d <- get
    let d' = elems d
        e' = zipWith (+) d' $ zipWith (+) s' $ 0 : e'
        e = listArray (-bmax,bmax) e'
    put e
    sequence [tell (e!b) | b <- t]
    return ()
  (_,_,(Sum x)) = runRWS (sequence [dp s t | (s,t) <- zip src snk]) () (listArray (-bmax,bmax) (repeat 0))
  fact n  = product $ map fint [1..n]
  f n m = fact (n+m) / (fact n * fact m)
  in  (x - sum [f (2*a) (2*b) | (a,b)<-ps]) / 2

 
type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "YES"
yesNo False = "NO"

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . unwords . map show

readLnList :: (Read a) => IO [a]
readLnList = map read . words <$> getLine


-----  Modulo
theMod = 10^9 + 7 :: Int  -- and assume 64 bits

newtype Fp = Fp Int  deriving (Eq)

instance Show Fp  where
  showsPrec p (Fp x) = showsPrec p x

instance Num Fp  where
  (Fp x) + (Fp y) = Fp ((x + y) `mod` theMod)
  (Fp x) - (Fp y) = Fp ((x - y) `mod` theMod)
  (Fp x) * (Fp y) = Fp ((x * y) `mod` theMod)
  negate (Fp x) = Fp ((negate x) `mod` theMod)
  abs _ = error "Fp: abs"
  signum _ = error "Fp: signum"
  fromInteger x = Fp (fromInteger (x `mod` toInteger theMod))

instance Fractional Fp  where
  recip (Fp x) = Fp ((fst . snd $ egcd x theMod) `mod` theMod)
  fromRational = undefined

egcd :: (Integral a) => a -> a -> (a,(a,a))
egcd a b = last $ zip (takeWhile (/= 0) r) $ zip s t
  where
    r = a : b : zipWith mod r (tail r)
    q = zipWith div r (tail r)
    s = 1 : 0 : zipWith (-) s (zipWith (*) q (tail s))
    t = 0 : 1 : zipWith (-) t (zipWith (*) q (tail t))

-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw

-- vi:expandtab: