Problem: Suppose that the set $\{1,2,\dots, 1998\}$
has been partitioned into disjoint pairs $\{a_i,b_i\}$ ($1\leq i\leq 999$)
so that for all $i$, $|a_i-b_i|$ equals $1$ or $6$.
Prove that the sum
\[ |a_1-b_1|+|a_2-b_2|+\dotsb +|a_{999}-b_{999}|  \]
ends in the digit $9$.

Solution: Let $S$ be the sum.
Modulo $2$,
\[ S = \sum |a_i-b_i| \equiv \sum (a_i+b_i)
  = 1 + 2 + \dots + 1998 \equiv 1 \pmod 2. \]
Modulo $5$,
\[ S = \sum |a_i-b_i| = 1 \cdot 999 \equiv 4 \pmod 5. \]
So $S \equiv 9 \pmod{10}$.