P5784 [CQOI2008] Number of Matrices

Description

Given the sums of each row and each column of an $n \times 3$ non-negative integer matrix, count how many matrices satisfy these conditions. Output the answer modulo $10^{17}$.

Input Format

The first line contains four positive integers $N$, $c_1$, $c_2$, $c_3$, representing the number of rows and the sums of the three columns. The second line contains $N$ positive integers, representing the sum of the three numbers in each row. The sum of each row and each column does not exceed $125$.

Output Format

Output one number: the number of matrices satisfying the conditions modulo $10^{17}$.

Explanation/Hint

| Test Point ID | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | :----------: | | $N$ | $1$ | $2$ | $3$ | $10$ | $30$ | $50$ | $80$ | $120$ | $150$ | $200$ | Translated by ChatGPT 5