Cardinality of a set Consider four variables  $x,y,z,w$.
Also consider the set $S=\{x^{i_1+j_1}y^{i_2+j_2}z^{j_1+j_3}w^{j_2+j_4}\}$ where
$i_1,i_2,j_1,j_2,j_3,j_4$ are nonnegative integers such that
$i_1+i_2+j_1+j_2 =m$ and $0\leq j_3,j_4 \leq m_1$ with  $m,m_1$ are positive integers. 
What is the cardinality of the set $S$ in terms of $m,m_1$? 

Since $i_1+i_2+j_1+j_2 =m$, $S=\{x^{i_1+j_1}y^{i_2+j_2}z^{j_1+j_3}w^{j_2+j_4}\}$ can be written as $S=\{x^{m-i_2-j_2}y^{i_2+j_2}z^{j_1+j_3}w^{j_2+j_4}\}$. Since $i_1,i_2,j_1,j_2,j_3,j_4$ are nonnegative integers, $m-i_2-j_2=i_1+j_1\geq0$, we have $m\geq i_2+j_2\geq0$. So there are $m+1$ distinct $x^{m-i_2-j_2}y^{i_2+j_2}$ when $i_2+j_2=0,1,..., m$. 
Now fix $k=0,1,..., m$. If $i_2+j_2=k$, then the possible values for $j_2$ are $0,1,2,..., k$. On the other hand, since $i_1+j_1=m-i_2-j_2=m-k$, the possible values for $j_1$ are $0,1,2,..., m-k$. Therefore, if $i_2+j_2=k$, $0\leq j_1+j_3\leq k+m_1$ and $0\leq j_2+j_4\leq m-k+m_1$. That is, if $x^{m-i_2-j_2}y^{i_2+j_2}=x^{m-k}y^k$, the number of possible $z^{j_1+j_3}w^{j_2+j_4}$ are $(k+m_1+1)(m-k+m_1+1)$. 
Combining all these, the cardinality of the set $S$ is 
$$|S|=\sum_{k=0}^m(k+m_1+1)(m-k+m_1+1).$$
