Say you have $M$ bins and $N$ balls, and each bin can only be filled with $C$ balls. At step zero, all bins are empty. Then at each step, one of the $M$ bins is chosen with equal probability, and a ball is "dropped" onto it. If the bin is filled with less than $C$ balls, its ball count is increased by 1. If it is filled with $C$ balls, the ball falls to the floor. After $N$ steps (i.e. all balls are used), what is the mean number of balls on the floor?
This stack exchange question is nearly the same, but the answer is not explained, appears to not be general, and debated in a comment.
Define $A_i$ as the number of balls assigned (randomly) to bin $i$. The residual of each bin $i$ overflowing on the floor is given by
$$R_i=\max ( A_i-C, 0 ).$$
Considering that each $A_i$ follows the binomial distribution with parameters $n=N$ and $p=1/M$, the expectation of $R_i$ is given by
$$\mathbb{E}(R_i)=\sum_{i=C+1}^N (i-C){N \choose i } \ \left (\frac{1}{M}\right ) ^i \left (\frac{M-1}{M}\right )^{N-i}.$$
Considering $R=\sum_{i=1}^M R_i$ and that $\mathbb{E}(U+V)=\mathbb{E}(U)+\mathbb{E}(V)$ whenever both $\mathbb{E}(U)$ and $\mathbb{E}(V)$ are finite (i.e., $U \text{ and } V \in L_1(\Omega,\mathcal{F},P)$; $U$ and $V$ can be dependent), the expectation of all the residuals can be obtained as follows:
$$\mathbb{E}(R)=\sum_{i=1}^M \mathbb{E}(R_i)=M \times \mathbb{E}(R_1)=\left (\frac{1}{M} \right )^{N-1} \sum_{i=C+1}^N (i-C){N \choose i }(M-1)^{N-i}. $$
This can be simplified to
$$\mathbb{E}(R)={\left (\frac{1}{M} \right )^{N-1}} \left ( N \sum_{j=C}^{N-1} {N-1 \choose j }(M-1)^{N-1-j}- C \sum_{i=C+1}^N {N \choose i }(M-1)^{N-i} \right ) $$
or based on the CDFs of two binomial random variables:
$$\mathbb{E}(R)=M \left [ C\, \mathbb{P}\left (W(N) \le C\right ) - N\, \mathbb{P}\left (W(N-1)\le C-1\right ) +N-C \right ] $$
with $W(N) \sim \text{Binomial}(N,1/M)$ and $W(N-1) \sim \text{Binomial}(N-1,1/M)$. You can see that the expectation becomes zero for $C=N$.
The latter can be used to compute the expectation in R or python, or to approximate the expectation using CLT when $N$ is sufficiently large.