AtCoder Beginner Contest 154 - Many Many Paths

Snuke is standing on a two-dimensional plane. In one operation, he can move by 1 in the positive x-direction, or move by 1 in the positive y-direction.
Let us define a function f(r, c) as follows:
 - f(r,c) :=  (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above)
Given are integers r_1, r_2, c_1, and c_2.
Find the sum of f(i, j) over all pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute this value modulo (10^9+7).

-----Constraints-----
 - 1 ≤ r_1 ≤ r_2 ≤ 10^6
 - 1 ≤ c_1 ≤ c_2 ≤ 10^6
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
r_1 c_1 r_2 c_2

-----Output-----
Print the sum of f(i, j) modulo (10^9+7).

-----Sample Input-----
1 1 2 2

-----Sample Output-----
14

For example, there are two paths from the point (0, 0) to the point (1, 1): (0,0) → (0,1) → (1,1) and (0,0) → (1,0) → (1,1), so f(1,1)=2.
Similarly, f(1,2)=3, f(2,1)=3, and f(2,2)=6. Thus, the sum is 14.

Difficulty: MEDIUM_HARD

Starter code:

Solutions:
MOD = 1000000007

def fact(x):
	k = 1
	for i in range(x + 1):
		if i != 0:
			k = k * i % MOD
	return k

def inverse(b):
	r = 1
	e = MOD - 2
	while e:
		if e % 2 == 1:
			r = r * b % MOD
		b = b * b % MOD
		e >>= 1
	return r

def Comb(i, j):
	if i == 0 or j == 0:
		return 0
	num = fact(i + j)
	num *= inverse(fact(i))
	num %= MOD
	num *= inverse(fact(j))
	num %= MOD
	return num
(r1, c1, r2, c2) = map(int, input().split())
Ans = 0
Ans += Comb(r2 + 1, c2 + 1)
Ans -= Comb(r1, c2 + 1)
Ans -= Comb(r2 + 1, c1)
Ans += Comb(r1, c1)
Ans += MOD
Ans += MOD
Ans %= MOD
print(Ans)


def main():
	M = 10 ** 9 + 7
	(a, b, c, d) = map(int, input().split())
	n = c + d + 2
	fac = [0] * (n + 1)
	fac[0] = lt = 1
	for i in range(1, n + 1):
		fac[i] = lt = lt * i % M
	inv = lambda n: pow(fac[n], M - 2, M)
	f = lambda r, c: fac[r + c + 2] * inv(c + 1) * inv(r + 1) - c - r - 2
	print((f(c, d) - f(c, b - 1) - f(a - 1, d) + f(a - 1, b - 1)) % M)
main()


import sys
sys.setrecursionlimit(10 ** 7)

def main():
	(r1, c1, r2, c2) = map(int, input().split())
	mod = pow(10, 9) + 7

	def cmb(n, r, mod):
		if r < 0 or r > n:
			return 0
		r = min(r, n - r)
		return g1[n] * g2[r] * g2[n - r] % mod
	g1 = [1, 1]
	g2 = [1, 1]
	inverse = [0, 1]
	for i in range(2, r2 + c2 + 3):
		g1.append(g1[-1] * i % mod)
		inverse.append(-inverse[mod % i] * (mod // i) % mod)
		g2.append(g2[-1] * inverse[-1] % mod)
	ans = 0
	for r in range(r1, r2 + 1):
		ans += cmb(r + c2 + 1, r + 1, mod) - cmb(r + c1, r + 1, mod)
		ans %= mod
	print(ans)
main()


def comb(n, r, p):
	(x, y) = (1, 1)
	for i in range(n, n - r, -1):
		x *= i
		y *= i + r - n
		x %= p
		y %= p
	return pow(y, p - 2, p) * x % p
(r1, c1, r2, c2) = map(int, input().split())
mod = pow(10, 9) + 7
(s1, s2) = (c1 + r1, c1 + r2 + 1)
(t1, t2) = (min(c1 + 1, r1 - 1), min(c1 + 1, r2))
comb1 = comb(s1, t1, mod)
comb2 = comb(s2, t2, mod)
(u1, u2) = (s1 - r1 + 1, s2 - r2)
ans = comb2 - comb1
for i in range(1, c2 - c1 + 1):
	comb1 = comb1 * (s1 + i) * pow(u1 + i, mod - 2, mod)
	comb1 %= mod
	comb2 = comb2 * (s2 + i) * pow(u2 + i, mod - 2, mod)
	comb2 %= mod
	ans += comb2
	ans -= comb1
	ans %= mod
print(ans)


import sys
input = sys.stdin.readline

def main():
	U = 2 * 10 ** 6 + 2
	MOD = 10 ** 9 + 7
	fact = [1] * (U + 1)
	fact_inv = [1] * (U + 1)
	for i in range(1, U + 1):
		fact[i] = fact[i - 1] * i % MOD
	fact_inv[U] = pow(fact[U], MOD - 2, MOD)
	for i in range(U, 0, -1):
		fact_inv[i - 1] = fact_inv[i] * i % MOD

	def comb(n, k):
		if k < 0 or k > n:
			return 0
		z = fact[n]
		z *= fact_inv[k]
		z *= fact_inv[n - k]
		z %= MOD
		return z
	ans = 0
	(r1, c1, r2, c2) = map(int, input().split())
	for i in range(c1, c2 + 1):
		ans += comb(i + r2 + 1, i + 1) - comb(i + r1, i + 1)
	print(ans % MOD)

def __starting_point():
	main()
__starting_point()


class Factorial:

	def __init__(self, n, mod):
		self.f = [1]
		self.mod = mod
		for i in range(1, n + 1):
			self.f.append(self.f[-1] * i % mod)
		self.i = [pow(self.f[-1], mod - 2, mod)]
		for i in range(1, n + 1)[::-1]:
			self.i.append(self.i[-1] * i % mod)
		self.i.reverse()

	def factorial(self, i):
		return self.f[i]

	def ifactorial(self, i):
		return self.i[i]

	def comb(self, n, k):
		return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0
M = 10 ** 9 + 7
(a, b, c, d) = map(int, input().split())
comb = Factorial(c + d + 2, M).comb
f = lambda r, c: comb(c + r + 2, r + 1) - c - r - 2
print((f(c, d) - f(c, b - 1) - f(a - 1, d) + f(a - 1, b - 1)) % M)


from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

def rsa(sep=''):
	if sep == '':
		return input().split()
	else:
		return input().split(sep)

def rip(sep=''):
	if sep == '':
		return list(map(int, input().split()))
	else:
		return list(map(int, input().split(sep)))

def ria(sep=''):
	return list(rip(sep))

def ri():
	return int(input())

def rd():
	return float(input())

def rs():
	return input()

def inv(v, mod):
	return pow(v, mod - 2, mod)

def main():
	(r1, c1, r2, c2) = rip()
	MM = int(2000000.0 + 10)
	fact = [0] * MM
	finv = [0] * MM
	fact[0] = 1
	finv[0] = 1
	mod = int(1000000000.0) + 7
	for i in range(1, MM):
		fact[i] = fact[i - 1] * i % mod
	finv[MM - 1] = inv(fact[MM - 1], mod)
	for i in reversed(list(range(1, MM - 1))):
		finv[i] = finv[i + 1] * (i + 1) % mod

	def sum_naive(r, c):
		ret = 0
		for i in range(r):
			ret += fact[i + 1 + c - 1] * finv[i + 1] * finv[c - 1] % mod
		return ret

	def sum(r, c):
		ret = fact[r + c] * finv[r] * finv[c] % mod
		ret += -1 + mod
		ret %= mod
		return ret
	ans = 0
	ans += sum(r2 + 1, c2 + 1)
	ans -= sum(r2 + 1, c1)
	ans -= sum(r1, c2 + 1)
	ans += sum(r1, c1)
	ans %= mod
	print(ans)

def __starting_point():
	main()
__starting_point()


(r1, c1, r2, c2) = list(map(int, input().split()))
mod = 10 ** 9 + 7

def comb(n, k, mod):
	if n < k:
		return 0
	if n - k < k:
		k = n - k
	c = 1
	for x in range(n - k + 1, n + 1):
		c = c * x % mod
	d = 1
	for x in range(1, k + 1):
		d = d * x % mod
	c = c * pow(d, mod - 2, mod)
	return c % mod

def f(i, j):
	return comb(i + j, i, mod)
ans = f(r2 + 1, c2 + 1) - f(r2 + 1, c1) - f(r1, c2 + 1) + f(r1, c1)
ans %= mod
print(ans)


(r1, c1, r2, c2) = map(int, input().split())
n = [1] * (r2 + c2 + 3)
mod = 10 ** 9 + 7
for i in range(r2 + c2 + 2):
	n[i + 1] = n[i] * ((i + 1) % mod) % mod

def calc(r, c):
	x = n[r + c] % mod
	y = n[r] * n[c] % mod
	return x * (pow(y, mod - 2, mod) % mod) % mod
ans = calc(r2 + 1, c2 + 1) - calc(r2 + 1, c1) - calc(r1, c2 + 1) + calc(r1, c1)
ans %= mod
print(ans)


(r1, c1, r2, c2) = map(int, input().split())
MOD = 10 ** 9 + 7

def factorial(n, mod=10 ** 9 + 7):
	a = 1
	for i in range(1, n + 1):
		a = a * i % mod
	return a

def power(n, r, mod=10 ** 9 + 7):
	if r == 0:
		return 1
	if r % 2 == 0:
		return power(n * n % mod, r // 2, mod) % mod
	if r % 2 == 1:
		return n * power(n, r - 1, mod) % mod

def comb(n, k, mod=10 ** 9 + 7):
	if n < k or k < 0:
		result = 0
	else:
		a = factorial(n, mod=mod)
		b = factorial(k, mod=mod)
		c = factorial(n - k, mod=mod)
		result = a * power(b, mod - 2, mod=mod) * power(c, mod - 2, mod=mod) % mod
	return result

def g(r, c):
	return comb(c + r + 2, r + 1) - 1
ans = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)
ans %= MOD
print(ans)


(r1, c1, r2, c2) = map(int, input().split())
MOD = 10 ** 9 + 7
MAXN = r2 + c2 + 5
fac = [1, 1] + [0] * MAXN
for i in range(2, MAXN + 2):
	fac[i] = fac[i - 1] * i % MOD

def inv(n):
	return pow(n, MOD - 2, MOD)

def comb(n, r):
	if n < r:
		return 0
	if n < 0 or r < 0:
		return 0
	return fac[n] * inv(fac[r]) * inv(fac[n - r]) % MOD
(r2, c2) = (r2 + 1, c2 + 1)
ans = comb(r2 + c2, r2) - comb(r2 + c1, r2) - comb(r1 + c2, r1) + comb(r1 + c1, r1)
ans %= MOD
print(ans)


(r1, c1, r2, c2) = map(int, input().split())
n = r2 + c2 + 3
mod = 10 ** 9 + 7
f = [1 for _ in range(n)]
f_inv = [1 for _ in range(n)]
for i in range(1, n):
	f[i] = f[i - 1] * i % mod
	f_inv[i] = pow(f[i], mod - 2, mod)

def comb(n, k):
	return f[n] * f_inv[k] * f_inv[n - k] % mod

def g(r, c):
	return comb(r + c + 2, c + 1) - 1
ans = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)
ans %= mod
print(ans)


def mod_inverse(n, mod=10 ** 9 + 7):
	return pow(n, mod - 2, mod)

def combination(n, k, mod=10 ** 9 + 7):
	numer = denom = 1
	for i in range(k):
		numer = numer * (n - i) % mod
		denom = denom * (i + 1) % mod
	return numer * mod_inverse(denom, mod) % mod
mod = 10 ** 9 + 7
(r1, c1, r2, c2) = list(map(int, input().split()))
ans = combination(r1 + c1, r1) - combination(1 + r2 + c1, 1 + r2) - combination(1 + r1 + c2, r1) + combination(2 + r2 + c2, 1 + r2)
print(ans % mod)


MOD = 10 ** 9 + 7
fac = [1, 1]

def prepare(n, mod):
	for i in range(2, n + 1):
		fac.append(fac[-1] * i % mod)

def modcmb(n, r, mod):
	if n < 0 or r < 0 or r > n:
		return 0
	return fac[n] * pow(fac[r], mod - 2, mod) * pow(fac[n - r], mod - 2, mod) % mod

def f(r, c):
	return modcmb(r + c, r, MOD)

def g(x, y):
	return ((y + 2) * modcmb(x + y + 2, x, MOD) - (x + 1)) * pow(x + 1, MOD - 2, MOD)

def main():
	prepare(2 * 10 ** 6 + 10, MOD)
	(r1, c1, r2, c2) = map(int, input().split())
	ans = g(r2, c2) - g(r1 - 1, c2) - g(r2, c1 - 1) + g(r1 - 1, c1 - 1)
	ans %= MOD
	print(ans)
main()


import sys
input = sys.stdin.buffer.readline

def main():
	(a, b, p, d) = map(int, input().split())
	MOD = 10 ** 9 + 7
	N = p + d + 5
	fac = [0 for _ in range(N + 1)]
	(fac[0], fac[1]) = (1, 1)
	for i in range(2, N + 1):
		fac[i] = fac[i - 1] * i % MOD

	def comb(x, y):
		return fac[x + y] * pow(fac[x], MOD - 2, MOD) * pow(fac[y], MOD - 2, MOD) % MOD
	print((comb(p + 1, d + 1) - comb(p + 1, b) - comb(d + 1, a) + comb(a, b)) % MOD)
main()


(r1, c1, r2, c2) = list(map(int, input().split()))
mod = 10 ** 9 + 7
MAX_N = 3 * 10 ** 6
fact = [1]
fact_inv = [0] * (MAX_N + 4)
for i in range(MAX_N + 3):
	fact.append(fact[-1] * (i + 1) % mod)
fact_inv[-1] = pow(fact[-1], mod - 2, mod)
for i in range(MAX_N + 2, -1, -1):
	fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod

def comb(n, k, mod=mod):
	if n < k:
		return 0
	return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod
ans = comb(c1 + r1, r1) - comb(c1 + r2 + 1, r2 + 1) - comb(c2 + r1 + 1, r1) + comb(c2 + r2 + 2, r2 + 1)
ans %= mod
print(ans)


(r1, c1, r2, c2) = map(int, input().split())

def cmb(n, r, mod):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % mod
mod = 10 ** 9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
N = r2 + c2 + 3
mod = 10 ** 9 + 7
for i in range(2, N + 1):
	fact.append(fact[-1] * i % mod)
	inv.append(-inv[mod % i] * (mod // i) % mod)
	factinv.append(factinv[-1] * inv[-1] % mod)
a = cmb(r2 + c2 + 2, r2 + 1, mod)
b = cmb(r1 + c2 + 1, r1, mod)
c = cmb(r2 + c1 + 1, c1, mod)
d = cmb(r1 + c1, r1, mod)
ans = a - b - c + d
print(ans % mod)


mod = 10 ** 9 + 7

def comb(n, r):
	if n < r:
		return 0
	if n < 0 or r < 0:
		return 0
	return fa[n] * fi[r] % mod * fi[n - r] % mod
(r1, c1, r2, c2) = map(int, input().split())
fa = [1] * (r2 + c2 + 3)
fi = [1] * (r2 + c2 + 3)
for i in range(1, r2 + c2 + 3):
	fa[i] = fa[i - 1] * i % mod
	fi[i] = pow(fa[i], mod - 2, mod)

def ans(r, c):
	return fa[r + c + 2] * fi[r + 1] * fi[c + 1] % mod - 1
print((ans(r2, c2) - ans(r2, c1 - 1) - ans(r1 - 1, c2) + ans(r1 - 1, c1 - 1)) % mod)


MOD = 10 ** 9 + 7

def nCr(n, r, mod=MOD):
	r = min(r, n - r)
	numer = denom = 1
	for i in range(1, r + 1):
		numer = numer * (n + 1 - i) % mod
		denom = denom * i % mod
	return numer * pow(denom, mod - 2, mod) % mod

def g(r, c):
	return nCr(r + c + 2, r + 1) - 1
(r1, c1, r2, c2) = list(map(int, input().split()))
r1 -= 1
c1 -= 1
ans = g(r2, c2)
ans -= g(r1, c2)
ans -= g(r2, c1)
ans += g(r1, c1)
ans += MOD * 2
ans %= MOD
print(ans)


mod = 10 ** 9 + 7

def cmb(n, k):
	return fac[n] * inv_fac[n - k] * inv_fac[k] % mod

def g(r, c):
	x = 0
	for i in range(1, r + 2):
		x += cmb(c + i, i)
	x %= mod
	return x
(r1, c1, r2, c2) = map(int, input().split())
N = r2 + c2 + 1
fac = [1]
for i in range(1, N + 1):
	fac.append(fac[-1] * i % mod)
inv_fac = [pow(fac[N], mod - 2, mod)]
for i in range(1, N + 1)[::-1]:
	inv_fac.append(inv_fac[-1] * i % mod)
inv_fac = inv_fac[::-1]
print((g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % mod)


nn = 2002002
P = 10 ** 9 + 7
fa = [1] + [0] * nn
for i in range(nn):
	fa[i + 1] = fa[i] * (i + 1) % P
f = lambda a, b: fa[a + b + 2] * pow(fa[a + 1] * fa[b + 1], P - 2, P) % P - 1
(r1, c1, r2, c2) = map(int, input().split())
print((f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)) % P)


M = 10 ** 9 + 7
(r1, c1, r2, c2) = map(int, input().split())
n = r2 + c2 + 2
fac = [0] * (n + 1)
fac[0] = val = 1
for i in range(1, n + 1):
	fac[i] = val = val * i % M
pr1 = pow(fac[r1], M - 2, M)
pc1 = pow(fac[c1], M - 2, M)
pr2 = pow(fac[r2 + 1], M - 2, M)
pc2 = pow(fac[c2 + 1], M - 2, M)
a = fac[r2 + c2 + 2] * pr2 * pc2
a -= fac[r2 + c1 + 1] * pr2 * pc1
a -= fac[r1 + c2 + 1] * pr1 * pc2
a += fac[r1 + c1] * pr1 * pc1
print(a % M)


MOD = 10 ** 9 + 7
FACT_MAX = 2 * 10 ** 6 + 3
fact = [1] * FACT_MAX
for i in range(1, FACT_MAX):
	fact[i] = fact[i - 1] * i % MOD

def comb(n, r):
	return fact[n] * pow(fact[n - r], MOD - 2, MOD) * pow(fact[r], MOD - 2, MOD)

def g(r, c):
	return (comb(r + c + 2, c + 1) - 1) % MOD
(r1, c1, r2, c2) = list(map(int, input().split()))
print((g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % MOD)


def solve():
	(r1, c1, r2, c2) = map(int, input().split())
	MOD = 10 ** 9 + 7
	n = r2 + c2 + 2
	fac = [1] * (n + 1)
	rev = [1] * (n + 1)
	for i in range(1, n + 1):
		fac[i] = i * fac[i - 1] % MOD
		rev[i] = pow(fac[i], MOD - 2, MOD)
	comb = lambda a, b: fac[a] * rev[a - b] * rev[b] % MOD

	def f(r, c):
		return comb(r + c + 2, c + 1)
	ans = f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)
	ans %= MOD
	print(ans)
solve()


class Combination:

	def __init__(self, N, MOD=10 ** 9 + 7):
		self.MOD = MOD
		(self.fact, self.inv) = self._make_factorial_list(N)

	def __call__(self, n, k):
		if k < 0 or k > n:
			return 0
		res = self.fact[n] * self.inv[k] % self.MOD
		res = res * self.inv[n - k] % self.MOD
		return res

	def _make_factorial_list(self, N):
		fact = [1] * (N + 1)
		inv = [1] * (N + 1)
		MOD = self.MOD
		for i in range(1, N + 1):
			fact[i] = fact[i - 1] * i % MOD
		inv[N] = pow(fact[N], MOD - 2, MOD)
		for i in range(N, 0, -1):
			inv[i - 1] = inv[i] * i % MOD
		return (fact, inv)

def __starting_point():
	(r1, c1, r2, c2) = list(map(int, input().split()))
	mod = 10 ** 9 + 7
	comb = Combination(2 * 10 ** 6 + 10, mod)

	def f(r, c):
		return comb(r + c + 2, r + 1)
	CD = (f(r2, c2) - f(r2, c1 - 1) + mod) % mod
	C = (f(r1 - 1, c2) - f(r1 - 1, c1 - 1) + mod) % mod
	ans = (CD - C + mod) % mod
	print(ans)
__starting_point()


def combination(n, r, mod=10 ** 9 + 7):
	(n1, r) = (n + 1, min(r, n - r))
	numer = denom = 1
	for i in range(1, r + 1):
		numer = numer * (n1 - i) % mod
		denom = denom * i % mod
	return numer * pow(denom, mod - 2, mod) % mod
mod = 10 ** 9 + 7
(r1, c1, r2, c2) = list(map(int, input().split()))
r2 += 1
c2 += 1
a1 = combination(r1 + c1, r1)
a2 = combination(r2 + c2, r2)
a3 = combination(r1 + c2, r1)
a4 = combination(r2 + c1, r2)
print((a1 + a2 - a3 - a4) % mod)


def main():
	(r1, c1, r2, c2) = map(int, input().split())
	mod = 10 ** 9 + 7
	fact = [1, 1]
	finv = [1, 1]
	inv = [0, 1]
	for i in range(2, r2 + c2 + 3):
		fact.append(fact[-1] * i % mod)
		inv.append(inv[mod % i] * (mod - mod // i) % mod)
		finv.append(finv[-1] * inv[-1] % mod)

	def nCr(n, r, mod):
		return fact[n] * finv[r] * finv[n - r] % mod
	print((nCr(r2 + c2 + 2, r2 + 1, mod) + nCr(r1 + c1, r1, mod) - nCr(c2 + r1 + 1, r1, mod) - nCr(r2 + c1 + 1, c1, mod)) % mod)
main()


mod = 10 ** 9 + 7
f = [1] * (2 * 10 ** 6 + 5)
f[0] = 1
for i in range(1, 2 * 10 ** 6 + 4):
	f[i] = f[i - 1] * i % mod

def inv(i):
	return pow(f[i], mod - 2, mod)

def g(x, y):
	return f[x + y] * inv(x) * inv(y) % mod
(r1, c1, r2, c2) = map(int, input().split(' '))
ans = g(r2 + 1, c2 + 1) - g(r2 + 1, c1) - g(r1, c2 + 1) + g(r1, c1)
print(ans % mod)


(r1, c1, r2, c2) = list(map(int, input().split()))
mod = int(1000000000.0 + 7)

def cmb(n, r, mod=mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % mod

def init_cmb(Nmax):
	g1 = [1, 1]
	g2 = [1, 1]
	inverse = [0, 1]
	for i in range(2, Nmax + 1):
		g1.append(g1[-1] * i % mod)
		inverse.append(-inverse[mod % i] * (mod // i) % mod)
		g2.append(g2[-1] * inverse[-1] % mod)
	return (g1, g2)
(g1, g2) = init_cmb(max(r1, r2) + max(c1, c2) + 10)

def solve(r1, c1, r2, c2):

	def f(r, c):
		return cmb(r + c, min(r, c))
	res = 0
	(r2, c2) = (r2, c2)
	res += f(r2, c2)
	res -= f(r2, c1)
	res -= f(r1, c2)
	res += f(r1, c1)
	return res % mod

def solve2(r1, c1, r2, c2):
	res = 0
	for r in range(r1, r2 + 1):
		for c in range(c1, c2 + 1):
			res += cmb(c + r, c)
			res %= mod
	return res
print(solve(r1, c1, r2 + 1, c2 + 1))


(r1, c1, r2, c2) = map(int, input().split())
M = r2 + c2 + 10
mod = 10 ** 9 + 7
f = [1] * M
p = 1
for i in range(1, M):
	p = p * i % mod
	f[i] = p
finv = [1] * M
p = finv[-1] = pow(f[-1], mod - 2, mod)
for i in range(M - 2, 0, -1):
	p = p * (i + 1) % mod
	finv[i] = p
g = [0] * M
p = 0
for i in range(1, M):
	g[i] = p = ((p + 1) * 2 - 1) % mod

def comb(n, k):
	return f[n] * finv[n - k] * finv[k] % mod

def count(R, C):
	ret = g[R + C + 1] % mod
	for c in range(C):
		x1 = comb(R + c, c)
		x2 = g[C - c]
		ret = (ret - x1 * x2) % mod
	for r in range(R):
		x1 = comb(C + r, r)
		x2 = g[R - r]
		ret = (ret - x1 * x2) % mod
	return ret
ans = count(r2, c2) + count(r1 - 1, c1 - 1) - count(r2, c1 - 1) - count(r1 - 1, c2)
ans %= mod
print(ans)


(r1, c1, r2, c2) = map(int, input().split())
mod = 10 ** 9 + 7
n = [1] * (r2 + c2 + 3)
for i in range(r2 + c2 + 2):
	n[i + 1] = n[i] * (i + 1) % mod

def g(a, b):
	(x, y, z) = (n[a + b], n[a], n[b])
	return x * pow(y, mod - 2, mod) % mod * pow(z, mod - 2, mod) % mod
print((g(r2 + 1, c2 + 1) - g(r2 + 1, c1) - g(r1, c2 + 1) + g(r1, c1)) % mod)


(r1, c1, r2, c2) = map(int, input().split())
n = 2 * max(r1, r2, c1, c2) + 2
mod = 10 ** 9 + 7
factorial = [1]
for i in range(1, n + 1):
	factorial.append(factorial[-1] * i % mod)
inv_factorial = [-1] * (n + 1)
inv_factorial[-1] = pow(factorial[-1], mod - 2, mod)
for i in reversed(range(n)):
	inv_factorial[i] = inv_factorial[i + 1] * (i + 1) % mod

def fact(n):
	return factorial[n]

def nck(n, k):
	if k > n or k < 0:
		return 0
	else:
		return factorial[n] * inv_factorial[n - k] * inv_factorial[k]

def routes(r, c):
	return nck(r + c + 2, c + 1) - 1
ans = routes(r2, c2) - routes(r2, c1 - 1) - routes(c2, r1 - 1) + routes(r1 - 1, c1 - 1)
ans %= mod
print(ans)


import copy

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)

def func(r, c):
	return f[r + 1 + c + 1] * i[r + 1] % MOD * i[c + 1] % MOD
MOD = 10 ** 9 + 7
(f, i) = prepare(2 * 10 ** 6 + 2, MOD)
(r1, c1, r2, c2) = map(int, input().split())
combi = func(r2, c2) - func(r2, c1 - 1) - func(r1 - 1, c2) + func(r1 - 1, c1 - 1)
print(combi % MOD)


def g(r, c):
	return (fact[r + c + 2] * fact_inv[r + 1] * fact_inv[c + 1] - 1) % mod
(r1, c1, r2, c2) = list(map(int, input().split()))
mod = 10 ** 9 + 7
MAX = 10 ** 6
fact = [1] * (2 * MAX + 10)
for i in range(1, 2 * MAX + 10):
	fact[i] = fact[i - 1] * i % mod
inv = [1] * (MAX + 10)
for i in range(2, MAX + 10):
	inv[i] = inv[mod % i] * (mod - mod // i) % mod
fact_inv = [1] * (MAX + 10)
for i in range(1, MAX + 10):
	fact_inv[i] = fact_inv[i - 1] * inv[i] % mod
ans = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)
ans %= mod
print(ans)


(r1, c1, r2, c2) = map(int, input().split())
mod = 10 ** 9 + 7
fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, r2 + c2 + 5):
	fac.append(fac[i - 1] * i % mod)
	inv.append(mod - inv[mod % i] * (mod // i) % mod)
	finv.append(finv[i - 1] * inv[i] % mod)

def nck(n, k):
	if n < k:
		return 0
	if n < 0 or k < 0:
		return 0
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod

def comb_sum(i, j):
	return nck(i + j + 2, i + 1)
print((comb_sum(c2, r2) - comb_sum(c2, r1 - 1) - comb_sum(c1 - 1, r2) + comb_sum(c1 - 1, r1 - 1)) % mod)


import sys
MOD = 10 ** 9 + 7

def make_table(size=2 * 10 ** 6 + 2, p=MOD):
	fac = [None] * (size + 1)
	fac[0] = 1
	for i in range(size):
		fac[i + 1] = fac[i] * (i + 1) % p
	ifac = [None] * (size + 1)
	ifac[size] = pow(fac[size], p - 2, p)
	for i in range(size, 0, -1):
		ifac[i - 1] = ifac[i] * i % p
	return (fac, ifac)
(fac, ifac) = make_table()

def comb(n, r, mod=MOD):
	if r > n or r < 0:
		return 0
	return fac[n] * ifac[r] % mod * ifac[n - r] % mod

def g(y, x):
	return comb(y + x + 2, y + 1) - 1
(r1, c1, r2, c2) = map(int, sys.stdin.readline().split())

def main():
	ans = (g(r2, c2) - (g(r1 - 1, c2) + g(r2, c1 - 1) - g(r1 - 1, c1 - 1))) % MOD
	return ans

def __starting_point():
	ans = main()
	print(ans)
__starting_point()


(r1, c1, r2, c2) = map(int, input().split())
MOD = 10 ** 9 + 7
ans = 0

class Factorial:

	def __init__(self, n, mod):
		self.f = [1]
		self.mod = mod
		for j in range(1, n + 1):
			self.f.append(self.f[-1] * j % mod)
		self.i = [pow(self.f[-1], mod - 2, mod)]
		for j in range(n, 0, -1):
			self.i.append(self.i[-1] * j % mod)
		self.i.reverse()

	def factorial(self, j):
		return self.f[j]

	def ifactorial(self, j):
		return self.i[j]

	def comb(self, n, k):
		return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0
F = Factorial(r2 + c2 + 3, MOD)
ans = F.comb(c1 + r1, c1) - F.comb(c1 + r2 + 1, c1) - F.comb(c2 + r1 + 1, c2 + 1) + F.comb(c2 + r2 + 2, c2 + 1)
print(ans % MOD)


mod = 10 ** 9 + 7

def chs(a, b):
	a += 1
	b += 1
	a += b
	res = 1
	for i in range(a, a - b, -1):
		res *= i
		res %= mod
	for i in range(1, b + 1):
		res *= rev[i]
		res %= mod
	return res
(r1, c1, r2, c2) = map(int, input().split())
r1 -= 1
c1 -= 1
if c2 > r2:
	(r2, c2) = (c2, r2)
	(r1, c1) = (c1, r1)
rev = [pow(i, mod - 2, mod) for i in range(c2 + 5)]
ans = chs(r2, c2) - chs(r1, c2) - chs(r2, c1) + chs(r1, c1)
ans %= mod
print(ans)


Q = 10 ** 9 + 7

def getInv(N):
	inv = [0] * (N + 1)
	inv[0] = 1
	inv[1] = 1
	for i in range(2, N + 1):
		inv[i] = -(Q // i) * inv[Q % i] % Q
	return inv

def getFactorialInv(N):
	inv = [0] * (N + 1)
	inv[0] = 1
	inv[1] = 1
	ret = [1] * (N + 1)
	for i in range(2, N + 1):
		inv[i] = -(Q // i) * inv[Q % i] % Q
		ret[i] = ret[i - 1] * inv[i] % Q
	return ret

def getFactorial(N):
	ret = [1] * (N + 1)
	for i in range(2, N + 1):
		ret[i] = ret[i - 1] * i % Q
	return ret

def main():
	(r1, c1, r2, c2) = list(map(int, input().split()))
	F = getFactorial(2 * 10 ** 6 + 2)
	I = getFactorialInv(10 ** 6 + 1)

	def G(a, b):
		return F[a + b + 2] * I[a + 1] % Q * I[b + 1] % Q
	print((G(r2, c2) - G(r2, c1 - 1) - G(r1 - 1, c2) + G(r1 - 1, c1 - 1)) % Q)

def __starting_point():
	main()
__starting_point()


(r1, c1, r2, c2) = map(int, input().split())
MOD = 10 ** 9 + 7
N = r2 + c2 + 10
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
	fact[i] = fact[i - 1] * i % MOD
invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)
for i in range(N - 2, -1, -1):
	invfact[i] = invfact[i + 1] * (i + 1) % MOD

def nCk(n, k):
	if k < 0 or n < k:
		return 0
	else:
		return fact[n] * invfact[k] * invfact[n - k] % MOD
ans = nCk(r2 + c2 + 2, r2 + 1) - nCk(r2 + c1 + 1, r2 + 1) - nCk(r1 + c2 + 1, c2 + 1) + nCk(r1 + c1, r1)
print(ans % MOD)


import sys
read = sys.stdin.read
mod = 10 ** 9 + 7
(r1, c1, r2, c2) = map(int, read().split())

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)
(fac, finv) = prepare(2 * 10 ** 6 + 10, mod)

def comb(n, k, mod=mod, fac=fac, finv=finv):
	if n < k:
		return 0
	if n < 0 or k < 0:
		return 0
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod
answer = comb(r2 + c2 + 2, r2 + 1) - comb(r1 + c2 + 1, r1) - comb(c1 + r2 + 1, c1) + comb(r1 + c1, r1)
answer %= mod
print(answer)


import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)
(r1, c1, r2, c2) = list(map(int, input().split()))

def cumprod(arr, MOD):
	L = len(arr)
	Lsq = int(L ** 0.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)
MOD = 10 ** 9 + 7
U = 10 ** 6 * 2 + 10
(fact, fact_inv) = make_fact(U, MOD)

def mod_comb_k(n, k, mod):
	return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod

def calc_rc(r, c):
	a = mod_comb_k(r + c + 2, r + 1, MOD)
	b = 1
	return a - b
ans = calc_rc(r2, c2) + calc_rc(r1 - 1, c1 - 1) - calc_rc(r1 - 1, c2) - calc_rc(r2, c1 - 1)
ans %= MOD
print(ans)


(r, c, R, C) = [int(_) for _ in input().split()]
mod = 10 ** 9 + 7
f = [1] * (2 * 10 ** 6 + 10)
for i in range(1, 2 * 10 ** 6 + 10):
	f[i] = i * f[i - 1] % mod

def comb(x, y):
	return f[x] * pow(f[y], mod - 2, mod) * pow(f[x - y], mod - 2, mod)
print((comb(C + R + 2, R + 1) - comb(c + R + 1, R + 1) - comb(C + r + 1, r) + comb(c + r, r)) % mod)


def main():
	M = 10 ** 9 + 7
	(r1, c1, r2, c2) = map(int, input().split())
	n = r2 + c2 + 2
	fac = [1]
	val = 1
	append = fac.append
	for i in range(1, n + 1):
		val = val * i % M
		append(val)
	f = lambda r, c: fac[r + c + 2] * pow(fac[c + 1], M - 2, M) * pow(fac[r + 1], M - 2, M) - c - r - 2
	print((f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)) % M)
main()


def mod_combination(n, k, mod=10 ** 9 + 7):

	def extended_gcd(a, b):
		if b == 0:
			return (a, 1, 0)
		(d, x, y) = extended_gcd(b, a % b)
		return (d, y, x - a // b * y)
	(p, q) = (1, 1)
	for i in range(n - k + 1, n + 1):
		p = p * i % mod
	for i in range(2, k + 1):
		q = q * i % mod
	return p * (extended_gcd(q, mod)[1] % mod) % mod
mod = 10 ** 9 + 7
(r1, c1, r2, c2) = map(int, input().split())

def f(i, j):
	return mod_combination(i + j, i)
print((f(r2 + 1, c2 + 1) - f(r2 + 1, c1) - f(r1, c2 + 1) + f(r1, c1)) % mod)


import sys
import socket
hostname = socket.gethostname()
if hostname == 'F451C':
	sys.stdin = open('f1.in')

def read_int_list():
	return list(map(int, input().split()))

def read_str_list():
	return input().split()

def read_int():
	return int(input())

def read_str():
	return input()
M = 10 ** 9 + 7
f = [1] * (2 * 10 ** 6 + 4)
for i in range(1, 2 * 10 ** 6 + 3):
	f[i] = f[i - 1] * i
	f[i] %= M

def g(r, s):
	res = 1
	frs = f[r + s + 2]
	fs = f[s + 1]
	fr = f[r + 1]
	res *= pow(fr, M - 2, M)
	res *= pow(fs, M - 2, M)
	res *= frs
	res %= M
	return res

def main():
	(r1, c1, r2, c2) = read_int_list()
	res = 0
	res += g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)
	res %= M
	print(res)
main()


(r1, c1, r2, c2) = map(int, input().split())
mod = 10 ** 9 + 7

def p_mod(m, n, p):
	a = 1
	for i in range(n):
		a = a * (m - i) % p
	return a

def c_mod(m, n, p):
	return p_mod(m, n, p) * pow(p_mod(n, n, p), p - 2, p) % p
print((c_mod(r2 + c2 + 2, r2 + 1, mod) - c_mod(r1 + c2 + 1, r1, mod) - c_mod(r2 + c1 + 1, c1, mod) + c_mod(r1 + c1, r1, mod)) % mod)


(r1, c1, r2, c2) = map(int, input().split())
MOD = 10 ** 9 + 7
idx = r2 + c2 + 3
perm = [1] * (idx + 1)
for i in range(1, idx + 1):
	perm[i] = perm[i - 1] * i
	perm[i] %= MOD

def inv_mod(a):
	return pow(a, MOD - 2, MOD)

def comb(n, m, p=10 ** 9 + 7):
	if n < m:
		return 0
	if n < 0 or m < 0:
		return 0
	m = min(m, n - m)
	top = bot = 1
	for i in range(m):
		top = top * (n - i) % p
		bot = bot * (i + 1) % p
	bot = pow(bot, p - 2, p)
	return top * bot % p

def g(i, j):
	return comb(i + j + 2, i + 1, MOD)

def s(n, m):
	return comb(n + m + 2, m + 1, MOD)
res = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)
res %= MOD
ans = s(r2, c2) - s(r2, c1 - 1) - s(r1 - 1, c2) + s(r1 - 1, c1 - 1)
ans %= MOD
print(res)


def paths(r, c):
	return facts[r + c] * ifacts[r] * ifacts[c]
mod = 10 ** 9 + 7
(r1, c1, r2, c2) = map(int, input().split())
facts = [1] * (r2 + c2 + 10)
ifacts = [1] * (r2 + c2 + 10)
for i in range(1, r2 + c2 + 10):
	facts[i] = facts[i - 1] * i % mod
	ifacts[i] = pow(facts[i], mod - 2, mod)
ans = 0
for i in range(r1 + 1, r2 + 2):
	ans += paths(i, c2) - paths(i, c1 - 1)
	ans %= mod
print(ans)


import sys
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
import math
from itertools import combinations, product

def run():
	(r1, c1, r2, c2) = map(int, read().split())
	mod = 10 ** 9 + 7

	def generate_inv(n, mod):
		ret = [0, 1]
		for i in range(2, n + 1):
			next = -ret[mod % i] * (mod // i)
			next %= mod
			ret.append(next)
		return ret
	inv = generate_inv(10 ** 6 + 1, mod)

	def calc(i, j):
		ret = 0
		agg = 1
		for k in range(1, i + 2):
			agg *= (j + k) % mod
			agg *= inv[k]
			agg %= mod
			ret += agg
		return ret
	ret = 0
	ret += calc(r2, c2)
	ret -= calc(r2, c1 - 1)
	ret -= calc(r1 - 1, c2)
	ret += calc(r1 - 1, c1 - 1)
	ret %= mod
	print(ret)

def __starting_point():
	run()
__starting_point()


(r1, c1, r2, c2) = map(int, input().split())
a = r2 - r1 + 1
b = c2 - c1 + 1
m = max(a, b)
n = min(a, b)
mod = 10 ** 9 + 7

def framod(n, mod, a=1):
	for i in range(1, n + 1):
		a = a * i % mod
	return a

def comb(n, k, mod):
	a = framod(n, mod)
	b = framod(k, mod)
	c = framod(n - k, mod)
	return a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod) % mod

def f(x, y):
	return comb(x + y + 2, y + 1, mod) - 1
print((f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)) % mod)


(r1, c1, r2, c2) = map(int, input().split())
mod = 10 ** 9 + 7
fac = [1]
inv = [1]
for i in range(1, r2 + c2 + 10):
	fac.append(fac[-1] * i % mod)
	inv.append(pow(fac[-1], mod - 2, mod))

def comb(n, r):
	return fac[n] * inv[n - r] % mod * inv[r] % mod

def g(x, y):
	return comb(x + y, y)
ret = g(r2 + 1, c2 + 1) - g(r2 + 1, c1) - g(r1, c2 + 1) + g(r1, c1)
ret %= mod
print(ret)


MOD = 10 ** 9 + 7
list_size = 2000003
f_list = [1] * list_size
f_r_list = [1] * list_size
for i in range(list_size - 1):
	f_list[i + 1] = int(f_list[i] * (i + 2) % MOD)
f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)
for i in range(2, list_size + 1):
	f_r_list[-i] = int(f_r_list[-i + 1] * (list_size + 2 - i) % MOD)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return f_list[n - 1] * f_r_list[n - r - 1] % MOD * f_r_list[r - 1] % MOD

def f(x, y):
	if x * y == 0:
		return 0
	elif x == 1:
		return y * (y + 3) // 2
	else:
		return comb(x + y + 2, x + 1) - x - y - 2
(r1, c1, r2, c2) = list(map(int, input().split()))
ans = (f(r2, c2) + f(r1 - 1, c1 - 1) - f(r1 - 1, c2) - f(r2, c1 - 1)) % MOD
print(ans)


(r1, c1, r2, c2) = map(int, input().split())
MOD = 10 ** 9 + 7
MAX = r2 + c2 + 10
fact = [1] * (MAX + 1)
finv = [1] * (MAX + 1)
iinv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
	fact[i] = fact[i - 1] * i % MOD
	iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
	finv[i] = finv[i - 1] * iinv[i] % MOD

def comb(n: int, k: int) -> int:
	if n < k or n < 0 or k < 0:
		return 0
	return fact[n] * finv[k] % MOD * finv[n - k] % MOD

def func(a, b):
	res = 0
	for i in range(a + 1):
		res += comb(i + b + 1, i + 1)
		res %= MOD
	return res
ans = func(r2, c2) - func(r2, c1 - 1) - func(r1 - 1, c2) + func(r1 - 1, c1 - 1)
ans %= MOD
print(ans)


MOD = 10 ** 9 + 7
(r1, c1, r2, c2) = list(map(int, input().split()))
size = 1010000 * 2
f_list = [1] * size
for i in range(1, size):
	f_list[i] = f_list[i - 1] * i % MOD

def func(r, c):
	return f_list[r + c] * pow(f_list[r], MOD - 2, MOD) * pow(f_list[c], MOD - 2, MOD)
ans = func(r2 + 1, c2 + 1) - 1
ans += func(r1, c1) - 1
ans -= func(r2 + 1, c1) - 1
ans -= func(r1, c2 + 1) - 1
print(ans % MOD)


from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 999999999
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)

def modinv2(x, r):
	return pow(x, r - 2, r)

def f(r, c):
	d = c
	prod = 1
	div = 1
	divacc = 1
	for i in range(r - 1):
		prod = prod * d % R
		divacc = divacc * div % R
		d += 1
		div += 1
	ret = prod * modinv2(divacc, R) % R
	return ret
(r1, c1, r2, c2) = inm()
r1 += 1
c1 += 1
r2 += 1
c2 += 1
print((f(r2 + 1, c2 + 1) - f(r2 + 1, c1) - f(r1, c2 + 1) + f(r1, c1)) % R)


def f_many_many_paths():

	class Combination(object):
		__slots__ = ['mod', 'factorial', 'inverse']

		def __init__(self, max_val_arg: int=10 ** 6, mod: int=10 ** 9 + 7):
			(fac, inv) = ([1], [])
			(fac_append, inv_append) = (fac.append, inv.append)
			for i in range(1, max_val_arg + 1):
				fac_append(fac[-1] * i % mod)
			inv_append(pow(fac[-1], mod - 2, mod))
			for i in range(max_val_arg, 0, -1):
				inv_append(inv[-1] * i % mod)
			(self.mod, self.factorial, self.inverse) = (mod, fac, inv[::-1])

		def combination(self, n, r):
			if n < 0 or r < 0 or n < r:
				return 0
			return self.factorial[n] * self.inverse[r] * self.inverse[n - r] % self.mod
	(R1, C1, R2, C2) = [int(i) for i in input().split()]
	comb = Combination(R2 + C2 + 2).combination

	def g(r, c):
		return comb(r + c + 2, r + 1) - 1
	return (g(R2, C2) - g(R1 - 1, C2) - g(R2, C1 - 1) + g(R1 - 1, C1 - 1)) % (10 ** 9 + 7)
print(f_many_many_paths())


import sys
input = sys.stdin.buffer.readline

def main():
	(a, b, c, d) = map(int, input().split())
	MOD = 10 ** 9 + 7
	N = c + d + 5
	fac = [0 for _ in range(N + 1)]
	(fac[0], fac[1]) = (1, 1)
	for i in range(2, N + 1):
		fac[i] = fac[i - 1] * i % MOD

	def comb(g, h):
		return fac[g + h] * pow(fac[g], MOD - 2, MOD) * pow(fac[h], MOD - 2, MOD) % MOD
	print((comb(c + 1, d + 1) - comb(c + 1, b) - comb(d + 1, a) + comb(a, b)) % MOD)
main()


(a1, b1, a2, b2) = map(int, input().split())
import sys
sys.setrecursionlimit(2000000000)
p = 10 ** 9 + 7
N = a2 + b2 + 2
R = max(a2 + 1, b2 + 1)
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
	fact.append(fact[-1] * i % p)
for i in range(2, R + 1):
	inv.append(-inv[p % i] * (p // i) % p)
	factinv.append(factinv[-1] * inv[-1] % p)

def comb(n, r, p):
	if r < 0 or n < r:
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p
score = comb(a2 + b2 + 2, a2 + 1, p) - comb(a2 + b1 + 1, a2 + 1, p) - comb(a1 + b2 + 1, a1, p) + comb(a1 + b1, a1, p)
print(score % (10 ** 9 + 7))


def main():
	mod = 10 ** 9 + 7
	N = 2 * 10 ** 6 + 3
	fac = [0] * N
	finv = [0] * N
	inv = [0] * N
	fac[0] = fac[1] = 1
	finv[0] = finv[1] = 1
	inv[1] = 1
	for i in range(2, N):
		fac[i] = fac[i - 1] * i % mod
	finv[N // 2] = pow(fac[N // 2], mod - 2, mod)
	for i in reversed(list(range(N // 2))):
		finv[i] = finv[i + 1] * (i + 1) % mod

	def com(r, c):
		ans = fac[r + c] * finv[r] * finv[c]
		return ans % mod

	def g(r, c):
		return (com(r + 1, c + 1) - 1) % mod
	(r1, c1, r2, c2) = list(map(int, input().split()))
	answer = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)
	answer %= mod
	print(answer)

def __starting_point():
	main()
__starting_point()


(r1, c1, r2, c2) = list(map(int, input().split()))
MOD = 10 ** 9 + 7
r = r2 + 1
l = r1
ans = 0
for i in range(0, c2):
	gyaku = pow(i + 2, MOD - 2, MOD)
	r *= r2 + 1 + (i + 1)
	r *= gyaku
	l *= r1 + (i + 1)
	l *= gyaku
	r %= MOD
	l %= MOD
	if i >= c1 - 1:
		ans += r
		ans -= l
	ans %= MOD
print(ans % MOD)


def modfac(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)

def modnCr(n, r, mod, fac, inv):
	return fac[n] * inv[n - r] * inv[r] % mod
(r1, c1, r2, c2) = map(int, input().split())
mod = 10 ** 9 + 7
(fac, inv) = modfac(r2 + c2 + 1, mod)
ans = 0
for r in range(r1, r2 + 1):
	ans += modnCr(r + c2 + 1, c2, mod, fac, inv) - modnCr(r + c1, c1 - 1, mod, fac, inv)
	ans %= mod
print(ans)


def main():
	mod = 1000000007
	(r1, c1, r2, c2) = map(int, input().split())
	Fact = [1]
	n = r2 + c2 + 1
	for i in range(1, n + 1):
		Fact.append(Fact[i - 1] * i % mod)
	Finv = [0] * (n + 1)
	Finv[-1] = pow(Fact[-1], mod - 2, mod)
	for i in range(n - 1, -1, -1):
		Finv[i] = Finv[i + 1] * (i + 1) % mod

	def comb(n, r):
		if n < r:
			return 0
		return Fact[n] * Finv[r] * Finv[n - r] % mod

	def f(r, c):
		ret = 0
		for i in range(r + 1):
			ret += comb(c + i + 1, c)
			ret %= mod
		return ret
	print((f(r2, c2) - f(r2, c1 - 1) - f(c2, r1 - 1) + f(r1 - 1, c1 - 1)) % mod)
main()


MOD = 10 ** 9 + 7
MOD_t_MAX = 2 * 10 ** 6 + 10
fac = [None] * MOD_t_MAX
finv = [None] * MOD_t_MAX
inv = [None] * MOD_t_MAX

def MOD_COM_init():
	fac[0] = fac[1] = 1
	finv[0] = finv[1] = 1
	inv[1] = 1
	for i in range(2, MOD_t_MAX):
		fac[i] = fac[i - 1] * i % MOD
		inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD

def MOD_COM(n, k):
	if n < k:
		return 0
	if n < 0 or k < 0:
		return 0
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

def main():
	(r1, c1, r2, c2) = map(int, input().split())
	MOD_COM_init()
	a = MOD_COM(r2 + 1 + c2 + 1, r2 + 1) - 1
	b = MOD_COM(r2 + 1 + c1, c1) - 1
	c = MOD_COM(r1 + c2 + 1, r1) - 1
	d = MOD_COM(r1 + c1, c1) - 1
	ans = a - (b + c) + d
	print(ans % MOD)

def __starting_point():
	main()
__starting_point()


mod = 10 ** 9 + 7

def inv(x):
	return pow(x, mod - 2, mod)
(r1, c1, r2, c2) = map(int, input().split())
(fact, inv_fact) = ([1, 1], [1, 1])
for i in range(2, r2 + c2 + 3):
	fact.append(fact[-1] * i % mod)
	inv_fact.append(inv(fact[-1]))

def nCr(n, r):
	return fact[n] * inv_fact[r] * inv_fact[n - r] % mod

def path_sum_sum(r, c):
	return ((r + 2) * nCr(c + r + 2, r + 2) % mod + mod - c - 1) * inv(c + 1) % mod
ans = path_sum_sum(r2, c2) + mod - path_sum_sum(r2, c1 - 1) + mod - path_sum_sum(r1 - 1, c2) + path_sum_sum(r1 - 1, c1 - 1)
print(ans % mod)


(r1, c1, r2, c2) = list(map(int, input().split()))
MOD = 10 ** 9 + 7

def modInverse(x, p):
	return pow(x, p - 2, p)

def nCr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * modInverse(den, p) % p

def hockey(n, m):
	return nCr(n + m + 1, m, MOD)
tot1 = hockey(c2, r2 + 1) - hockey(c2, r1)
tot2 = hockey(c1 - 1, r2 + 1) - hockey(c1 - 1, r1)
print((tot1 - tot2) % MOD)


(r1, c1, r2, c2) = map(int, input().split())
L = 10 ** 9 + 7

def get_euclidian(A, B):
	if B == 1:
		return 1
	else:
		return int((1 - A * get_euclidian(B, A % B)) / B)
F = [1]
for i in range(1, r2 + c2 + 3):
	F.append(F[i - 1] * i % L)

def get_combi(n, r):
	Euc = get_euclidian(L, F[r] * F[n - r] % L)
	return F[n] * Euc % L
combi1 = get_combi(r2 + c2 + 2, r2 + 1)
combi2 = get_combi(r2 + c1 + 1, c1)
combi3 = get_combi(r1 + c2 + 1, r1)
combi4 = get_combi(r1 + c1, r1)
print((int(combi1 - combi2 - combi3 + combi4) + L) % L)


import sys
TEST_INPUT = ['\n    1 1 2 2\n    ', '\n    314 159 2653 589\n    ']
ANSWER = ['14', '602215194']

class InputHandler:

	def __init__(self, text_lines='', is_test=False):
		self.data = list(text_lines.split('\n'))
		self.index = 0
		self.is_test = is_test

	def input(self):
		if self.is_test:
			self.index += 1
			return self.data[self.index].strip()
		else:
			return sys.stdin.readline().rstrip()
LARGE = 10 ** 9 + 7

def solve(r1, c1, r2, c2):
	fact = [0] * (r2 + c2 + 3)
	fact[0] = 1
	for i in range(1, r2 + c2 + 3):
		fact[i] = fact[i - 1] * i % LARGE
	fact_inv = [0] * (r2 + c2 + 3)
	fact_inv[-1] = pow(fact[-1], LARGE - 2, LARGE)
	for i in range(r2 + c2 + 1, -1, -1):
		fact_inv[i] = fact_inv[i + 1] * (i + 1) % LARGE

	def solve_special(r, c):
		return (fact[r + c + 2] * fact_inv[r + 1] * fact_inv[c + 1] - 1) % LARGE
	res = solve_special(r2, c2) - solve_special(r1 - 1, c2) - solve_special(r2, c1 - 1) + solve_special(r1 - 1, c1 - 1)
	return res % LARGE

def input_and_solve(ih):
	(r1, c1, r2, c2) = list(map(int, ih.input().split()))
	res = solve(r1, c1, r2, c2)
	return res

def main():
	ih = InputHandler()
	res = input_and_solve(ih)
	print(res)

def test():
	for (test_input, ans) in zip(TEST_INPUT, ANSWER):
		ih = InputHandler(test_input, True)
		res = input_and_solve(ih)
		assert str(res) == str(ans)

def __starting_point():
	main()
__starting_point()


k = 72
K = 1 << k
nu = lambda L: int(''.join([bin(K + a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + '0'
li = lambda s, l: [int(a, 2) if len(a) else 0 for a in [s[-(i + 1) * k - 1:-i * k - 1] for i in range(l)]]

def grow(d, v, h):
	h += [0] * d
	f = [(-1 if (i + d) % 2 else 1) * fainv[i] * fainv[d - i] % P * h[i] % P for i in range(d + 1)]
	for (idx, a) in enumerate([d + 1, d * fa[v - 1] * fainv[v] % P, (d * fa[v - 1] * fainv[v] + d + 1) % P]):
		t = [1] * (2 * d + 2)
		for i in range(1, 2 * d + 2):
			t[i] = t[i - 1] * (a - d + i - 1) % P
		ti = [1] * (2 * d + 2)
		ti[-1] = pow(t[-1], P - 2, P)
		for i in range(1, 2 * d + 2)[::-1]:
			ti[i - 1] = ti[i] * (a - d + i - 1) % P
		g = [ti[i + 1] * t[i] % P for i in range(2 * d + 1)]
		fg = li(st(nu(f) * nu(g)), d * 2 + 2)
		if idx == 1:
			for i in range(d + 1):
				h[i] = h[i] * (fg[d + i] * t[d + i + 1] % P * ti[i] % P) % P
		elif idx == 0:
			for i in range(d):
				h[i + d + 1] = fg[d + i] * t[d + i + 1] % P * ti[i] % P
		elif idx == 2:
			for i in range(d):
				h[i + d + 1] = h[i + d + 1] * (fg[d + i] * t[d + i + 1] % P * ti[i] % P) % P
	return h

def create_table(v):
	s = 1
	X = [1, v + 1]
	while s < v:
		X = grow(s, v, X)
		s *= 2
	table = [1]
	for x in X:
		table.append(table[-1] * x % P)
	return table

def fact(i, table):
	a = table[i // v]
	for j in range(i // v * v + 1, i + 1):
		a = a * j % P
	return a
P = 10 ** 9 + 7
v = 1 << 11
fa = [1] * (2 * v + 2)
fainv = [1] * (2 * v + 2)
for i in range(2 * v + 1):
	fa[i + 1] = fa[i] * (i + 1) % P
fainv[-1] = pow(fa[-1], P - 2, P)
for i in range(2 * v + 1)[::-1]:
	fainv[i] = fainv[i + 1] * (i + 1) % P
T = create_table(v)
f = lambda a, b: fact(a + b + 2, T) * pow(fact(a + 1, T) * fact(b + 1, T), P - 2, P) % P
(r1, c1, r2, c2) = list(map(int, input().split()))
print((f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)) % P)


import sys
import numpy as np
sr = lambda : sys.stdin.readline().rstrip()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
MOD = 10 ** 9 + 7

def cmb(n, k):
	if k < 0 or k > n:
		return 0
	return fact[n] * fact_inv[k] % MOD * fact_inv[n - k] % MOD

def cumprod(arr, MOD):
	L = len(arr)
	Lsq = int(L ** 0.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)
U = 2 * 10 ** 6 + 3
(fact, fact_inv) = make_fact(U, MOD)
(r1, c1, r2, c2) = lr()
answer = cmb(r2 + c2 + 2, r2 + 1) - 1
answer -= cmb(r2 + c1 + 1, r2 + 1) - 1
answer -= cmb(r1 + c2 + 1, c2 + 1) - 1
answer += cmb(r1 + c1, r1) - 1
print(answer % MOD)


(r1, c1, r2, c2) = map(int, input().split())
p = 10 ** 9 + 7
size = 1010000 * 2
f_list = [1] * size
for i in range(1, size):
	f_list[i] = f_list[i - 1] * i % p

def cmb(n, r):
	return f_list[n + r] * pow(f_list[n], p - 2, p) * pow(f_list[r], p - 2, p) % p
hole = cmb(r2 + 1, c2 + 1) - 1
rect1 = cmb(r2 + 1, c1) - 1
rect2 = cmb(r1, c2 + 1) - 1
duplicate = cmb(r1, c1) - 1
ans = (hole - rect1 - rect2 + duplicate) % p
print(ans)


mod = 10 ** 9 + 7
(r1, c1, r2, c2) = map(int, input().split())
fact = [1] * (r2 + c2 + 3)
inv = [1] * (r2 + c2 + 3)
inv_fact = [1] * (r2 + c2 + 3)
for i in range(2, r2 + c2 + 3):
	fact[i] = fact[i - 1] * i % mod
	inv[i] = -inv[mod % i] * (mod // i) % mod
	inv_fact[i] = inv_fact[i - 1] * inv[i] % mod
total = fact[r2 + c2 + 2] * inv_fact[r2 + 1] * inv_fact[c2 + 1] % mod
total -= fact[r1 + c2 + 1] * inv_fact[r1] * inv_fact[c2 + 1] % mod
total -= fact[r2 + c1 + 1] * inv_fact[c1] * inv_fact[r2 + 1] % mod
total += fact[r1 + c1] * inv_fact[r1] * inv_fact[c1] % mod
print(total % mod)


def inpl():
	return list(map(int, input().split()))

def cmb(n, r):
	if n < r:
		return 0
	r = min(n - r, r)
	if r == 0:
		return 1
	return over[n] * under[r] * under[n - r] % MOD

def extGCD(x, y):
	r = [1, 0, x]
	w = [0, 1, y]
	while w[2] != 1:
		q = r[2] // w[2]
		w_tmp = [r[0] - q * w[0], r[1] - q * w[1], r[2] % w[2]]
		(r, w) = (w, w_tmp)
	return w[:2]

def mod_inv(a, m):
	(_, x) = extGCD(m, a)
	return (x + m) % m

def g(x, y):
	return (cmb(x + y + 2, x + 1) - 1 + MOD) % MOD
(r1, c1, r2, c2) = inpl()
MOD = 10 ** 9 + 7
over = [0 for i in range(r2 + c2 + 3)]
under = [0 for i in range(r2 + c2 + 3)]
over[0] = 1
for i in range(r2 + c2 + 2):
	over[i + 1] = over[i] * (i + 1) % MOD
under[r2 + c2 + 2] = mod_inv(over[r2 + c2 + 2], MOD)
for i in range(r2 + c2 + 1, 0, -1):
	under[i] = under[i + 1] * (i + 1) % MOD
print((g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % MOD)


class ModComb:

	def __init__(self, MAX, mod=10 ** 9 + 7):
		fac = [1, 1]
		finv = [1, 1]
		inv = [0, 1]
		for i in range(2, MAX):
			fac.append(fac[i - 1] * i % mod)
			inv.append(mod - inv[mod % i] * (mod // i) % mod)
			finv.append(finv[i - 1] * inv[i] % mod)
		(self.fac, self.finv, self.mod) = (fac, finv, mod)

	def nCk(self, n, k):
		if n < k or n < 0 or k < 0:
			return 0
		(fac, finv, mod) = (self.fac, self.finv, self.mod)
		return fac[n] * (finv[k] * finv[n - k] % mod) % mod
mod = 10 ** 9 + 7
(r1, c1, r2, c2) = map(int, input().split())
mc = ModComb(r2 + c2 + 10)

def f(i, j):
	return mc.nCk(i + j, i)
print((f(r2 + 1, c2 + 1) - f(r2 + 1, c1) - f(r1, c2 + 1) + f(r1, c1)) % mod)


from functools import reduce

def C(n, r):
	if not 0 <= r <= n:
		return 0
	r = min(r, n - r)
	N = reduce(lambda x, y: x * y % M, range(n, n - r, -1), 1)
	D = reduce(lambda x, y: x * y % M, range(1, r + 1), 1)
	return N * pow(D, M - 2, M) % M

def f(r, c):
	return C(r + c, c)
M = 10 ** 9 + 7
(a, b, c, d) = map(int, input().split())
print((f(c + 1, d + 1) - f(a, d + 1) - f(c + 1, b) + f(a, b)) % M)


(r1, c1, r2, c2) = map(int, input().split())
mod = 10 ** 9 + 7
m = r2 + c2 + 10
fac = [1] * m
ninv = [1] * m
finv = [1] * m
for i in range(2, m):
	fac[i] = fac[i - 1] * i % mod
	ninv[i] = -(mod // i) * ninv[mod % i] % mod
	finv[i] = finv[i - 1] * ninv[i] % mod

def comb(n, k):
	return fac[n] * finv[k] % mod * finv[n - k] % mod

def g(r, c):
	ret = 0
	for i in range(0, r + 1):
		ret += comb(i + c + 1, i + 1)
		ret %= mod
	return ret
ans = (g(r2, c2) - g(r1 - 1, c2) - g(r2, c1 - 1) + g(r1 - 1, c1 - 1)) % mod
print(ans)


(r1, c1, r2, c2) = map(int, input().split())
mod = int(1000000000.0) + 7

def inved(x):
	(a, b, c, d, k, l) = (1, 0, 0, 1, x, mod)
	while l != 0:
		(a, b, c, d) = (c, d, a - c * (k // l), b - d * (k // l))
		(k, l) = (l, k % l)
	return a % mod
frac = [1]
for i in range(r2 + c2 + 2):
	frac.append((i + 1) * frac[i] % mod)
fracr2c2 = frac[r2 + c2 + 2]
fracr1c2 = frac[r1 + c2 + 1]
fracr2c1 = frac[r2 + c1 + 1]
fracr1c1 = frac[r1 + c1]
fracr2 = frac[r2 + 1]
fracr1 = frac[r1]
fracc2 = frac[c2 + 1]
fracc1 = frac[c1]
g = 0
g += fracr2c2 * inved(fracr2) * inved(fracc2) % mod
g %= mod
g += fracr1c1 * inved(fracr1) * inved(fracc1) % mod
g %= mod
g -= fracr1c2 * inved(fracr1) * inved(fracc2) % mod
g %= mod
g -= fracr2c1 * inved(fracr2) * inved(fracc1) % mod
g %= mod
print(g)


(r1, c1, r2, c2) = map(int, input().split())

class Combination:

	def __init__(self, N: int, MOD: int):
		fac = [0 for _ in range(N + 1)]
		fac[0] = 1
		for i in range(1, N + 1):
			fac[i] = fac[i - 1] * i % MOD
		self.fac = fac
		self.N = N
		self.MOD = MOD

	def _modpow(self, x: int, n: int) -> int:
		ret = 1
		while n > 0:
			if n % 2 == 1:
				ret = ret * x % self.MOD
			x = x * x % self.MOD
			n >>= 1
		return ret

	def _modinv(self, x: int) -> int:
		return self._modpow(x, self.MOD - 2)

	def combination(self, n: int, k: int) -> int:
		if n < k:
			return 0
		return self.fac[n] * self._modinv(self.fac[k]) % self.MOD * self._modinv(self.fac[n - k]) % self.MOD
MOD = 1000000007
comb = Combination(2 * 1000000 + 10, MOD)
ans = (2 * MOD + comb.combination(r1 + c1, r1) - comb.combination(r1 + c2 + 1, r1) - comb.combination(r2 + c1 + 1, r2 + 1) + comb.combination(r2 + c2 + 2, r2 + 1)) % MOD
print(ans)


(r1, c1, r2, c2) = map(int, input().split())
MOD = 10 ** 9 + 7
idx = r2 + c2 + 2
perm = [1] * (idx + 1)
perm_inv = [1] * (idx + 1)
for i in range(1, idx + 1):
	perm[i] = perm[i - 1] * i
	perm[i] %= MOD

def inv_mod(a):
	return pow(a, MOD - 2, MOD)
perm_inv[-1] = inv_mod(perm[-1])
for i in range(idx - 1, -1, -1):
	perm_inv[i] = perm_inv[i + 1] * (i + 1)
	perm_inv[i] %= MOD

def comb(i, j):
	buf = perm[i + j + 2]
	buf *= perm_inv[i + 1]
	buf %= MOD
	buf *= perm_inv[j + 1]
	buf %= MOD
	return buf
res = comb(r2, c2)
res -= comb(r2, c1 - 1)
res -= comb(r1 - 1, c2)
res += comb(r1 - 1, c1 - 1)
print(res % MOD)


mod = 10 ** 9 + 7

def find_power(n, mod):
	powlist = [0] * (n + 1)
	powlist[0] = 1
	powlist[1] = 1
	for i in range(2, n + 1):
		powlist[i] = powlist[i - 1] * i % mod
	return powlist

def pow_cal(x, n, mod):
	if n == 0:
		return 1
	elif n == 1:
		return x % mod
	elif n >= 2:
		if n % 2 == 0:
			return pow_cal(x, n // 2, mod) ** 2 % mod
		else:
			return x * pow_cal(x, n // 2, mod) ** 2 % mod

def find_inv_power(n, mod):
	c = 1
	uselist = [0 for i in range(n + 1)]
	for i in range(1, n + 1):
		c *= i
		c %= mod
	first = pow_cal(c, mod - 2, mod)
	uselist[n] = first
	for i in range(n, 0, -1):
		uselist[i - 1] = uselist[i] * i % mod
	return uselist
A = find_power(2 * 10 ** 6 + 10, mod)
B = find_inv_power(2 * 10 ** 6 + 10, mod)

def combi(n, r, mod):
	if n < r:
		return 0
	elif n >= r:
		return A[n] * B[r] * B[n - r] % mod
(r1, c1, r2, c2) = list(map(int, input().split()))
mod = 10 ** 9 + 7
K = combi(r2 + c2 + 2, c2 + 1, mod) - combi(r2 + c1 + 1, c1, mod) - combi(r1 + c2 + 1, r1, mod) + combi(r1 + c1, c1, mod)
print(K % mod)


(a, b, c, d) = map(int, input().split())
m = 10 ** 9 + 7

def f(r, c):
	s = t = 1
	for i in range(c):
		s = s * (r + c - i) % m
		t = t * -~i % m
	return s * pow(t, m - 2, m)
print((f(a, b) - f(c + 1, b) - f(a, d + 1) + f(c + 1, d + 1)) % m)


def comb(n, m, p=10 ** 9 + 7):
	if n < m:
		return 0
	if n < 0 or m < 0:
		return 0
	m = min(m, n - m)
	top = bot = 1
	for i in range(m):
		top = top * (n - i) % p
		bot = bot * (i + 1) % p
	bot = pow(bot, p - 2, p)
	return top * bot % p

def s(n, m):
	return comb(n + m + 2, m + 1, mod)
mod = 10 ** 9 + 7
(r1, c1, r2, c2) = map(int, input().split())
ans = s(r2, c2) - s(r2, c1 - 1) - s(r1 - 1, c2) + s(r1 - 1, c1 - 1)
ans %= mod
print(ans)


(r1, c1, r2, c2) = list(map(int, input().split()))
mod = 1000000007

def inversion(a):
	b = mod
	(u, v) = (1, 0)
	while b >= 1:
		t = a // b
		a -= t * b
		(a, b) = (b, a)
		u -= t * v
		(u, v) = (v, u)
	u %= mod
	if u < 0:
		u += mod
	return u
fact = [0 for i in range(2000003)]
for i in range(2000003):
	if i <= 1:
		fact[i] = 1
	else:
		fact[i] = fact[i - 1] * i % mod

def combination(n, r):
	return fact[n] * inversion(fact[r]) % mod * inversion(fact[n - r]) % mod
answer = combination(r2 + c2 + 2, r2 + 1) - combination(r2 + c1 + 1, r2 + 1) - combination(r1 + c2 + 1, c2 + 1) + combination(r1 + c1, c1)
answer %= mod
if answer < 0:
	answer += mod
print(answer)


mod = 10 ** 9 + 7

def comb_mod(n, r, mod, invs):
	ans = 1
	for i in range(r):
		ans *= n - i
		ans %= mod
	ans *= invs[r]
	ans %= mod
	return ans
(A, B, C, D) = map(int, input().split())
invs = [1] * (C + 2)
for i in range(1, C + 2):
	invs[i] = invs[i - 1] * pow(i, mod - 2, mod)
	invs[i] %= mod
ans = comb_mod(C + D + 2, C + 1, mod, invs) - comb_mod(B + C + 1, B, mod, invs) - comb_mod(A + D + 1, A, mod, invs) + comb_mod(A + B, A, mod, invs)
print(ans % mod)


mod = 10 ** 9 + 7
rng = 2000100
fctr = [1] + [0] * (rng - 1)
for i in range(1, rng):
	fctr[i] = fctr[i - 1] * i % mod

def finv(x):
	return pow(fctr[x], 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
(x1, y1, x2, y2) = map(int, input().split())
print((cmb(x2 + y2 + 2, x2 + 1) - cmb(x2 + y1 + 1, y1) - cmb(x1 + y2 + 1, x1) + cmb(x1 + y1, x1)) % mod)


def getComb(n, k, MOD):
	if n < k:
		return 0
	if n - k < k:
		k = n - k
	comb = 1
	for x in range(n - k + 1, n + 1):
		comb = comb * x % MOD
	d = 1
	for x in range(1, k + 1):
		d = d * x % MOD
	comb *= pow(d, MOD - 2, MOD)
	return comb % MOD
(r1, c1, r2, c2) = map(int, input().split())
MOD = 10 ** 9 + 7
ans = 0
ans += getComb(r2 + c2 + 2, r2 + 1, MOD)
ans -= getComb(r2 + c1 + 1, r2 + 1, MOD)
ans -= getComb(r1 + c2 + 1, r1, MOD)
ans += getComb(r1 + c1, r1, MOD)
print(ans % MOD)


def prepare(n, mod):
	fac = [1]
	for i in range(1, n + 1):
		fac.append(fac[-1] * i % mod)
	rec = pow(fac[-1], mod - 2, mod)
	den = [1 for _ in range(n + 1)]
	den[n] = rec
	for i in range(n - 1, 0, -1):
		rec = rec * (i + 1) % mod
		den[i] = rec
	return (fac, den)

def comb_mod(n, r, mod, fac, den):
	return fac[n] * den[r] * den[n - r] % mod
(r1, c1, r2, c2) = map(int, input().split())
mod = 10 ** 9 + 7
(fac, den) = prepare(r2 + c2 + 2, mod)
ans = comb_mod(r2 + 1 + c2 + 1, c2 + 1, mod, fac, den)
ans -= comb_mod(r2 + 1 + c1, c1, mod, fac, den)
ans -= comb_mod(r1 + c2 + 1, c2 + 1, mod, fac, den)
ans += comb_mod(r1 + c1, c1, mod, fac, den)
print(ans % mod)


(r1, c1, r2, c2) = map(int, input().split())
mod = 1000000007

def pow(x, n):
	ret = 1
	while n > 0:
		if n & 1 == 1:
			ret = ret * x % mod
		x = x * x % mod
		n //= 2
	return ret

def fac(n):
	ret = 1
	for i in range(1, n + 1):
		ret = ret * i % mod
	return ret

def facinv(n):
	return pow(fac(n), mod - 2)

def cmb(n, k):
	if k < 0 or k > n:
		return 0
	return fac(n) * facinv(k) % mod * facinv(n - k) % mod

def rect(r, c):
	return cmb(r + c, c)
ret = (rect(r2 + 1, c2 + 1) - rect(r1, c2 + 1) - rect(r2 + 1, c1) + rect(r1, c1) + mod + mod) % mod
print(ret)


M = 1000000007
(r1, c1, r2, c2) = map(int, input().split())
n = r2 + c2 + 2
fac = [1] + [0] * n
for i in range(1, n + 1):
	fac[i] = fac[i - 1] * i % M
f = lambda r, c: fac[r + c + 2] * pow(fac[c + 1], M - 2, M) * pow(fac[r + 1], M - 2, M) - 1
print((f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)) % M)


class Combination:

	def __init__(self, n_max, mod=10 ** 9 + 7):
		self.mod = mod
		f = 1
		self.fac = fac = [f]
		for i in range(1, n_max + 1):
			f = f * i % mod
			fac.append(f)
		f = pow(f, mod - 2, mod)
		self.facinv = facinv = [f]
		for i in range(n_max, 0, -1):
			f = f * i % mod
			facinv.append(f)
		facinv.reverse()

	def __call__(self, n, r):
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

	def nCr(self, n, r):
		if not 0 <= r <= n:
			return 0
		return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

def resolve():

	def f(r, c):
		return cmb.nCr(r + c + 2, r + 1) - 1
	MOD = 10 ** 9 + 7
	(r1, c1, r2, c2) = map(int, input().split())
	r1 -= 1
	c1 -= 1
	cmb = Combination(r2 + c2 + 5)
	ans = f(r2, c2)
	ans -= f(r1, c2)
	ans -= f(r2, c1)
	ans += f(r1, c1)
	print(ans % MOD)

def __starting_point():
	resolve()
__starting_point()


import sys
input = sys.stdin.readline
(lr, lc, rr, rc) = map(int, input().split())
mod = 10 ** 9 + 7

class Factorial:

	def __init__(self, n, mod):
		self.f = [1]
		for i in range(1, n + 1):
			self.f.append(self.f[-1] * i % mod)
		self.i = [pow(self.f[-1], mod - 2, mod)]
		for i in range(1, n + 1)[::-1]:
			self.i.append(self.i[-1] * i % mod)
		self.i.reverse()

	def factorial(self, i):
		return self.f[i]

	def ifactorial(self, i):
		return self.i[i]

	def combi(self, n, k):
		return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
f = Factorial(rr + rc + 1, mod)
res = 0
for i in range(lr, rr + 1):
	res += f.combi(i + rc + 1, i + 1)
	res %= mod
for i in range(lr, rr + 1):
	res -= f.combi(i + lc, i + 1)
	res %= mod
print(res)


(r1, c1, r2, c2) = list(map(int, input().split()))
mod = 10 ** 9 + 7

def cmb(n, r, mod):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * pow(g1[r], mod - 2, mod) * pow(g1[n - r], mod - 2, mod) % mod

def make_table(n, mod=10 ** 9 + 7):
	N = n
	g1 = [0] * (N + 1)
	g1[0] = 1
	g1[1] = 1
	tmp = g1[1]
	for i in range(2, N + 1):
		tmp = tmp * i % mod
		g1[i] = g1[i - 1] * i % mod
	return g1

def f(x, y):
	return ((x + 2) * cmb(x + y + 2, y, mod) - y - 1) * pow(y + 1, mod - 2, mod)
g1 = make_table(2 * 10 ** 6 + 10)
answer = f(c2, r2) - f(c2, r1 - 1) - f(c1 - 1, r2) + f(c1 - 1, r1 - 1)
answer %= mod
print(answer)


def ncr(n, r):
	p = 10 ** 9 + 7
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
(r1, c1, r2, c2) = [int(i) for i in input().split()]
r1 += 1
c1 += 1
r2 += 1
c2 += 1
print((ncr(r2 + c2, c2) - ncr(r2 + c1 - 1, c1 - 1) - ncr(c2 + r1 - 1, r1 - 1) + ncr(r1 + c1 - 2, c1 - 1)) % (10 ** 9 + 7))


def solve():
	(r1, c1, r2, c2) = map(int, input().split())
	p = 10 ** 9 + 7
	N = r2 + c2 + 2
	fact = [1, 1]
	for i in range(2, N + 1):
		fact.append(fact[-1] * i % p)

	def comb(n, r):
		a = fact[n]
		b = pow(fact[r], p - 2, p)
		c = pow(fact[n - r], p - 2, p)
		return a * b * c % p

	def f(i, j):
		return comb(i + j, i)

	def g(i, j):
		return f(i + 1, j + 1) - 1
	ans = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)
	print(ans % p)
solve()


(u, l, d, r) = map(int, input().split())
mod = 10 ** 9 + 7

def extGCD(a, b):
	if b == 0:
		return (a, 1, 0)
	(g, y, x) = extGCD(b, a % b)
	y -= a // b * x
	return (g, x, y)

def moddiv(a, b):
	(_, inv, _) = extGCD(b, mod)
	return a * inv % mod
f = [0] * (2 * 10 ** 6 + 10)
f[0] = 1
for i in range(1, 2 * 10 ** 6 + 10):
	f[i] = f[i - 1] * i % mod

def comb(a, b):
	return moddiv(moddiv(f[a + b], f[a]), f[b])
ans = 0
d += 1
r += 1
ans += comb(d, r)
ans += comb(u, l)
ans -= comb(d, l)
ans -= comb(u, r)
print(ans % mod)


def main():
	mod = 10 ** 9 + 7
	fact = [1, 1]
	for i in range(2, 2 * 10 ** 6 + 10):
		fact.append(fact[-1] * i % mod)
	(r1, c1, r2, c2) = map(int, input().split())
	r1 -= 1
	c1 -= 1

	def calc(r, c):
		return (pow(fact[c + 1] * fact[r + 1] % mod, mod - 2, mod) * fact[r + c + 2] - 1) % mod
	print((calc(r2, c2) - calc(r1, c2) - calc(r2, c1) + calc(r1, c1)) % mod)
main()


import numpy as np
import sys
read = sys.stdin.read
(r1, c1, r2, c2) = list(map(int, read().split()))
MOD = 10 ** 9 + 7

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

def make_fact(U, MOD=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]
	fact.flags.writeable = False
	fact_inv.flags.writeable = False
	return (fact, fact_inv)
(fac, finv) = make_fact(2 * 10 ** 6 + 10, MOD)

def comb(n, k, mod=MOD, fac=fac, finv=finv):
	if n < k:
		return 0
	if n < 0 or k < 0:
		return 0
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod
answer = comb(r2 + c2 + 2, r2 + 1) - comb(r1 + c2 + 1, r1) - comb(c1 + r2 + 1, c1) + comb(r1 + c1, r1)
answer %= MOD
print(answer)


mod = 10 ** 9 + 7
(r1, c1, r2, c2) = map(int, input().split())

def inv(x):
	m = mod
	u = 1
	v = 0
	while m:
		t = x // m
		x -= t * m
		(x, m) = (m, x)
		u -= t * v
		(u, v) = (v, u)
	u %= mod
	if u < 0:
		u += mod
	return u
fac = [1]
for i in range(1, r2 + c2 + 3):
	fac.append(fac[i - 1] * i % mod)

def paths(r, c):
	return fac[r + c + 2] * inv(fac[r + 1] * fac[c + 1]) % mod
f = paths(r2, c2) - paths(r2, c1 - 1) - paths(r1 - 1, c2) + paths(r1 - 1, c1 - 1)
f %= mod
if f < 0:
	f += mod
print(f)


MOD = 10 ** 9 + 7

def facinv(N):
	(fac, finv, inv) = ([0] * (N + 1), [0] * (N + 1), [0] * (N + 1))
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i in range(2, N + 1):
		fac[i] = fac[i - 1] * i % MOD
		inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD
	return (fac, finv, inv)

def COM(n, r):
	if n < r or r < 0:
		return 0
	else:
		return fac[n] * finv[r] % MOD * finv[n - r] % MOD
(r1, c1, r2, c2) = map(int, input().split())
(fac, finv, inv) = facinv(r2 + c2 + 1)
ans = 0
for i in range(r1, r2 + 1):
	ans = (ans + COM(c2 + i + 1, i + 1) - COM(c1 + i, i + 1) + MOD) % MOD
print(ans)


MOD = 10 ** 9 + 7
table_len = 2 * 10 ** 6 + 10
fac = [1, 1]
for i in range(2, table_len):
	fac.append(fac[-1] * i % MOD)
finv = [0] * table_len
finv[-1] = pow(fac[-1], MOD - 2, MOD)
for i in range(table_len - 1, 0, -1):
	finv[i - 1] = finv[i] * i % MOD

def comb(a, b):
	return fac[a + b] * finv[a] * finv[b] % MOD
(r1, c1, r2, c2) = map(int, input().split())
ans = (comb(r1, c1) + comb(r2 + 1, c2 + 1) - comb(r1, c2 + 1) - comb(r2 + 1, c1)) % MOD
print(ans)


MOD = 10 ** 9 + 7

def prepare(n):
	global MOD
	modFacts = [0] * (n + 1)
	modFacts[0] = 1
	for i in range(n):
		modFacts[i + 1] = modFacts[i] * (i + 1) % MOD
	invs = [1] * (n + 1)
	invs[n] = pow(modFacts[n], MOD - 2, MOD)
	for i in range(n, 1, -1):
		invs[i - 1] = invs[i] * i % MOD
	return (modFacts, invs)

def f(i, j):
	Fij = modFacts[i + j]
	Ii = invs[i]
	Ij = invs[j]
	rst = Fij * Ii * Ij % MOD
	return rst

def g(r1, r2, y):
	rst = 0
	for x in range(r1, r2 + 1):
		rst += f(x + 1, y)
		rst %= MOD
	return rst
(r1, c1, r2, c2) = map(int, input().split())
(modFacts, invs) = prepare(max(r1, c1, r2, c2) * 2 + 1)
ans = g(r1, r2, c2) - g(r1, r2, c1 - 1)
print(ans % MOD)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return list(map(int, input().split()))

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class ModTools:

	def __init__(self, MAX, MOD):
		MAX += 1
		self.MAX = MAX
		self.MOD = MOD
		factorial = [1] * MAX
		factorial[0] = factorial[1] = 1
		for i in range(2, MAX):
			factorial[i] = factorial[i - 1] * i % MOD
		inverse = [1] * MAX
		inverse[MAX - 1] = pow(factorial[MAX - 1], MOD - 2, MOD)
		for i in range(MAX - 2, 0, -1):
			inverse[i] = inverse[i + 1] * (i + 1) % MOD
		self.fact = factorial
		self.inv = inverse

	def nCr(self, n, r):
		if n < r:
			return 0
		r = min(r, n - r)
		numerator = self.fact[n]
		denominator = self.inv[r] * self.inv[n - r] % self.MOD
		return numerator * denominator % self.MOD

	def div(self, x, y):
		return x * pow(y, self.MOD - 2, self.MOD) % self.MOD
(r1, c1, r2, c2) = MAP()
mt = ModTools(r2 + c2 + 2, MOD)

def calc(r, c):
	return mt.div((r + 2) * mt.nCr(c + r + 2, r + 2) - c - 1, c + 1)
ans = calc(r2, c2) - calc(r2, c1 - 1) - calc(r1 - 1, c2) + calc(r1 - 1, c1 - 1)
print(ans % MOD)


import math
import queue
import bisect
from collections import deque, defaultdict
import heapq as hpq
from sys import stdin, setrecursionlimit
ipt = stdin.readline
setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7

def main():
	(r1, c1, r2, c2) = list(map(int, ipt().split()))
	N = r2 + c2 + 2
	g1 = [1, 1]
	g2 = [1, 1]
	inverse = [0, 1]

	def cmb(n, r, mod=10 ** 9 + 7):
		if r < 0 or r > n:
			return 0
		r = min(r, n - r)
		return g1[n] * g2[r] * g2[n - r] % mod
	for i in range(2, N + 1):
		g1.append(g1[-1] * i % mod)
		inverse.append(-inverse[mod % i] * (mod // i) % mod)
		g2.append(g2[-1] * inverse[-1] % mod)
	print((cmb(r2 + c2 + 2, r2 + 1) + cmb(r1 + c1, r1) - cmb(r2 + c1 + 1, r2 + 1) - cmb(r1 + c2 + 1, r1)) % mod)
	return None

def __starting_point():
	main()
__starting_point()


MOD = int(1000000000.0) + 7

def fact(x):
	k = 1
	for i in range(1, x + 1):
		k = k * i % MOD
	return k

def inverse(b):
	r = 1
	e = MOD - 2
	while e:
		if e % 2 == 1:
			r = r * b % MOD
		b = b * b % MOD
		e >>= 1
	return r

def comb(i, j):
	if i == 0 or j == 0:
		return 0
	num = fact(i + j)
	num *= inverse(fact(i))
	num %= MOD
	num *= inverse(fact(j))
	num %= MOD
	return num
rc = list(map(int, input().split()))
ans = 0
ans += comb(rc[2] + 1, rc[3] + 1)
ans -= comb(rc[0], rc[3] + 1)
ans -= comb(rc[2] + 1, rc[1])
ans += comb(rc[0], rc[1])
ans += MOD
ans += MOD
ans %= MOD
print(ans)


def f(n, r, mod=10 ** 9 + 7):
	n += r
	assert n >= r >= 0

	def ex_euclid(x, y):
		(a, b) = (1, 0)
		while y != 0:
			(a, b) = (b, a - x // y * b)
			(x, y) = (y, x % y)
		return a
	p = q = 1
	for i in range(n - r + 1, n + 1):
		p *= i
		p %= mod
	for i in range(2, r + 1):
		q *= i
		q %= mod
	p *= ex_euclid(q, mod)
	p %= mod
	return p
(a, b, c, d) = map(int, input().split())
mod = 10 ** 9 + 7
print((f(c + 1, d + 1) + mod - f(a, d + 1) + mod - f(c + 1, b) + f(a, b)) % mod)


import sys
sys.setrecursionlimit(500 * 500)

def modpow(a, n, p):
	if n == 0:
		return 1
	x = modpow(a, n // 2, p)
	x = x * x % p
	if n % 2 == 1:
		x = x * a % p
	return x % p

def modinv(a, p):
	return modpow(a, p - 2, p)
(r1, c1, r2, c2) = map(int, input().split())
n1 = r2 + c2 + 2
n2 = r2 + c1 + 1
n3 = r1 + c2 + 1
n4 = r1 + c1
l = [r2 + 1, r2 + 1, r1, r1]
p = 10 ** 9 + 7
buf = 1
cnt = 0
l = [0] * (10 ** 7 + 10)
inv = [0] * (10 ** 7 + 10)
l[1] = 1
for i in range(2, n1 + 3, 1):
	l[i] = l[i - 1] * i % p
print((l[n1] * modinv(l[r2 + 1], p) * modinv(l[n1 - r2 - 1], p) % p - l[n2] * modinv(l[r2 + 1], p) * modinv(l[n2 - r2 - 1], p) - l[n3] * modinv(l[r1], p) * modinv(l[n3 - r1], p) + l[n4] * modinv(l[r1], p) * modinv(l[n4 - r1], p)) % p)


(r1, c1, r2, c2) = map(int, input().split())
MOD = 10 ** 9 + 7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

def func(r, c):
	if c == 0:
		return r + 1
	return comb(r + c + 2, c + 1, MOD)

def comb(n, r, mod):
	return g1[n] * g2[r] * g2[n - r] % mod
for i in range(2, r2 + c2 + 10):
	g1.append(g1[-1] * i % MOD)
	inverse.append(-inverse[MOD % i] * (MOD // i) % MOD)
	g2.append(g2[-1] * inverse[-1] % MOD)
print((func(r2, c2) - func(r1 - 1, c2) - func(r2, c1 - 1) + func(r1 - 1, c1 - 1)) % MOD)


m = 1000000007
(r1, c1, r2, c2) = map(int, input().split())
nf = 10 ** 6 * 2 + 100
fact = [0] * (nf + 1)
fact[0] = 1
for i in range(nf):
	fact[i + 1] = fact[i] * (i + 1) % m

def F(r, c):
	path = fact[r + c + 2] % m * pow(fact[r + 1] * fact[c + 1], m - 2, m) % m
	return path - 1
r1 -= 1
c1 -= 1
ans = F(r2, c2)
ans -= F(r1, c2)
ans -= F(r2, c1)
ans += F(r1, c1)
ans = ans % m
print(ans)


mod = 1000000007

class combination:

	def __init__(self, n):
		self.fact = [1] * (n + 1)
		self.ifact = [1] * (n + 1)
		for i in range(1, n + 1):
			self.fact[i] = self.fact[i - 1] * i % mod
		self.ifact[n] = pow(self.fact[n], mod - 2, mod)
		for i in range(n, 0, -1):
			self.ifact[i - 1] = self.ifact[i] * i % mod

	def comb(self, n, k):
		if k < 0 or k > n:
			return 0
		comb = self.fact[n] * self.ifact[k] * self.ifact[n - k] % mod
		return comb

def main():
	import sys
	input = sys.stdin.readline
	(r1, c1, r2, c2) = map(int, input().split())
	comb = combination(2000010)
	ans = comb.comb(c2 + r2 + 2, r2 + 1) - 1
	ans -= comb.comb(c1 + r2 + 1, c1) - 1
	ans -= comb.comb(c2 + r1 + 1, r1) - 1
	ans += comb.comb(c1 + r1, r1) - 1
	print(ans % mod)
main()


from operator import mul
from functools import reduce
(r1, c1, r2, c2) = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
num = 10 ** 6 * 2 + 3
fact = [0] * num
fact[0] = 1
for i in range(1, num):
	fact[i] = fact[i - 1] * i % mod

def combinations_count(n, r):
	r = min(r, n - r)
	numer = reduce(mul, range(n, n - r, -1), 1)
	denom = reduce(mul, range(1, r + 1), 1)
	return numer // denom

def f(rr, cc):
	return fact[rr + cc + 2] % mod * pow(fact[rr + 1] * fact[cc + 1], mod - 2, mod) % mod - 1
ans = f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)
print(ans % mod)


def main():
	import sys
	M = 10 ** 9 + 7
	(r1, c1, r2, c2) = map(int, sys.stdin.buffer.readline().split())
	n = r2 + c2 + 2
	val = 1
	fac = [val]
	append = fac.append
	for i in range(1, n + 1):
		val = val * i % M
		append(val)
	pr1 = pow(fac[r1], M - 2, M)
	pc1 = pow(fac[c1], M - 2, M)
	pr2 = pow(fac[r2 + 1], M - 2, M)
	pc2 = pow(fac[c2 + 1], M - 2, M)
	print((fac[r2 + c2 + 2] * pr2 * pc2 - fac[r2 + c1 + 1] * pr2 * pc1 - fac[r1 + c2 + 1] * pr1 * pc2 + fac[r1 + c1] * pr1 * pc1) % M)
main()


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)
(r1, c1, r2, c2) = list(map(int, input().split()))
MOD = 10 ** 9 + 7
(facts, invs) = prepare(r2 + c2 + 1, MOD)
ans = 0
for i in range(r1, r2 + 1):
	d1 = facts[i + c2 + 1] * invs[c2] % MOD
	d2 = facts[i + c1] * invs[c1 - 1] % MOD
	ans = (ans + (d1 - d2) * invs[i + 1]) % MOD
print(ans)