How many ways can we give $19$ identical pieces of candy to $6$ people so that everyone gets at most $5$ pieces? My solution was to first take the total amount of ways to distribute the candies $24\choose19$ and subtract the number of ways someone can get more than $5$. First I chose one person to give six candies to: $6\choose1$. Then I multiplied that by the number of ways to distribute the rest of the candies: $18\choose13$. So in total that gave me ${24\choose19} - 6 {18\choose13}$ ways to distribute these candies. But my teacher said the subtracted portion overcounted. Why is this the case? And what is a proper solution to this problem?
I know this question was recently asked, but I'm asking it mainly for clarification of my first question.
 A: You are counting the number of integer solutions to $$x_1 +x_2 + x_3 + x_4 + x_5 + x_6 = 19, \text{ where } \forall i: x_i \le 5$$  Here $x_i$ is the amount given to person $i$, of course.
This is the same as the coefficient of $x^{19}$ in the product
$$(1+ x+x^2 + x^3+x^4 + x^5)^6$$ and this last formula can be written as 
$$\left(\frac{1-x^6}{1-x}\right)^6 = (1-x^6)^6 (1-x)^{-6}$$ which using the (generalised ) binomial formulas comes down to finding the coefficient of $x^{19}$ in
$$\left(1 - 6x^6 + {6 \choose 2}x^{12} - {6 \choose 3}x^{18} + {6 \choose 4}x^{24} - 6x^{30} + x^{36}\right)\sum_{k=0}^\infty {k+5 \choose k}x^k$$
This will give you an alternating sum of products of binomial coefficients:
$${24 \choose 5} - {6 \choose 1}{18 \choose 13} + {6 \choose 2}{16 \choose 13} - {6 \choose 3}{6 \choose 1}$$ which already suggests (inclusion-exclusion) how to correct your overcounting. 
If you're only interested in the answer and are online, you could use Wolfram alpha to find the answer 2856 right from the first expansion.
A: The number of ways $19$ pieces of candy can be distributed to six people if no person receives more than five pieces is the number of solutions in the nonnegative integers of the equation 
$$x_1 + x_2 + x_3 + x_4 + x_5 + x_6 = 19 \tag{1}$$
subject to the restrictions $x_k \leq 5$, $1 \leq k \leq 6$.  You correctly found that if there were no restrictions that equation 1 would have 
$$\binom{19 + 6 - 1}{6 - 1} = \binom{24}{5} = \binom{24}{19}$$
solutions.  
If we first give one person six pieces of candy, we have $19 - 6 = 13$ pieces of candy left to distribute to six people.  The number of ways we can distribute the remaining $13$ pieces of candy is the number of solutions in the nonnegative integers of the equation
$$x_1 + x_2 + x_3 + x_4 + x_5 + x_6 = 13 \tag{2}$$
which is 
$$\binom{13 + 6 - 1}{6 - 1} = \binom{18}{5} = \binom{18}{13}$$
Since there are six ways to choose the person who receives six pieces of candy, you subtracted 
$$\binom{6}{1}\binom{18}{13} = \binom{6}{1}\binom{18}{5}$$
from the total number of solutions.  As your instructor told you, this under counts the number of ways of distributing the candy.  What you did not take into account is that more than one person may receive more than five pieces of candy.  
Notice that in each case in which two people receive at least six pieces of candy, you have subtracted twice, once for each way you could have initially chosen one of them to give one of them six pieces of candy.  We only want to subtract them once, so we must add the number of cases in which two people receive at least six pieces of candy to the total you found.
There are $\binom{6}{2}$ to choose two people to give six pieces of candy.  Once those candies have been distributed, we are left with $19 - 2 \cdot 6 = 7$ pieces of candy to distribute to six people.  The number of ways we can distribute those candies is the number of solutions of the equation 
$$x_1 + x_2 + x_3 + x_4 + x_5 + x_6 = 7 \tag{3}$$
in the nonnegative integers, which is 
$$\binom{7 + 6 - 1}{6 - 1} = \binom{12}{5} = \binom{12}{7}$$
Hence, there are 
$$\binom{6}{2}\binom{12}{5}$$
cases in which two people are given six pieces of candy.  Adding this correction term yields
$$\binom{24}{5} - \binom{6}{1}\binom{18}{5} + \binom{6}{2}\binom{12}{5}$$ 
This is still not right.  We subtracted each case in which three people receive at least six pieces of candy three times when we subtracted cases in which one person is given six pieces of candy, once for each way we could have chosen to give one of them six pieces of candy.  We then added each case in which three people receive at least six pieces of candy three times when we added cases in which two people are each given six pieces of candy, once for each of the $\binom{3}{2}$ ways we could have chosen to give two of the three people six pieces of candy.  Hence, we have not counted these cases at all.  However, we must exclude them.
If we give three people six pieces of candy, we are left with $19 - 3 \cdot 6 = 1$ piece of candy to distribute to six people.  Since there are $\binom{6}{3}$ ways to choose which three of the six people will be given six pieces of candy and six ways to distribute the remaining piece of candy, there are 
$$6\binom{6}{3}$$
ways to distribute the candies if three people are given six pieces of candy.  
Subtracting this from the total yields
$$\binom{24}{19} - \binom{6}{1}\binom{18}{5} + \binom{6}{2}\binom{12}{5} - \binom{6}{3}\binom{6}{5}$$
ways to distribute $19$ identical pieces of candy to six people if no person receives more than five pieces.  
Note that this argument is based on the Inclusion-Exclusion Principle.  
