Suppose that the set \{1, 2, ..., 1998\} has been partitioned into disjoint pairs \{a_i, b_i\}, i = 1, 2, ..., 999, so that for all i, |a_i - b_i| is either 1 or 6. Prove that the sum

|a_1 - b_1| + |a_2 - b_2| + ... + |a_{999} - b_{999}|

ends in the digit 9.

Solution