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.



Sample input:
3
1 1
1 1
2 1


Sample output:
26

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
def solve():
	Base = 2000
	MAX = Base*2
	p = 10**9+7
	F = [1]; Finv = [0]*(MAX+1)
	for i in xrange(MAX*2): F.append(F[i]*(i+1)%p)
	Finv[MAX] = pow(F[MAX],p-2,p)
	for i in xrange(MAX,0,-1): Finv[i-1] = Finv[i]*i%p
	N = int(raw_input())
	dup = 0
	dp = [[0]*(MAX+2) for i in xrange(MAX+2)]
	goals = defaultdict(int)
	for i in xrange(N):
		A,B = map(int,raw_input().split())
		dup = (dup + F[A*2+B*2]*Finv[A*2]*Finv[B*2]%p)%p
		goals[(Base+A,Base+B)] += 1
		dp[Base-B][Base-A] += 1
	for j in xrange(MAX+1):
		for i in xrange(MAX+1):
			dp[j+1][i] += dp[j][i]
			dp[j][i+1] += dp[j][i]
	ans = 0
	for (i,j),v in goals.iteritems():
		ans = (ans + dp[j][i]*v) % p
	print ((ans - dup) / 2 + p) % p
solve()

Submission status: Time Limit Exceeded

Solution code:
import math

set_num = int(raw_input())
bbqsets = []
_append = bbqsets.append
for _ in xrange(set_num):
    _append([ int(x) for x in raw_input().split() ])

maxnum = math.pow(10, 9) + 7

cache = {}
total = 0
fact = math.factorial
for x in xrange(set_num):
    setA = bbqsets[x]
    for y in xrange(x + 1, set_num):
        setB = bbqsets[y]
        nums = tuple(sorted([setA[0] + setB[0], setA[1] + setB[1]]))
        cmb = 0
        if nums in cache:
            cmb = cache[nums]
        else:
            cmb = fact(nums[0] + nums[1]) / fact(nums[0]) / fact(nums[1])
            cache[nums] = cmb
        # print meats, veges
        total += cmb
        if total > maxnum:
            total = total % maxnum
print total

Submission status: Time Limit Exceeded

Solution code:
import math

set_num = int(raw_input())
bbqsets = []
_append = bbqsets.append
for _ in xrange(set_num):
    _append([ int(x) for x in raw_input().split() ])

maxnum = math.pow(10, 9) + 7

cache = {}
total = 0
for x in xrange(set_num):
    setA = bbqsets[x]
    for y in xrange(x + 1, set_num):
        setB = bbqsets[y]
        nums = tuple(sorted([setA[0] + setB[0], setA[1] + setB[1]]))
        cmb = 0
        if nums in cache:
            cmb = cache[nums]
        else:
            cmb = 1.0
            for n in xrange(1, nums[0] + 1):
                cmb *= float(nums[1] + n) / n
            # print nums, cmb
            cmb = round(cmb)
            cache[nums] = cmb
        # print meats, veges
        total += cmb
        if total > maxnum:
            total = total % maxnum
print int(total)

Submission status: Time Limit Exceeded

Solution code:
import scipy.misc as scm
def combi(p,q):
    return scm.comb(p,q,1)

ans=0
n=int(input())
k=[]
for i in range(n):
    a,b=map(int,input().split())
    k.append([a,b])

for i in range(n-1):
    for j in range(i+1,n):
        p=k[i][0]+k[i][1]+k[j][0]+k[j][1]
        q=k[i][0]+k[j][0]
        ans += combi(p,q) % (10**9+7)


ans = ans % (10**9+7)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def calc(ab1,ab2):
    meat = ab1[0] + ab2[0]
    vege = ab1[1] + ab2[1]
    pattern = fact_list[meat+vege] / (fact_list[meat] * fact_list[vege])
    return pattern
 
 
if __name__ == '__main__':
    N = int(input())
    AB = [list(map(int, input().split())) for i in range(N)]
 
    fact_list = {}
    fact_list[0] = 1
    # max_ab = max(AB[x][0] + AB[x][1] for x in range(N))
    for i in range(1,4001):
        fact_list[i] = (fact_list[i-1] * i) % (10**9 + 7)
 
    sum_count = 0
    for i in range(N):
        for j in range(i+1,N):
            sum_count += calc(AB[i],AB[j])
            sum_count = sum_count % (10**9 + 7)
 
    print( int(sum_count % (10**9 + 7)) )

Submission status: Time Limit Exceeded

Solution code:

def calc(ab1,ab2):
    meat = ab1[0] + ab2[0]
    vege = ab1[1] + ab2[1]
    pattern = fact_list[meat+vege] / (fact_list[meat] * fact_list[vege])
    return pattern


if __name__ == '__main__':
    N = int(input())
    AB = [list(map(int, input().split())) for i in range(N)]

    fact_list = {}
    fact_list[0] = 1
    # max_ab = max(AB[x][0] + AB[x][1] for x in range(N))
    for i in range(1,4001):
        fact_list[i] = fact_list[i-1] * i

    sum_count = 0
    for i in range(N):
        for j in range(i+1,N):
            sum_count += calc(AB[i],AB[j])
            sum_count = sum_count % (10**9 + 7)

    print( int(sum_count % (10**9 + 7)) )

Submission status: Time Limit Exceeded

Solution code:

def calc(ab1,ab2):
    meat = ab1[0] + ab2[0]
    vege = ab1[1] + ab2[1]
    pattern = fact_list[meat+vege] / (fact_list[meat] * fact_list[vege])
    return pattern


if __name__ == '__main__':
    N = int(input())
    AB = [list(map(int, input().split())) for i in range(N)]

    fact_list = {}
    fact_list[0] = 1
    # max_ab = max(AB[x][0] + AB[x][1] for x in range(N))
    for i in range(1,4001):
        fact_list[i] = fact_list[i-1] * i

    sum_count = 0
    for i in range(N):
        for j in range(i+1,N):
            sum_count += calc(AB[i],AB[j])

    print( int(sum_count % (10**9 + 7)) )

Submission status: Time Limit Exceeded

Solution code:
import math

set_num = int(raw_input())
bbqsets = []
_append = bbqsets.append
for _ in xrange(set_num):
    _append([ int(x) for x in raw_input().split() ])

maxnum = math.pow(10, 9) + 7

cache = {}
def get_combinations(meats, veges):
    nums = sorted([meats, veges])
    key = '{}:{}'.format(nums[0], nums[1])
    if key in cache:
        return cache[key]
    allnum = meats + veges
    greater = nums[1]
    result = 1.0
    for n in xrange(1, nums[0] + 1):
        t = greater + n
        result *= float(t) / n
    # print key, result
    result = round(result)
    cache[key] = result
    return result

total = 0
for x in xrange(set_num):
    setA = bbqsets[x]
    for y in xrange(x + 1, set_num):
        setB = bbqsets[y]
        meats = setA[0] + setB[0]
        veges = setA[1] + setB[1]
        # print meats, veges
        combinations = get_combinations(meats, veges)
        total += combinations
        if total > maxnum:
            total = total % maxnum
print int(total)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
import numpy as np


def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


MOD = 10 ** 9 + 7
n = int(sys.stdin.buffer.readline())
ab = list(map(int, sys.stdin.buffer.read().split()))
aaa = ab[0::2]
bbb = ab[1::2]
max_a = max(aaa)
max_b = max(bbb)
facts, invs = prepare(2 * (max_a + max_b), MOD)
dp_size = max_b * 2 + 1
ans = 0

dd_create_func = lambda: np.zeros(dp_size, dtype=np.int64)
get_ab = defaultdict(dd_create_func)
for a, b in zip(aaa, bbb):
    get_ab[a][b + max_b] += 1
    ans = (ans - facts[2 * (a + b)] * invs[2 * a] * invs[2 * b]) % MOD

dp = np.zeros(dp_size, dtype=np.int64)
for i in range(-max_a, max_a + 1):
    if i < 0 and -i in get_ab:
        dp += get_ab[-i][::-1]
    dp = np.add.accumulate(dp) % MOD
    if i > 0 and i in get_ab:
        ans = (ans + (dp * get_ab[i]).sum()) % MOD

print(ans * invs[2] % MOD)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
import numpy as np


def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


MOD = 10 ** 9 + 7
n = int(sys.stdin.buffer.readline())
ab = list(map(int, sys.stdin.buffer.read().split()))
aaa = ab[0::2]
bbb = ab[1::2]
max_a = max(aaa)
max_b = max(bbb)
facts, invs = prepare(2 * (max_a + max_b), MOD)
dp_size = max_b * 2 + 1
ans = 0

dd_create_func = lambda: np.zeros(dp_size, dtype=np.int64)
put_ab = defaultdict(dd_create_func)
get_ab = defaultdict(dd_create_func)
for a, b in zip(aaa, bbb):
    put_ab[-a][-b + max_b] += 1
    get_ab[a][b + max_b] += 1
    ans = (ans - facts[2 * (a + b)] * invs[2 * a] * invs[2 * b]) % MOD

dp = np.zeros(dp_size, dtype=np.int64)
for i in range(-max_a, max_a + 1):
    if i < 0 and i in put_ab:
        dp += put_ab[i]
    dp = np.add.accumulate(dp) % MOD
    if i > 0 and i in get_ab:
        ans = (ans + (dp * get_ab[i]).sum()) % MOD

print(ans * invs[2] % MOD)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

import numpy as np


def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


n = int(sys.stdin.buffer.readline())
mp = map(int, sys.stdin.buffer.read().split())
ab = list(zip(mp, mp))
atob = defaultdict(list)
max_a, max_b = 0, 0
for a, b in ab:
    atob[a].append(b)
    max_a = max(max_a, a)
    max_b = max(max_b, b)

MOD = 10 ** 9 + 7

dp = np.zeros(max_b * 2 + 1, dtype=np.int64)
ans = 0
for i in range(-max_a, max_a + 1):
    if i < 0 and -i in atob:
        for j in atob[-i]:
            dp[-j + max_b] += 1
    dp = np.add.accumulate(dp) % MOD
    if i > 0 and i in atob:
        for j in atob[i]:
            ans = (ans + dp[j + max_b]) % MOD

facts, invs = prepare(2 * (max_a + max_b), MOD)
ans = int(ans)
for a, b in ab:
    ans = (ans - facts[2 * (a + b)] * invs[2 * a] * invs[2 * b]) % MOD

print(ans * invs[2] % MOD)

Submission status: Accepted

Solution code:
mod = 10**9+7
mod2 = 998244353
rng = 100100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
s = 0
for a,b in ab:
  s = max(s,a,b)
dp = [[0 for i in range(2*s+2)] for j in range(2*s+2)]
for a,b in ab:
  dp[s+1-a][s+1-b] += 1
for i in range(1,2*s+2):
  for j in range(1,2*s+2):
    dp[i][j] = (dp[i][j]+dp[i-1][j]+dp[i][j-1])%mod
x = 0
for a,b in ab:
  x = (x+dp[s+1+a][s+1+b])%mod
t = 0
for a,b in ab:
  t = (t+cmb(2*a+2*b,2*a))%mod
ans = (x-t)*pow(2,mod-2,mod)%mod
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
mod = int(1e+9) + 7
def extgcd(a, b):
  if b == 0:
    return 1, 0
  else:
    x, y, u, v, k, l = 1, 0, 0, 1, a, b
    while l != 0:
      x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
      k, l = l, k % l
    return x, y
def inved(x):
  a, b = extgcd(x, mod)
  return a % mod

fact = [1 for i in range(8001)]
finv = [0 for i in range(8001)]
for i in range(8000):
  fact[i+1] = (fact[i] * (i + 1)) % mod
finv[8000] = inved(fact[8000])
for i in range(8000, 0, -1):
  finv[i-1] = (finv[i] * i) % mod
Y = 0
for i in range(N):
  Y += (fact[2*(A[i][0]+A[i][1])]*finv[2*A[i][0]]*finv[2*A[i][1]])%mod
  Y %= mod
B = [[] for i in range(4001)]
for i in A:
  B[i[0]+i[1]].append(2000-i[0])
f = np.zeros(2000+2000+1,np.int64)
for b in B[::-1]:
  f[1:] += f[:-1].copy()
  np.add.at(f,b,1)
  f %= mod
X = (f * f[::-1] % mod).sum() % mod

print(((X-Y) * inved(2))%mod)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
m = map(int,read().split())
AB = zip(m,m)

D = 2000

U = 10 ** 4
fact = [1] * U
for n in range(1,U):
    fact[n] = fact[n-1] * n % MOD
fact_inv = [1] * U
fact_inv[-1] = pow(fact[-1],MOD-2,MOD)
for n in range(U-1,0,-1):
    fact_inv[n-1] = fact_inv[n] * n % MOD

C_to_A = [[] for _ in range(D+D+1)]
Y = 0
for a,b in AB:
    c = a+b
    C_to_A[c].append(D-a)
    Y += fact[c+c] * fact_inv[a+a] * fact_inv[b+b]
Y %= MOD

f = np.zeros(D+D+1,np.int64)
for A in C_to_A[::-1]:
    f[1:] += f[:-1].copy()
    np.add.at(f,A,1)
    f %= MOD
X = (f * f[::-1] % MOD).sum() % MOD

answer = (X - Y) * fact_inv[2] % MOD
print(answer)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
m = map(int,read().split())
AB = zip(m,m)

D = 2000

U = 10 ** 4
fact = [1] * U
for n in range(1,U):
    fact[n] = fact[n-1] * n % MOD
fact_inv = [1] * U
fact_inv[-1] = pow(fact[-1],MOD-2,MOD)
for n in range(U-1,0,-1):
    fact_inv[n-1] = fact_inv[n] * n % MOD

C_to_A = [[] for _ in range(D+D+1)]
remove = 0
for a,b in AB:
    c = a+b
    C_to_A[c].append(D-a)
    remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b]

dp = np.zeros(D+D+1,np.int64)
for A in C_to_A[::-1]:
    dp[1:] += dp[:-1].copy()
    np.add.at(dp,A,1)
    dp %= MOD

x = (dp * dp[::-1] % MOD).sum() % MOD
x -= remove % MOD
x *= fact_inv[2]
x %= MOD

print(x)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
m = map(int,read().split())
AB = zip(m,m)

D = 2000

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

fact,fact_inv = make_fact(10 ** 4,MOD)
fact = fact.tolist()
fact_inv = fact_inv.tolist()

C_to_A = [[] for _ in range(D+D+1)]
remove = 0
for a,b in AB:
    c = a+b
    C_to_A[c].append(D-a)
    remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b]
remove %= MOD

dp = np.zeros(D+D+1,np.int64)
for A in C_to_A[::-1]:
    dp[:0:-1] += dp[-2::-1]
    np.add.at(dp,A,1)
    dp %= MOD

x = (dp * dp[::-1] % MOD).sum() % MOD
x -= remove
if x&1:
    x += MOD
x //= 2
x %= MOD

print(x)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
m = map(int,read().split())
AB = zip(m,m)

D = 2000

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

fact,fact_inv = make_fact(10 ** 4,MOD)
fact = fact.tolist()
fact_inv = fact_inv.tolist()

C_to_A = [[] for _ in range(D+D+1)]
remove = 0
for a,b in AB:
    c = a+b
    C_to_A[c].append(D-a)
    remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b]
remove %= MOD

dp = np.zeros(D+D+1,np.int64)
for A in C_to_A[::-1]:
    dp[1:] += dp[:-1].copy()
    np.add.at(dp,A,1)
    dp %= MOD

x = (dp * dp[::-1] % MOD).sum() % MOD
x -= remove
if x&1:
    x += MOD
x //= 2
x %= MOD

print(x)

Submission status: Accepted

Solution code:
from collections import defaultdict
def solve():
	Base = 2000
	MAX = Base*2
	p = 10**9+7
	F = [1]; Finv = [0]*(MAX*2+1)
	for i in xrange(MAX*2): F.append(F[i]*(i+1)%p)
	Finv[MAX] = pow(F[MAX],p-2,p)
	for i in xrange(MAX,0,-1): Finv[i-1] = Finv[i]*i%p
	N = int(raw_input())
	dup = A_MAX = B_MAX = 0
	dp = [[0]*(MAX+2) for i in xrange(MAX+2)]
	goals = defaultdict(int)
	for i in xrange(N):
		A,B = map(int,raw_input().split())
		dup = (dup + F[A*2+B*2]*Finv[A*2]*Finv[B*2])%p
		if A > A_MAX: A_MAX = A
		if B > B_MAX: B_MAX = B
		goals[(Base+A,Base+B)] += 1
		dp[Base-B][Base-A] += 1
	for j in xrange(Base-B_MAX,Base+B_MAX+1):
		for i in xrange(Base-A_MAX,Base+A_MAX+1):
			dp[j+1][i] = (dp[j+1][i] + dp[j][i]) % p
			dp[j][i+1] = (dp[j][i+1] + dp[j][i]) % p
	ans = 0
	for (i,j),v in goals.iteritems():
		ans = (ans + dp[j][i]*v) % p
	print ((ans - dup)*pow(2,p-2,p)+p) % p
solve()

Submission status: Runtime Error

Solution code:
import math

n = int(input())
list = []

for i in range(n):
	list.append(input().split())

sum = 0

for j in range(n):
	for k in range(j+1,n):
		if j!=k:
			num = math.factorial(int(list[j][0])+int(list[j][1])+int(list[k][0])+int(list[k][1])) / (math.factorial(int(list[j][0])+int(list[k][0]))*math.factorial(int(list[j][1])+int(list[k][1])))
			sum += num
print(int(sum%(10**9+7)))

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+50,M=4040,mod=1e9+7,L=2000;
int n,a[N],b[N],f[M][M],ans,J[N],I[N];
int C(int n,int m){return 1ll*J[n]*I[m]%mod*I[n-m]%mod;}
int main(){
	scanf("%d",&n);J[0]=I[0]=I[1]=1;
	for(int i=2;i<=4*L;i++)I[i]=mod-1ll*mod/i*I[mod%i]%mod;
	for(int i=1;i<=4*L;i++)J[i]=1ll*J[i-1]*i%mod,I[i]=1ll*I[i-1]*I[i]%mod;
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]);
	for(int i=1;i<=n;i++)f[L-a[i]][L-b[i]]++;
	for(int i=0;i<=2*L;i++)for(int j=0;j<=2*L;j++){
		if(i)(f[i][j]+=f[i-1][j])%=mod;
		if(j)(f[i][j]+=f[i][j-1])%=mod;
	}
	for(int i=1;i<=n;i++)(ans+=f[L+a[i]][L+b[i]]-C(2*(a[i]+b[i]),2*a[i]))%=mod;
	printf("%d\n",1ll*ans*I[2]%mod);
	return 0;
}

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
m = map(int,read().split())
AB = zip(m,m)

D = 2000

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

fact,fact_inv = make_fact(10 ** 4,MOD)
fact = fact.tolist()
fact_inv = fact_inv.tolist()

C_to_A = [[] for _ in range(D+D+1)]
remove = 0
for a,b in AB:
    c = a+b
    C_to_A[c].append(D-a)
    remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b]
remove %= MOD

dp = np.zeros(D+D+1,np.int64)
for A in C_to_A[::-1]:
    dp[:0:-1] += dp[-1::-1]
    np.add.at(dp,A,1)
    dp %= MOD

x = (dp * dp[::-1] % MOD).sum() % MOD
x -= remove
if x&1:
    x += MOD
x //= 2
x %= MOD

print(x)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
m = map(int,read().split())
AB = zip(m,m)

D = 2000

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

fact,fact_inv = make_fact(D+D+100,MOD)
fact = fact.tolist()
fact_inv = fact_inv.tolist()

C_to_A = [[] for _ in range(D+D+1)]
remove = 0
for a,b in AB:
    c = a+b
    C_to_A[c].append(D-a)
    remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b]
remove %= MOD

dp = np.zeros(D+D+1,np.int64)
for A in C_to_A[::-1]:
    dp[1:] += dp[:-1]
    np.add.at(dp,A,1)

x = (dp * dp[::-1] % MOD).sum() % MOD
x -= remove
if x&1:
    x += MOD
x //= 2
x %= MOD

print(x)

Submission status: Runtime Error

Solution code:
def co(a, b):
    a += b
    res = 1
    for i in range(1,b+1):
        res *= ((a-i+1) / i)
    return int(res)

n = int(input())

a = [0 for i in range(n)]
b = [0 for i in range(n)]

for ni in range(n):
    a[ni], b[ni] = (int(i) for i in input().split(" "))

a = tuple(a)
b = tuple(b)

res = 0
for i in range(n):
    for j in range(i+1,n):
        res += co(a[i]+a[j], b[i]+b[j])

res %= (10**9+7)
print(res)

Submission status: Runtime Error

Solution code:
def co(a, b):
    a += b
    res = 1
    for i in range(1,b+1):
        res *= ((a-i+1) / i)
    return int(res)

n = int(input())

a = [0 for i in range(n)]
b = [0 for i in range(n)]

for ni in range(n):
    a[ni], b[ni] = (int(i) for i in input().split(" "))

res = 0
for i in range(n):
    for j in range(i+1,n):
        res += co(a[i]+a[j], b[i]+b[j])

res %= 10**9+7
print(res)

Submission status: Runtime Error

Solution code:
def co(a, b):
    res = 1
    for i in range(1,b+1):
        res *= ((a-i+1) / i)
    return int(res)

n = int(input())

a = [0 for i in range(n)]
b = [0 for i in range(n)]

for ni in range(n):
    a[ni], b[ni] = (int(i) for i in input().split(" "))

res = 0
for i in range(n):
    for j in range(i+1,n):
        res += co(a[i]+a[j]+b[i]+b[j], b[i]+b[j])

print(res % (10**9+7))

Submission status: Runtime Error

Solution code:
# your code goes here
from itertools import combinations
from scipy.misc import comb

N = int(input())
A = []
B = []
for n in range(N):
	a, b = [int(x) for x in input().split()]
	A.append(a)
	B.append(b)
 
S = 0
for n1, n2 in combinations(range(N),2):
	a1, b1 = A[n1], B[n1]
	a2, b2 = A[n2], B[n2]
	s = comb(a1+b1+a2+b2, a1+a2, exact=True)
	S += s % (1e+9 + 7)
S %= 1e+9+7
print(int(S))

Submission status: Runtime Error

Solution code:
# your code goes here
from itertools import combinations
from scipy.special import comb
# a = comb(n, r)
# a = comb(n, r, exact=True)

N = int(input())
A = []
B = []
for n in range(N):
	a, b = [int(x) for x in input().split()]
	A.append(a)
	B.append(b)
 
S = 0
for n1, n2 in combinations(range(N),2):
	a1, b1 = A[n1], B[n1]
	a2, b2 = A[n2], B[n2]
	s = comb(a1+b1+a2+b2, a1+a2, exact=True)
	S += s % (1e+9 + 7)
S %= 1e+9+7
print(int(S))

Submission status: Runtime Error

Solution code:
def fact(n):
  ret = 1
  for i in range(2, n+1):
    ret *= i
  return ret

def C(a,b,c):
  ret = 1
  for i in range(b+1, a + 1):
    ret *= i
  return int(ret / fact(c))

n = int(input())

gu = []

for i in range(n):
  gu.append(list(map(int, input().split(' '))))

ret = 0

for i in range(n - 1):
  for j in range(i+1, n):
    ret += C(gu[i][0] + gu[i][1] + gu[j][0] + gu[j][1], gu[i][0] + gu[j][0], gu[i][1] + gu[j][1])

print(ret)

Submission status: Runtime Error

Solution code:
def fact(n):
    ret = 1
    for i in range(2, n+1):
        ret *= i
    return ret

def C(a,b,c):
    ret = 1
    for i in range(b+1, a + 1):
        ret *= i
    return int(ret / fact(c))

n = int(input())

gu = []

for i in range(n):
    gu.append(list(map(int, input().split(' '))))

ret = 0

for i in range(n - 1):
    for j in range(i+1, n):
        ret += C(gu[i][0] + gu[i][1] + gu[j][0] + gu[j][1], gu[i][0] + gu[j][0], gu[i][1] + gu[j][1])

print(ret)

Submission status: Runtime Error

Solution code:
def fact(n):
    ret = 1
    for i in range(2, n+1):
        ret *= i
    return ret

n = int(input())

gu = []

for i in range(n):
    gu.append(list(map(int, input().split(' '))))

ret = 0

for i in range(n - 1):
    for j in range(i+1, n):
        ret += int(fact(gu[i][0] + gu[i][1] + gu[j][0] + gu[j][1]) / fact(gu[i][0] + gu[j][0]) / fact(gu[i][1] + gu[j][1]))

print(ret)

Submission status: Runtime Error

Solution code:
def fact(n):
    if n == 1:
        return 1
    else:
        return fact(n - 1) * n

n = int(input())

gu = []

for i in range(n):
    gu.append(list(map(int, input().split(' '))))

ret = 0

for i in range(n - 1):
    for j in range(i+1, n):
        ret += int(fact(gu[i][0] + gu[i][1] + gu[j][0] + gu[j][1]) / fact(gu[i][0] + gu[j][0]) / fact(gu[i][1] + gu[j][1]))

print(ret)

Submission status: Runtime Error

Solution code:
import scipy.misc as scm
def combi(p,q):
    return scm.comb(p,q,1)

ans=0
n=int(input())
k=[]
for i in range(n):
    a,b=map(int,input().split())
    k.append([a,b])

for i in range(n-1):
    for j in range(1,n):
        p=k[i][0]+k[i][1]+k[j][0]+k[j][1]
        q=k[i][0]+k[j][0]
        ans += combi(p,q) % (10**9+7)

print(ans)

Submission status: Runtime Error

Solution code:

def calc(ab1,ab2):
    meat = ab1[0] + ab2[0]
    vege = ab1[1] + ab2[1]
    pattern = fact_list[meat+vege] / (fact_list[meat] * fact_list[vege])
    return pattern


if __name__ == '__main__':
    N = int(input())
    AB = [list(map(int, input().split())) for i in range(N)]

    fact_list = {}
    fact_list[0] = 1
    max_ab = max(AB[x][0] + AB[x][1] for x in range(N))
    for i in range(1,2*max_ab):
        fact_list[i] = fact_list[i-1] * i

    sum_count = 0
    for i in range(N):
        for j in range(i+1,N):
            sum_count += calc(AB[i],AB[j])

    print( int(sum_count % (10**9 + 7)) )

Submission status: Runtime Error

Solution code:

def calc(ab1,ab2,fact_list):
    meat = ab1[0] + ab2[0]
    vege = ab1[1] + ab2[1]
    pattern = fact_list[meat+vege] / (fact_list[meat] * fact_list[vege])
    return pattern


if __name__ == '__main__':
    N = int(input())
    AB = [list(map(int, input().split())) for i in range(N)]

    fact_list = {}
    fact_list[0] = 1
    max_ab = max(AB[x][0] + AB[x][1] for x in range(N))
    for i in range(1,2*max_ab):
        fact_list[i] = fact_list[i-1] * i

    sum_count = 0
    for i in range(N):
        for j in range(i+1,N):
            sum_count += calc(AB[i],AB[j],fact_list)

    print( int(sum_count % (10**9 + 7)) )