Number of ways to distribute $n$ objects into $k$ distinguishable groups with constraints on the max size of each group? We have $x_1+x_2+...+x_k=n$ for some integers $k,n$. We have that $0 \leq x_1,...,x_k$ and individually $x_1 \leq a_1$, $x_2 \leq a_2$, ..., $x_k \leq a_k$.
How many integer solutions are there to this problem?
The solution when there are no constraints to the maximum number of objects in any individual bin is just the "stars and bars" method, but what about for this more constrained version?
 A: See Balls in Bins with Limited Capacity.
We have $k$ constraints with indices in $[1,k]$. There are
$$
\binom{n+k-1-\sum_{j\in S}\left(a_j+1\right)}{k-1}
$$
integer solutions that violate the constraints with indices in $S$. Thus by inclusion–exclusion there are
$$
\sum_{S\subseteq[1,k]}(-1)^{|S|}\binom{n+k-1-\sum_{j\in S}\left(a_j+1\right)}{k-1}
$$
integer solutions that violate none of the constraints (where, contrary to the usual convention, the binonial coefficients are to be taken as zero if the upper index is negative).
A: In order to show that the generating function approach gives the same answer as the Inclusion-Exclusion approach, I have changed the variables in my answer to match those in joriki's answer.

The generating function for the number of ways to distribute $n$ identical objects across $k$ bins with sizes $\{a_j\}_{j=1}^k$ is
$$
\begin{align}
\prod_{j=1}^k\left(1+x+x^2+\cdots+x^{a_j}\right)
&=\prod_{j=1}^k\frac{1-x^{a_j+1}}{1-x}\\
&=\prod_{j=1}^k\left(1-x^{a_j+1}\right)\sum_{i=0}^\infty(-1)^i\binom{-k}{i}x^i\\
&=\bbox[5px,border:2px solid #C0A000]{\prod_{j=1}^k\left(1-x^{a_j+1}\right)\sum_{i=0}^\infty\binom{i+k-1}{k-1}x^i}\tag1
\end{align}
$$

Expanding the product in $(1)$ gives
$$
\prod_{j=1}^k\left(1-x^{a_j+1}\right)=\sum_{S\subset[1,k]}(-1)^{|S|}x^{\sum_{j\in S}(a_j+1)}\tag2
$$
For a given $S$, to get the coefficient of $x^n$ in $(1)$, we choose $i=n-\sum_{j\in S}(a_j+1)$. That is, the coefficient of $x^n$ in $(1)$ is
$$
\bbox[5px,border:2px solid #C0A000]{\sum_{S\subset[1,k]}(-1)^{|S|}\binom{n-\sum_{j\in S}(a_j+1)+k-1}{k-1}}\tag3
$$
which matches joriki's answer.
