30. (MON 1) Given $m+n$ numbers $a_{i}(i=1,2, \ldots, m), b_{j}(j=1,2, \ldots, n)$, determine the number of pairs $\left(a_{i}, b_{j}\right)$ for which $|i-j| \geq k$, where $k$ is a nonnegative integer.
30. We assume w.l.o.g. that $m \leq n$. Let $r$ and $s$ be the numbers of pairs for which $i-j \geq k$ and of those for which $j-i \geq k$. The desired number is $r+s$. We easily find that
$$
\begin{array}{l}
r=\left\{\begin{array}{ll}
(m-k)(m-k+1) / 2, & k<m, \\
0, & k \geq m,
\end{array}\right. \\
s=\left\{\begin{array}{ll}
m(2 n-2 k-m+1) / 2, & k<n-m, \\
(n-k)(n-k+1) / 2, & n-m \leq k<n, \\
0, & k \geq n .
\end{array}\right.
\end{array}
$$