# Finding the number of solutions for an equation using Principle of Inclusion and Exclusion

Given that $$x_1 + x_2 + x_3 + x_4 + x_5 = 30$$ find the number non-negative integer solutions which satisfy the restrictions $x_1 \leq 5$ and $x_2 \geq 7$.

I found the number of solutions when the first restriction, $x_2\geq 7$, is applied. $$C(27, 4) = 17550$$ I also found the number of solutions when the second restriction, $x_1 \leq 5$, is applied. $$C(34, 4) - C(28, 4) = 25901$$ Now I have to apply Principle of Inclusion and Exclusion. But I don't know how to find the intersection that combines the first and second restriction.

How do I do it?

Without restrictions: we count the ways to place 30 "balls" into 5 "boxes". $$\binom{30+4}{4}$$
With restriction $\{X_2\geq 7\}$ we place the minimum of 7 "balls" into "box" two, and count the ways to place the remaining $23$ balls into the five "boxes".$$\binom{30-7+4}{4}$$
With restriction $\{X_1\leq 5\}$ we subtract the count for $\{X+1\geq 6\}$ from the unrestricted case.$$\binom{30+4}{4}-\binom{30-6+4}{4}$$
Applying both restrictions at once, $\{X_1\leq 5, X_2\geq 7\}$ is counted by substracting ways to fill restriction $\{X_1\geq 6, X_2\geq 7\}$ from ways to fill restriction $\{X_2\geq 7\}$.
$$\binom{30-7+4}{4}-\binom{30-7-6+4}{4}$$