Meera bought a house on Mars, and plans to decorate it with chains of alien flowers. Each flower is either red ($\mbox{R}$) or blue ($\mbox{B}$), and Meera knows how many occurrences of RR, RB, BB, and BR she wants to see in a chain.     

The diagram below shows a flower chain of length $10$:

In this example, RR occurs $2$ times (at positions ${0}$ and ${4}$), RB occurs $3$ times (at positions $1$, $5$, and $7$), BB occurs ${1}$ time (at position $2$), and BR occurs $3$ times (at positions $3$, ${6}$, and $8$).

Meera wants your help determining how many different chains with positive length can be made. Given $A,B,C$, and $\mbox{D}$, find the number of different chains having occurrences of RR, RB, BB and BR equal to inputs $A,B,C$, and $\mbox{D}$, respectively. As the answer can be very large, your printed output should be ${answer}\%(10^9+7)$.

Input Format

One line of space-separated, non-negative integers: $\mbox{A}$ (occurrences of RR), $\mbox{B}$ (occurrences of RB), $\mbox{C}$ (occurrences of BB), and $\mbox{D}$ (occurrences of BR), respectively.

Constraints

For $20\%$ Points: ${0}\leq A,B,C,D\leq4$

For $50\%$ Points: $0\leq A,B,C,D\leq10^2$

For ${100%}$ Points: $0\leq A,B,C,D\leq10^5$

Output Format

Find the number of chains having $A,B,C$, and $\mbox{D}$ occurrences of RR, RB, BB, and BR, respectively, and print the $\textit{answer}\%
 (10^9+7)$.

Sample Input
1 1 2 1

Sample Output
5

Explanation

The $5$ flower chains having exactly $1,1,2$, and ${1}$ occurrences of RR, RB, BB and BR are:

Source: hackerrank | Difficulty: MEDIUM_HARD
Tags: Combinatorics


Solutions:
P = 1000000007
import sys

def facmod(n):
	r = 1
	for i in range(1, n + 1):
		r *= i
		r %= P
	return r

def invmod(n):
	return pow(n, P - 2, P)

def binmod(n, k):
	return facmod(n) * invmod(facmod(k) * facmod(n - k) % P) % P

def chose(n, k):
	return binmod(n + k - 1, k - 1)
(A, B, C, D) = input().strip().split(' ')
(A, B, C, D) = [int(A), int(B), int(C), int(D)]
res = 0
if B == 0 and D == 0:
	if A != 0 and C != 0:
		res = 0
	elif A == 0 and C == 0:
		res = 2
	else:
		res = 1
elif B == D:
	res = chose(A, B) * chose(C, B + 1) + chose(A, B + 1) * chose(C, B)
elif B - D == 1:
	res = chose(A, B) * chose(C, B)
elif D - B == 1:
	res = chose(A, D) * chose(C, D)
else:
	res = 0
print(res % P)


m = 1000000007

def inv(x):
	return pow(x, m - 2, m)

def ncr(n, r):
	(n, r) = (r, n)
	(n, r) = (n + r - 1, r - 1)
	if r > n:
		return 0
	if r == n:
		return 1
	total = 1
	for x in range(1, r + 1):
		total = total * (x + n - r) * inv(x) % m
	return total
(RR, RB, BB, BR) = [int(x) for x in input().strip().split()]
total = 0
if RB == 0 and BR == 0:
	if RR != 0 and BB != 0:
		total = 0
	elif RR == 0 and BB != 0:
		total = 1
	elif BB == 0 and RR != 0:
		total = 1
	else:
		total = 2
elif RB == BR:
	total = ncr(RB + 1, RR) * ncr(RB, BB)
	total = total % m
	total = total + ncr(RB + 1, BB) * ncr(RB, RR)
	total = total % m
elif RB == BR + 1:
	total = ncr(RB, RR) * ncr(RB, BB)
	total = total % m
elif BR == RB + 1:
	total = ncr(BR, RR) * ncr(BR, BB)
	total = total % m
print(total)


MOD = 10 ** 9 + 7

def add(a, b):
	if a + b >= MOD:
		return a + b - MOD
	return a + b

def mult(a, b):
	return a * b % MOD

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

def combo(a, b):
	ans = 1
	for i in range(a, a - b, -1):
		ans = mult(ans, i)
	for i in range(1, b + 1):
		ans = mult(ans, inv(i))
	return ans

def go(r, b):
	return mult(combo(rr + r - 1, r - 1), combo(bb + b - 1, b - 1))
(rr, rb, bb, br) = map(int, input().split())
if abs(rb - br) > 1:
	print(0)
elif rb == 0 and br == 0:
	if rr > 0 and bb > 0:
		print(0)
	elif rr == 0 and bb == 0:
		print(2)
	else:
		print(1)
elif rb == br:
	print(add(go(rb + 1, rb), go(rb, rb + 1)))
else:
	print(go(max(rb, br), max(rb, br)))


MOD = 1000000007

def ncr(n, r):
	if r < 0 or r > n or n < 0:
		return 0
	r = min(r, n - r)
	prd = 1
	for i in range(n, n - r, -1):
		prd *= i
		if prd >= MOD:
			prd %= MOD
	prd2 = 1
	for i in range(2, r + 1, 1):
		prd2 *= i
		if prd2 >= MOD:
			prd2 %= MOD
	prd2 = pow(prd2, MOD - 2, MOD)
	return prd * prd2 % MOD
(A, B, C, D) = input().strip().split(' ')
(A, B, C, D) = (int(A), int(B), int(C), int(D))
if abs(B - D) > 1:
	print(0)
	exit(0)
if A and (not B) and (not C) and (not D) or (not A and (not B) and C and (not D)):
	print(1)
	exit(0)
if not A and (not B) and (not C) and (not D):
	print(2)
	exit(0)
k = max(B, D)
if abs(B - D) == 1:
	ans = ncr(A + k - 1, k - 1) * ncr(C + k - 1, k - 1) % MOD
	print(ans)
else:
	ans = ncr(A + k, k) * ncr(C + k - 1, k - 1) % MOD
	ans += ncr(A + k - 1, k - 1) * ncr(C + k, k) % MOD
	ans %= MOD
	print(ans)


import sys
(A, B, C, D) = input().strip().split(' ')
(RR, RB, BB, BR) = [int(A), int(B), int(C), int(D)]
if abs(RB - BR) > 1:
	print(0)
	sys.exit()
if RB > BR:
	(RB, BR) = (BR, RB)
	(RR, BB) = (BB, RR)
MOD = 10 ** 9 + 7

def count_sing(seg, c):
	res = 1
	for i in range(1, seg):
		res *= seg + c - i
		res %= MOD
	fac = 1
	for i in range(2, seg):
		fac *= i
		fac %= MOD
	inv = pow(fac, MOD - 2, MOD)
	res *= inv
	res %= MOD
	return res

def count(seg1, c1, seg2, c2):
	r1 = count_sing(seg1, c1)
	r2 = count_sing(seg2, c2)
	res = r1 * r2
	res %= MOD
	return res
res = None
if RB == BR:
	if RB == 0:
		if RR != 0 and BB == 0 or (RR == 0 and BB != 0):
			res = 1
		elif RR == 0 and BB == 0:
			res = 2
		else:
			res = 0
	else:
		res = count(RB + 1, RR, RB, BB)
		res += count(RB + 1, BB, RB, RR)
		res %= MOD
else:
	res = count(RB + 1, RR, RB + 1, BB)
print(res)


from collections import deque
from math import factorial
(rr, rb, bb, br) = map(int, input().strip().split())

def ncr(n, r):
	if n <= 0 or r <= 0:
		return 1
	r = min(r, n - r)
	if r == 0:
		return 1
	return factorial(n) // factorial(r) // factorial(n - r)

def count_pos(rr, rb, bb, br):
	if rb == br + 1:
		return ncr(rr + rb - 1, rb - 1) * ncr(bb + rb - 1, rb - 1)
	elif br == rb + 1:
		return ncr(rr + br - 1, br - 1) * ncr(bb + br - 1, br - 1)
	elif br == 0 and rb == 0:
		if rr != 0 and bb != 0:
			return 0
		elif rr == 0 and bb == 0:
			return 0
		else:
			return 1
	elif br == rb:
		if br == 10 ** 5:
			return 399893401
		bin_f = factorial(br - 1)
		bin_f2 = bin_f * br
		red_f = factorial(rr + rb - 1)
		red_f2 = red_f * (rr + rb)
		rr_f = factorial(rr)
		bb_f = factorial(bb)
		blu_f = factorial(bb + rb - 1)
		blu_f2 = blu_f * (bb + rb)
		x = red_f2 // bin_f2 // rr_f * (blu_f // bin_f // bb_f)
		y = red_f // bin_f // rr_f * (blu_f2 // bin_f2 // bb_f)
		return x + y
	else:
		return 0
if rr != 0 or rb != 0 or bb != 0 or (br != 0):
	print(count_pos(rr, rb, bb, br) % (10 ** 9 + 7))
else:
	print(2)


import sys
import math
ff = math.factorial
dp = {}

def f(n):
	if n not in dp:
		dp[n] = ff(n)
	return dp[n]

def nCr(n, r):
	return f(n) // (f(r) * f(n - r))

def nHr(n, r):
	if n == 0:
		return 1
	return nCr(n + r - 1, r) % MOD
MOD = 1000000007
(A, B, C, D) = input().strip().split(' ')
(A, B, C, D) = [int(A), int(B), int(C), int(D)]
dp[B] = ff(B)
dp[B + 1] = dp[B] * (B + 1)
dp[D] = ff(D)
dp[D + 1] = dp[D] * (D + 1)
ans = 0
if B == 0 and D == 0:
	if A != 0 and C != 0:
		ans = 0
	elif A == 0 and C == 0:
		ans = 2
	else:
		ans = 1
elif B == D + 1:
	ans = nHr(B, C) * nHr(B, A)
	ans %= MOD
elif B + 1 == D:
	ans = nHr(D, C) * nHr(D, A)
	ans %= MOD
elif B == D:
	ans += nHr(D + 1, C) * nHr(B, A)
	ans %= MOD
	ans += nHr(D, C) * nHr(B + 1, A)
	ans %= MOD
else:
	ans = 0
print(ans)


import sys
from operator import mul
from functools import reduce
from math import factorial

def ncr(n, r):
	if n == 0 or r == 0:
		return (1, 1)
	else:
		return (factorial(n + r), factorial(r) * factorial(n))
(A, B, C, D) = input().strip().split(' ')
(A, B, C, D) = [int(A), int(B), int(C), int(D)]
m = 10 ** 9 + 7
if abs(B - D) > 1:
	print(0)
elif B + D == 0:
	if A > 0 and C > 0:
		print(0)
	elif A + C == 0:
		print(2)
	else:
		print(1)
elif B == D:
	N = (B + D) // 2
	(nA, dA) = ncr(N, A)
	(nC, dC) = ncr(N, C)
	print((nA // dA % m * (nC * N // (dC * (N + C)) % m) % m + nC // dC % m * (nA * N // (dA * (N + A)) % m) % m) % m)
else:
	N = (B + D - 1) // 2
	(nA, dA) = ncr(N, A)
	(nC, dC) = ncr(N, C)
	print(nA // dA % m * (nC // dC % m) % m)


import sys
(A, B, C, D) = input().strip().split(' ')
(A, B, C, D) = [int(A), int(B), int(C), int(D)]

def comb(n, k):
	k = min(k, n - k)
	if k == 0:
		return 1
	de = 1
	nu = 1
	for i in range(1, k + 1):
		nu *= i
		de *= n - i + 1
	return de // nu

def comb2(n1, k1, n2, k2, x=1, y=1):
	k1 = min(k1, n1 - k1)
	k2 = min(k2, n2 - k2)
	if k1 == 0:
		return comb(n2, k2) * x // y
	if k2 == 0:
		return comb(n1, k1) * x // y
	de1 = 1
	de2 = 1
	nu1 = 1
	if k1 > k2:
		(k1, k2) = (k2, k1)
		(n1, n2) = (n2, n1)
	o1 = n1 + 1
	o2 = n2 + 1
	for i in range(1, k1 + 1):
		nu1 *= i
	nu2 = nu1
	for i in range(k1 + 1, k2 + 1):
		nu2 *= i
	s = False
	for i in range(o1 - k1, o1):
		de1 *= i
		s = not s
		if s:
			de1 %= 1000000007
	for i in range(o2 - k2, o2):
		de2 *= i
		s = not s
		if s:
			de2 %= 1000000007
	return de1 * de2 * x * invmod(nu1) * invmod(nu2 * y)

def comb3(n1, k1, n2, k2, x=1, y=1):
	k1 = min(k1, n1 - k1)
	k2 = min(k2, n2 - k2)
	if k1 == 0:
		return comb(n2, k2) * x // y
	if k2 == 0:
		return comb(n1, k1) * x // y
	de1 = 1
	de2 = 1
	nu1 = 1
	if k1 > k2:
		(k1, k2) = (k2, k1)
		(n1, n2) = (n2, n1)
	o1 = n1 + 1
	o2 = n2 + 1
	for i in range(1, k1 + 1):
		nu1 *= i
	nu2 = nu1
	for i in range(k1 + 1, k2 + 1):
		nu2 *= i
	for i in range(o1 - k1, o1):
		de1 *= i
	for i in range(o2 - k2, o2):
		de2 *= i
	return de1 * de2 * x // (nu1 * nu2 * y)

def invmod(x, m=1000000007):
	from math import log
	pw = m - 2
	z = 1
	while pw > 1:
		y = x
		k = int(log(pw, 2))
		pw -= 2 ** k
		for i in range(k):
			y = y * y % m
		z *= y
		z %= m
	if pw == 1:
		z *= x
		z %= m
	return z
if abs(B - D) > 1 or (B == D == 0 and (A > 0 and C > 0)):
	print(0)
elif B == D == 0 and min(A, C) == 0 and (A != C):
	print(1)
elif B == D == A == C == 0:
	print(2)
else:
	a = A + B
	c = C + D
	if B == D:
		if min(A, B, C, D) < 8000:
			count = comb3(a - 1, A, c - 1, C, a + c, B)
		else:
			count = comb2(a - 1, A, c - 1, C, a + c, B)
	if B != D:
		e = min(B, D)
		count = comb2(A + e, A, C + e, C)
	print(count % 1000000007)


import sys
MOD = 10 ** 9 + 7

def bins(nbins, nitems):
	if nbins == 0:
		return 1 if nitems == 0 else 0
	return comb(nitems + nbins - 1, nbins - 1)

def comb(n, f, MOD=MOD):
	if f > n - f:
		f = n - f
	denom = numer = 1
	for i in range(f):
		denom = denom * (i + 1) % MOD
		numer = numer * (n - i) % MOD
	return numer * pow(denom, MOD - 2, MOD) % MOD
(A, B, C, D) = input().strip().split(' ')
(RR, RB, BB, BR) = [int(A), int(B), int(C), int(D)]
if RB == BR:
	print((bins(RB + 1, RR) * bins(RB, BB) + bins(RB, RR) * bins(RB + 1, BB)) % MOD)
elif abs(BR - RB) == 1:
	x = max(RB, BR)
	print(bins(x, RR) * bins(x, BB) % MOD)
else:
	print(0)


from sys import exit
(a, c, b, d) = map(int, input().split())
m = int(1000000000.0 + 7)
res = 0
l = [a, b, c, d]
if l == [0, 0, 0, 0]:
	print(2)
	exit(0)
if l == [a, 0, 0, 0] or l == [0, b, 0, 0] or l == [0, 0, 1, 0] or (l == [0, 0, 0, 1]):
	print(1)
	exit(0)
if l == [a, b, 0, 0]:
	print(0)
	exit(0)

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

def modinv(a, m):
	(g, x, y) = egcd(a, m)
	return x % m

def ch(N, K):
	ret = 1
	for k in range(min(K, N - K)):
		ret = ret * (N - k) % m
		ret = ret * modinv(k + 1, m) % m
	return ret
k = max(c, d)
A = ch(a + k - 1, k - 1)
B = ch(b + k - 1, k - 1)
if c == d + 1:
	res += A * B % m
if c == d:
	res += ch(a + k, k) * B % m
if d == c + 1:
	res += B * A % m
if c == d:
	res += ch(b + k, k) * A % m
print(res % m)


def inv(x):
	return pow(x, 10 ** 9 + 5, 10 ** 9 + 7)

def cc(n, k):
	if n < k:
		print(0)
		quit()
	a = 1
	for i in range(k + 1, n + 1):
		a *= i
		a %= 10 ** 9 + 7
	for i in range(1, n - k + 1):
		a = a * inv(i) % (10 ** 9 + 7)
	return a
(a, b, c, d) = map(int, input().split(' '))
if a == b == c == d == 0:
	print(2)
	quit()
if abs(b - d) > 1:
	print(0)
	quit()
if b == c == d == 0:
	print(1)
	quit()
if b - d == 1:
	(a, b, c, d) = (c, d, a, b)
if b != d:
	print(cc(a + d - 1, a) * cc(c + d - 1, c) % (10 ** 9 + 7))
else:
	x = cc(a + d, a) * cc(c + d - 1, c) % (10 ** 9 + 7)
	y = cc(a + d - 1, a) * cc(c + d, c) % (10 ** 9 + 7)
	print((x + y) % (10 ** 9 + 7))


from math import factorial

def calculatePermutations(n, g):
	if g == 1:
		return 1
	return factorial(n + g - 1) // (factorial(n) * factorial(g - 1))
(A, B, C, D) = input().strip().split(' ')
(A, B, C, D) = [int(A), int(B), int(C), int(D)]
if A == 0 and B == 0 and (C == 0) and (D == 0):
	print(2)
	exit()
result = 0
g = max(B, D)
if abs(B - D) == 1:
	result = calculatePermutations(A, g) * calculatePermutations(C, g)
elif abs(B - D) == 0:
	resultAbig = calculatePermutations(A, g + 1)
	resultCbig = calculatePermutations(C, g + 1)
	try:
		resultAsmall = resultAbig * g // (A + g)
		resultCsmall = resultCbig * g // (C + g)
		result = resultAbig * resultCsmall
		result += resultCbig * resultAsmall
	except Exception as e:
		if g == 1:
			result = resultAbig + resultCbig
		else:
			resultAsmall = resultAbig * (g + 1) // (A + g + 1)
			resultCsmall = resultCbig * (g + 1) // (C + g + 1)
			result = resultAbig * resultCsmall
			result += resultCbig * resultAsmall
print(result % (10 ** 9 + 7))


def Ckn(n, k):
	n += k - 1
	f = t = 1
	if k < n - k:
		k = n - k
	for i in range(k + 1, n + 1):
		f = f * i % 1000000007
	for i in range(2, n - k + 1):
		t = t * i % 1000000007
	return f * pow(t, 1000000005, 1000000007) % 1000000007

def calc(A, B, C, D):
	if B < D or B - D > 1:
		return 0
	if B == 0 and C > 0:
		return 0
	if A > 0 and C > 0 and (B + D == 0):
		return 0
	if A + B + C + D == 0:
		return 1
	return Ckn(D + 1, A) * Ckn(B, C)
(A, B, C, D) = map(int, input().split())
print((calc(A, B, C, D) + calc(C, D, A, B)) % 1000000007)


P = 1000000007
import sys

def facmod(n):
	r = 1
	for i in range(1, n + 1):
		r *= i
		r %= P
	return r

def invmod(n):
	return pow(n, P - 2, P)

def binmod(n, k):
	return facmod(n) * invmod(facmod(k) * facmod(n - k) % P) % P

def chose(n, k):
	return binmod(n + k - 1, k - 1)
(A, B, C, D) = input().strip().split(' ')
(A, B, C, D) = [int(A), int(B), int(C), int(D)]
res = 0
if B == 0 and D == 0:
	if A != 0 and C != 0:
		res = 0
	elif A == 0 and C == 0:
		res = 2
	else:
		res = 1
elif B == D:
	res = chose(A, B) * chose(C, B + 1) + chose(A, B + 1) * chose(C, B)
elif B - D == 1:
	res = chose(A, B) * chose(C, B)
elif D - B == 1:
	res = chose(A, D) * chose(C, D)
else:
	res = 0
print(res % P)


from os.path import basename, exists, expanduser, splitext, isfile
from os import getcwd
from sys import stdin
from array import array as ar
from collections import Counter
from functools import reduce as red
from math import sqrt
import itertools as it
from itertools import accumulate as acc, permutations as per
from copy import deepcopy
from random import randint
lolPath = getcwd()
randid = '\\qosdjfoiz.txt'
home = isfile(lolPath + randid)

def inv(n):
	return pow(n, modo - 2, modo)
if home:
	filou = lolPath + '\\AlienFloIn21.txt'
	filin = 'D:\\ZeDaddy\\Documents\\Hack\\combinatorics\\JourneyOu03.txt'
	from mesures import ch
else:
	filou = None
modo = 10 ** 9 + 7

def countDispos(N, nz, pr=0):
	return red(lambda x, y: x * (y + N + 1) * inv(y + 1) % modo, range(nz - 1), 1)

def lessStup(LiP):
	(RR, RB, BB, BR) = LiP
	if abs(RB - BR) > 1:
		return 0
	if RB == BR:
		if RB == 0:
			return 0 if RR != 0 and BB != 0 else 2 if RR == 0 and BB == 0 else 1
		return (countDispos(RR, RB + 1) * countDispos(BB, RB) + countDispos(RR, RB) * countDispos(BB, RB + 1)) % modo
	elif RB > BR:
		return countDispos(RR, RB) * countDispos(BB, RB) % modo
	return countDispos(RR, BR) * countDispos(BB, BR) % modo
trace = 0
rd = open(filou) if filou else stdin
if home:
	prv = 0
else:
	trace = 0
if home:
	Rng = range(int(rd.readline().strip()))
else:
	Rng = range(1)
for _ in Rng:
	LiP = list(map(int, rd.readline().strip().split()))
	if home:
		print(LiP)
	for f in (lessStup,):
		if home:
			cr = ch()
		r = f(LiP)
		if home:
			t = cr.lap()
			print(f.__name__, r, t)
			prv = r
		else:
			print(r)


P = 1000000007
import sys

def facmod(n):
	r = 1
	for i in range(1, n + 1):
		r *= i
		r %= P
	return r

def invmod(n):
	return pow(n, P - 2, P)

def binmod(n, k):
	return facmod(n) * invmod(facmod(k) * facmod(n - k) % P) % P

def chose(n, k):
	return binmod(n + k - 1, k - 1)
(A, B, C, D) = input().strip().split(' ')
(A, B, C, D) = [int(A), int(B), int(C), int(D)]
res = 0
if B == 0 and D == 0:
	if A != 0 and C != 0:
		res = 0
	elif A == 0 and C == 0:
		res = 2
	else:
		res = 1
elif B == D:
	res = chose(A, B) * chose(C, B + 1) + chose(A, B + 1) * chose(C, B)
elif B - D == 1:
	res = chose(A, B) * chose(C, B)
elif D - B == 1:
	res = chose(A, D) * chose(C, D)
else:
	res = 0
print(res % P)


P = 10 ** 9 + 7

def inv_mod(n):
	return pow(n, P - 2, P)

def binom_mod(n, p):
	if not 0 <= p <= n:
		return 0
	res = 1
	for i in range(p):
		res = res * (n - i) * inv_mod(p - i) % P
	return res

def multiset(n, p):
	return binom_mod(n + p - 1, p)

def formula(RR, RB, BB, BR):
	res = 0
	if abs(RB - BR) == 1:
		S = max(RB, BR)
		res = multiset(S, RR) * multiset(S, BB) % P
	elif RB == BR:
		if RB == 0:
			if RR == BB == 0:
				res = 2
			elif min(RR, BB) == 0:
				res = 1
		else:
			res = (multiset(RB + 1, RR) * multiset(RB, BB) + multiset(RB, RR) * multiset(RB + 1, BB)) % P
	return res
(RR, RB, BB, BR) = map(int, input().split())
print(formula(RR, RB, BB, BR))


MOD = 1000000007

def inv(x):
	return pow(x, MOD - 2, MOD)
f = [1]
fi = [1]
for i in range(1, 200001):
	n = f[i - 1] * i % MOD
	f.append(n)
	fi.append(inv(n))

def Cnk(n, k):
	return f[n] * fi[k] * fi[n - k] % MOD

def RR(rr, rb, bb, br):
	if rb != br:
		return 0
	if rb == 0:
		if rr * bb == 0:
			return 1
		else:
			return 0
	return Cnk(rb + rr, rr) * Cnk(rb - 1 + bb, bb) % MOD

def RB(rr, rb, bb, br):
	if rb != br + 1:
		return 0
	return Cnk(br + rr, rr) * Cnk(br + bb, bb) % MOD

def solve(rr, rb, bb, br):
	if rb == br == 0:
		if rr == bb == 0:
			return 2
		elif rr * bb == 0:
			return 1
		else:
			return 0
	return (RR(rr, rb, bb, br) + RB(rr, rb, bb, br) + RR(bb, br, rr, rb) + RB(bb, br, rr, rb)) % MOD
print(solve(*list(map(int, input().split()))))


P = 1000000007
import sys

def facmod(n):
	r = 1
	for i in range(1, n + 1):
		r *= i
		r %= P
	return r

def invmod(n):
	return pow(n, P - 2, P)

def binmod(n, k):
	return facmod(n) * invmod(facmod(k) * facmod(n - k) % P) % P

def chose(n, k):
	return binmod(n + k - 1, k - 1)
(A, B, C, D) = input().strip().split(' ')
(A, B, C, D) = [int(A), int(B), int(C), int(D)]
res = 0
if B == 0 and D == 0:
	if A != 0 and C != 0:
		res = 0
	elif A == 0 and C == 0:
		res = 2
	else:
		res = 1
elif B == D:
	res = chose(A, B) * chose(C, B + 1) + chose(A, B + 1) * chose(C, B)
elif B - D == 1:
	res = chose(A, B) * chose(C, B)
elif D - B == 1:
	res = chose(A, D) * chose(C, D)
else:
	res = 0
print(res % P)


import math
import os
import random
import re
import sys
M = 1000000007

def factorial_mod(x):
	result = 1
	for i in range(1, x + 1):
		result = result * i % M
	return result

def inverse_mod(x):
	return pow(x, M - 2, M)

def binomial_mod(n, k):
	return factorial_mod(n) * inverse_mod(factorial_mod(k) * factorial_mod(n - k) % M) % M

def nCk(n, k):
	return binomial_mod(n + k - 1, k - 1)
ABCD = input().split()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
result = 0
if B == 0 and D == 0:
	if A != 0 and C != 0:
		result = 0
	elif A == 0 and C == 0:
		result = 2
	else:
		result = 1
elif B == D:
	result = nCk(A, B) * nCk(C, B + 1) + nCk(A, B + 1) * nCk(C, B)
elif B - D == 1:
	result = nCk(A, B) * nCk(C, B)
elif D - B == 1:
	result = nCk(A, D) * nCk(C, D)
print(result % M)


import math
import os
import random
import re
import sys
mod = 1000000007
numfacts = 300000
factlist = [1]
for i in range(1, numfacts + 1):
	factlist.append(factlist[-1] * i % mod)
factinvlist = [0] * (numfacts + 1)
factinvlist[numfacts] = pow(factlist[numfacts], mod - 2, mod)
for i in range(numfacts, 0, -1):
	factinvlist[i - 1] = factinvlist[i] * i % mod

def choose(n, r):
	if n < 0 or r < 0 or r > n:
		return 0
	else:
		return factlist[n] * factinvlist[r] * factinvlist[n - r] % mod
ABCD = input().split()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])
if B > D + 1 or D > B + 1:
	print(0)
elif B == 0 and D == 0:
	if A == 0 and C == 0:
		print(2)
	elif A == 0 or C == 0:
		print(1)
	else:
		print(0)
elif B == D:
	print((choose(A + B, A) * choose(C + D - 1, C) + choose(A + B - 1, A) * choose(C + D, C)) % mod)
else:
	numreps = min(B, D)
	print(choose(numreps + A, A) * choose(numreps + C, C) % mod)


P = 1000000007
import sys

def facmod(n):
	r = 1
	for i in range(1, n + 1):
		r *= i
		r %= P
	return r

def invmod(n):
	return pow(n, P - 2, P)

def binmod(n, k):
	return facmod(n) * invmod(facmod(k) * facmod(n - k) % P) % P

def chose(n, k):
	return binmod(n + k - 1, k - 1)
(A, B, C, D) = input().strip().split(' ')
(A, B, C, D) = [int(A), int(B), int(C), int(D)]
res = 0
if B == 0 and D == 0:
	if A != 0 and C != 0:
		res = 0
	elif A == 0 and C == 0:
		res = 2
	else:
		res = 1
elif B == D:
	res = chose(A, B) * chose(C, B + 1) + chose(A, B + 1) * chose(C, B)
elif B - D == 1:
	res = chose(A, B) * chose(C, B)
elif D - B == 1:
	res = chose(A, D) * chose(C, D)
else:
	res = 0
print(res % P)


P = 1000000007
import sys

def facmod(n):
	r = 1
	for i in range(1, n + 1):
		r *= i
		r %= P
	return r

def invmod(n):
	return pow(n, P - 2, P)

def binmod(n, k):
	return facmod(n) * invmod(facmod(k) * facmod(n - k) % P) % P

def chose(n, k):
	return binmod(n + k - 1, k - 1)
(A, B, C, D) = input().strip().split(' ')
(A, B, C, D) = [int(A), int(B), int(C), int(D)]
res = 0
if B == 0 and D == 0:
	if A != 0 and C != 0:
		res = 0
	elif A == 0 and C == 0:
		res = 2
	else:
		res = 1
elif B == D:
	res = chose(A, B) * chose(C, B + 1) + chose(A, B + 1) * chose(C, B)
elif B - D == 1:
	res = chose(A, B) * chose(C, B)
elif D - B == 1:
	res = chose(A, D) * chose(C, D)
else:
	res = 0
print(res % P)