There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and the j-th column from the left.

In the grid, N Squares (r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N) are wall squares, and the others are all empty squares. It is guaranteed that Squares (1, 1) and (H, W) are empty squares.

Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square.

Find the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.

Constraints

* All values in input are integers.
* 2 \leq H, W \leq 10^5
* 1 \leq N \leq 3000
* 1 \leq r_i \leq H
* 1 \leq c_i \leq W
* Squares (r_i, c_i) are all distinct.
* Squares (1, 1) and (H, W) are empty squares.

Input

Input is given from Standard Input in the following format:


H W N
r_1 c_1
r_2 c_2
:
r_N c_N


Output

Print the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.

Examples

Input

3 4 2
2 2
1 4


Output

3


Input

5 2 2
2 1
4 2


Output

0


Input

5 5 4
3 1
3 5
1 3
5 3


Output

24


Input

100000 100000 1
50000 50000


Output

123445622

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10 ** 9))
write = lambda x: sys.stdout.write(x + '\n')
(h, w, n) = list(map(int, input().split()))
h -= 1
w -= 1
rc = [None] * n
for i in range(n):
	rc[i] = tuple(map(lambda x: int(x) - 1, input().split()))
rc.sort()
M = 10 ** 9 + 7
N = h + w + 10
g1 = [None] * (N + 1)
g2 = [None] * (N + 1)
inverse = [None] * (N + 1)
g1[0] = g1[1] = g2[0] = g2[1] = 1
(inverse[0], inverse[1]) = [0, 1]
for i in range(2, N + 1):
	g1[i] = g1[i - 1] * i % M
	inverse[i] = -inverse[M % i] * (M // i) % M
	g2[i] = g2[i - 1] * inverse[i] % M

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

def f(x, y):
	return cmb(x + y, x, M)
for i in range(n):
	(r, c) = rc[i]
	val = f(r, c)
	for j in range(i):
		val -= dp[j] * f(r - rc[j][0], c - rc[j][1])
		val %= M
	dp[i] = val
ans = 0
for i in range(n):
	(r, c) = rc[i]
	ans += dp[i] * f(h - r, w - c)
	ans %= M
ans = f(h, w) - ans
ans %= M
print(ans % M)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
(h, w, n) = map(int, readline().split())
rc = [(1, 1)]
for i in range(n):
	(r, c) = map(int, readline().split())
	rc.append((r, c))
rc.sort(key=lambda x: sum(x) * -1)
mod = 10 ** 9 + 7
max_n = 3 * 10 ** 5
(fac, finv, inv) = ([0] * max_n, [0] * max_n, [0] * max_n)

def comInit(max_n):
	fac[0] = fac[1] = 1
	finv[0] = finv[1] = 1
	inv[1] = 1
	for i in range(2, max_n):
		fac[i] = fac[i - 1] * i % mod
		inv[i] = mod - inv[mod % i] * (mod // i) % mod
		finv[i] = finv[i - 1] * inv[i] % mod
comInit(max_n)

def com(n, k):
	if n < k:
		return 0
	if (n < 0) | (k < 0):
		return 0
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod
dp = [0] * (n + 2)
dp[0] = 1
for i in range(n + 1):
	(ri, ci) = rc[i]
	dp[i + 1] = com(h + w - ri - ci, h - ri)
	for j in range(i):
		(rj, cj) = rc[j]
		if (ri <= rj) & (ci <= cj):
			dp[i + 1] -= com(rj + cj - ri - ci, rj - ri) * dp[j + 1]
			dp[i + 1] %= mod
print(dp[-1])


mod = 10 ** 9 + 7
frac = [1] * 200001
for i in range(2, 200001):
	frac[i] = i * frac[i - 1] % mod
fraci = [None] * 200001
fraci[-1] = pow(frac[-1], mod - 2, mod)
for i in range(-2, -200001 - 1, -1):
	fraci[i] = fraci[i + 1] * (200001 + i + 1) % mod

def comb(a, b):
	if not a >= b >= 0:
		return 0
	return frac[a] * fraci[b] * fraci[a - b] % mod

def count(a, b):
	((r1, c1), (r2, c2)) = (RC[a], RC[b])
	if c2 < c1:
		return 0
	return comb(r2 - r1 + c2 - c1, r2 - r1)
(H, W, N) = map(int, input().split())
RC = [list(map(int, input().split())) for _ in range(N)] + [[1, 1], [H, W]]
RC.sort()
dp = [0] * (N + 2)
dp[0] += 1
for i in range(1, N + 2):
	res = count(0, i)
	for k in range(1, i):
		res = (res - count(k, i) * dp[k]) % mod
	dp[i] = res
print(dp[-1])


SIZE = 300000
MOD = 10 ** 9 + 7
inv = [0] * (SIZE + 1)
fac = [0] * (SIZE + 1)
finv = [0] * (SIZE + 1)
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2, SIZE + 1):
	inv[i] = MOD - MOD // i * inv[MOD % i] % MOD
	fac[i] = fac[i - 1] * i % MOD
	finv[i] = finv[i - 1] * inv[i] % MOD

def choose(n, r):
	if 0 <= r <= n:
		return fac[n] * finv[r] % MOD * finv[n - r] % MOD
	else:
		return 0
(h, w, n) = [int(i) for i in input().split()]
xy = [[1, 1]] + [[int(i) for i in input().split()] for _ in range(n)]
dp = [0] * (n + 1)
dp[0] = 1
xy.sort(key=lambda x: x[1])
xy.sort(key=lambda x: x[0])
for i in range(1, n + 1):
	(x, y) = xy[i]
	for j in range(i):
		(xj, yj) = xy[j]
		dp[i] -= choose(x - xj + y - yj, y - yj) * dp[j]
		dp[i] %= MOD
ans = 0
for (i, dpi) in enumerate(dp):
	(x, y) = xy[i]
	ans += choose(h - x + w - y, w - y) * dpi
	ans %= MOD
print(ans)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def MI():
	return map(int, sys.stdin.readline().split())

def MI1():
	return map(int1, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def com(com_n, com_r):
	return fac[com_n] * inv[com_r] * inv[com_n - com_r] % md

def way(h, w):
	if h < 0 or w < 0:
		return 0
	else:
		return com(h + w, h)
md = 10 ** 9 + 7
n_max = 200005
fac = [1]
inv = [1] * (n_max + 1)
k_fac_inv = 1
for i in range(1, n_max + 1):
	k_fac_inv = k_fac_inv * i % md
	fac.append(k_fac_inv)
k_fac_inv = pow(k_fac_inv, md - 2, md)
for i in range(n_max, 1, -1):
	inv[i] = k_fac_inv
	k_fac_inv = k_fac_inv * i % md

def main():
	(h, w, n) = MI()
	rc = [LI1() for _ in range(n)]
	rc.sort(key=lambda x: x[0] + x[1])
	dp = [0] * n
	for (i, (r, c)) in enumerate(rc):
		dp[i] = way(r, c) - sum((v * way(r - pr, c - pc) % md for (v, (pr, pc)) in zip(dp[:i], rc[:i])))
		dp[i] %= md
	(h, w) = (h - 1, w - 1)
	ans = way(h, w) - sum((v * way(h - r, w - c) % md for (v, (r, c)) in zip(dp, rc)))
	print(ans % md)
main()


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():
	MOD = 10 ** 9 + 7
	(H, W, N) = map(int, input().split())
	wall = []
	for _ in range(N):
		(r, c) = map(lambda x: int(x) - 1, input().split())
		wall.append((r, c))
	wall.append((H - 1, W - 1))
	wall.sort()
	cmb = Combination(H + W + 1)
	dp = [0] * (N + 1)
	for i in range(N + 1):
		(r1, c1) = wall[i]
		dp[i] = cmb.nCr(r1 + c1, c1)
		for j in range(0, i):
			dx = r1 - wall[j][0]
			dy = c1 - wall[j][1]
			tmp = dp[j] * cmb.nCr(dx + dy, dy)
			dp[i] = (dp[i] - tmp % MOD + MOD) % MOD
	print(dp[N])
resolve()


mod = 10 ** 9 + 7
frac = [1] * 200001
for i in range(2, 200001):
	frac[i] = i * frac[i - 1] % mod
fraci = [None] * 200001
fraci[-1] = pow(frac[-1], mod - 2, mod)
for i in range(-2, -200001 - 1, -1):
	fraci[i] = fraci[i + 1] * (200001 + i + 1) % mod

def comb(a, b):
	if not a >= b >= 0:
		return 0
	return frac[a] * fraci[b] * fraci[a - b] % mod
(H, W, N) = map(int, input().split())
RC = [tuple(map(int, input().split())) for _ in range(N)] + [(1, 1), (H, W)]
RC.sort()
(R, C) = map(tuple, zip(*RC))
dp = [0] * (N + 2)
for i in range(1, N + 2):
	(r, c) = (R[i], C[i])
	res = comb(r + c - 2, r - 1)
	for k in range(1, i):
		(rk, ck) = (R[k], C[k])
		if ck > c:
			continue
		res = (res - comb(r - rk + c - ck, r - rk) * dp[k] % mod) % mod
	dp[i] = res
print(dp[-1])


(H, W, N) = map(int, input().split())
import sys
M = 10 ** 9 + 7

def C(n, r):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] * g2[n - r] % M
NNN = 2 * 10 ** 5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, NNN + 1):
	g1.append(g1[-1] * i % M)
	inverse.append(-inverse[M % i] * (M // i) % M)
	g2.append(g2[-1] * inverse[-1] % M)
vs = []
for _ in range(N):
	(X, Y) = map(int, input().split())
	vs.append((X, Y))
d = [0] * N
d2 = [0] * N
vs.sort()
for i in range(N - 1, -1, -1):
	(x, y) = vs[i]
	d2[i] = C(x + y - 2, x - 1)
	r = C(H - x + W - y, H - x)
	for j in range(N - 1, i, -1):
		(v, w) = vs[j]
		r = (r - C(v - x + w - y, v - x) * d[j]) % M
	d[i] = r
r = 0
for i in range(N):
	r = (r + d[i] * d2[i] % M) % M
r = (C(H + W - 2, H - 1) - r) % M
print(r)


import sys
input = sys.stdin.readline
MAX = 2 * 10 ** 5 + 100
MOD = 10 ** 9 + 7
fact = [0] * MAX
inv = [0] * MAX
finv = [0] * MAX
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
	fact[i] = fact[i - 1] * i % MOD
	inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
	finv[i] = finv[i - 1] * inv[i] % MOD

def C(n, r):
	if n < r:
		return 0
	if n < 0 or r < 0:
		return 0
	return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD
(H, W, N) = map(int, input().split())
rc = [tuple(map(int, input().split())) for _ in range(N)]
rc.sort(key=lambda t: t[0] + t[1])
ans = C(H + W - 2, H - 1)
dp = [0] * N
for i in range(N):
	(ri, ci) = rc[i]
	dp[i] = C(ri + ci - 2, ri - 1)
	for j in range(i):
		(rj, cj) = rc[j]
		dp[i] -= dp[j] * C(ri - rj + ci - cj, ri - rj)
		dp[i] %= MOD
	ans -= dp[i] * C(H - ri + W - ci, H - ri)
	ans %= MOD
print(ans)


from operator import itemgetter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7

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 main():
	(H, W, N) = map(int, input().split())
	XY = list((tuple(map(int, input().split())) for _ in range(N)))
	comb = Combination(H + W + 10, mod)
	fact = tuple(comb.fact)
	inv = tuple(comb.inv)
	edge = [[] for _ in range(N + 2)]
	indeg = {i: 0 for i in range(N + 2)}
	edge[0].append((N + 1, comb(H + W - 2, H - 1)))
	indeg[N + 1] += 1
	for (i, (x1, y1)) in enumerate(XY, 1):
		edge[0].append((i, comb(x1 + y1 - 2, x1 - 1)))
		indeg[i] += 1
		edge[i].append((N + 1, comb(H + W - x1 - y1, H - x1)))
		indeg[N + 1] += 1
		for (j, (x2, y2)) in enumerate(XY, 1):
			if i == j:
				continue
			if x1 <= x2 and y1 <= y2:
				edge[i].append((j, comb(x2 + y2 - x1 - y1, x2 - x1)))
				indeg[j] += 1
	order = sorted(indeg.items(), key=itemgetter(1))
	dp = [0] * (N + 2)
	dp[0] = -1
	for (s, _) in order:
		for (t, path) in edge[s]:
			dp[t] = (dp[t] - path * dp[s] + mod) % mod
	print(dp[N + 1])
main()


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 route(a, b):
		dx = b[0] - a[0]
		dy = b[1] - a[1]
		if dx < 0 or dy < 0:
			return 0
		return cmb.nCr(dx + dy, dx)
	MOD = 10 ** 9 + 7
	(H, W, N) = map(int, input().split())
	wall = []
	for _ in range(N):
		(r, c) = map(lambda x: int(x) - 1, input().split())
		wall.append((r, c))
	wall.append((0, 0))
	wall.sort()
	cmb = Combination(H + W + 1)
	dp = [[0] * 2 for _ in range(N + 1)]
	dp[0][0] = 1
	for i in range(1, N + 1):
		for j in range(0, i):
			dp[i][0] += dp[j][1] * route(wall[j], wall[i]) % MOD
			dp[i][0] %= MOD
			dp[i][1] += dp[j][0] * route(wall[j], wall[i]) % MOD
			dp[i][1] %= MOD
	goal = (H - 1, W - 1)
	ng = 0
	for i in range(1, N + 1):
		ng -= dp[i][0] * route(wall[i], goal) % MOD
		ng += dp[i][1] * route(wall[i], goal) % MOD
		ng %= MOD
	all = cmb.nCr(H + W - 2, H - 1)
	ans = (all - ng + MOD) % MOD
	print(ans)
resolve()


import sys
input = lambda : sys.stdin.readline().strip()

class PERM_COMB_MOD:

	def __init__(self, max_n=510000, mod=10 ** 9 + 7):
		self.fac = [0] * max_n
		self.finv = [0] * max_n
		self.inv = [0] * max_n
		self.fac[0] = self.fac[1] = 1
		self.finv[0] = self.finv[1] = 1
		self.inv[1] = 1
		self.max = max_n
		self.mod = mod
		self._maesyori()

	def _maesyori(self):
		for i in range(2, self.max):
			self.fac[i] = self.fac[i - 1] * i % self.mod
			self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
			self.finv[i] = self.finv[i - 1] * self.inv[i] % self.mod

	def comb(self, n, k):
		if n < k:
			return 0
		if n < 0 or k < 0:
			return 0
		return self.fac[n] * (self.finv[k] * self.finv[n - k] % self.mod) % self.mod
mod = 10 ** 9 + 7
PCM = PERM_COMB_MOD(3 * 10 ** 5, mod=mod)
(h, w, n) = map(int, input().split())
rc = [list(map(int, input().split())) for i in range(n)]
rc.append([h, w])
n += 1
rc.sort()
DP = [0] * (n + 1)
DP[0] = 1
for i in range(n):
	(r, c) = rc[i]
	DP[i + 1] = PCM.comb(r - 1 + c - 1, r - 1)
	for j in range(i):
		(rj, cj) = rc[j]
		if rj <= r and cj <= c:
			DP[i + 1] -= DP[j + 1] * PCM.comb(r - rj + c - cj, r - rj)
	DP[i + 1] %= mod
print(DP[-1])


def main():
	import sys
	from operator import itemgetter
	input = sys.stdin.readline
	mod = 1000000007
	nmax = 3 * 10 ** 5 + 1
	fac = [0] * (nmax + 1)
	finv = [0] * (nmax + 1)
	inv = [0] * (nmax + 1)
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i in range(2, nmax):
		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 comb(n, r):
		if n < r:
			return 0
		else:
			return fac[n] * (finv[r] * finv[n - r] % mod) % mod
	(H, W, N) = map(int, input().split())
	block = []
	for _ in range(N):
		(r, c) = map(int, input().split())
		block.append((r, c))
	block.sort(key=itemgetter(1))
	block.sort(key=itemgetter(0))
	block.insert(0, (1, 1))
	dp_p = [0] * (N + 1)
	dp_n = [0] * (N + 1)
	dp_p[0] = 1
	for i in range(1, N + 1):
		(ri, ci) = block[i]
		for j in range(i):
			(rj, cj) = block[j]
			if ri >= rj and ci >= cj:
				dp_p[i] = (dp_p[i] + dp_n[j] * comb(ri - rj + ci - cj, ri - rj) % mod) % mod
				dp_n[i] = (dp_n[i] + dp_p[j] * comb(ri - rj + ci - cj, ri - rj) % mod) % mod
	ans = 0
	for i in range(N + 1):
		ans = (ans + (dp_p[i] - dp_n[i]) % mod * comb(H - block[i][0] + W - block[i][1], H - block[i][0]) % mod) % mod
	print(ans)
main()


mod = 10 ** 9 + 7
frac = [1] * 200001
for i in range(2, 200001):
	frac[i] = i * frac[i - 1] % mod
fraci = [None] * 200001
fraci[-1] = pow(frac[-1], mod - 2, mod)
for i in range(-2, -200001 - 1, -1):
	fraci[i] = fraci[i + 1] * (200001 + i + 1) % mod

def comb(a, b):
	if not a >= b >= 0:
		return 0
	return frac[a] * fraci[b] * fraci[a - b] % mod

def count(a, b):
	((r1, c1), (r2, c2)) = (RC[a], RC[b])
	if c2 < c1:
		return 0
	return comb(r2 - r1 + c2 - c1, r2 - r1)
(H, W, N) = map(int, input().split())
RC = [list(map(int, input().split())) for _ in range(N)] + [[1, 1], [H, W]]
RC.sort()
dpe = [0] * (N + 2)
dpo = [0] * (N + 2)
dpe[0] += 1
for i in range(1, N + 2):
	rese = 0
	reso = 0
	for k in range(i):
		t = count(k, i)
		if not t:
			continue
		rese = (rese + t * dpo[k]) % mod
		reso = (reso + t * dpe[k]) % mod
	dpe[i] = rese
	dpo[i] = reso
print((dpo[-1] - dpe[-1]) % mod)