Optimal gems

1.7

3 votes
Open, Open, Open, Dynamic Programming, 4D dynamic programming, Data Structures, Medium, Algorithms, 4 Dimensional, approved
Problem

You are given four different types of gems that are denoted by G1, G2, G3, and G4. Their quantity is given by n1, n2, n3, and n4 respectively. You are required to arrange these gems in a straight line next to each other. However, in this arrangement, you want no two gems of the same type to be adjacent to each other.

Your task is to determine the number of distinct arrangements of the gems that exist. If yes, print the answer modulo 109+7

Input format

The only line of the input contains four integers denoting the number of available gems of each type.

Output format

Print the required answer modulo 109+7.

Constraints

0n1,n2,n3,n420

Sample Input
1 1 0 0
Sample Output
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

There are two ways to arrange gems :

  1. G1 G2

  2. G2 G1

Contributers:
Editor Image

?