Reduce the numbers in the list modulo 3 to get the set
{1, 2, 0, 1, 2, 0, …, 1, 2, 0}
containing
copies each of 1, 2, and 0.
Take any 3 elements from the list. Their sum is divisible by 3 if those elements' residues also sum to 3 ≡ 0 (mod 3). To get a sum of 0, we must make one of the following choices:
- 3 elements each with the same residue, so
0 + 0 + 0 ≡ 0 (mod 3)
1 + 1 + 1 ≡ 3 ≡ 0 (mod 3)
2 + 2 + 2 ≡ 6 ≡ 0 (mod 3)
- 1 element each with different residues, so
0 + 1 + 2 ≡ 3 ≡ 0 (mod 3)
There are
![\dbinom k3 \dbinom k0 \dbinom k0 = \frac{k(k-1)(k-2)}6](https://img.qammunity.org/2023/formulas/mathematics/high-school/xll376lq4k0xe6csxhwye5iz5o4rzak6vv.png)
ways of choosing 3 elements with a given residue and 0 elements with any other residue, hence
![3\dbinom k3\dbinom k0\dbinom k0 = \frac{k(k-1)(k-2)}2](https://img.qammunity.org/2023/formulas/mathematics/high-school/fuwxe6ai0p1eum1gm54jddm24zdfrwmhw3.png)
ways of choosing any 3 elements with the same residue, and there are
![\dbinom k1 \dbinom k1 \dbinom k1 = k^3](https://img.qammunity.org/2023/formulas/mathematics/high-school/98waweth3nmjnziaxlnv84idlyhsy2lngz.png)
ways of choosing any 3 elements with distinct residues.
So, the total number of ways of making the selection is
![3\dbinom k3\dbinom k0^2 + \dbinom k1^3 = \boxed{\frac32 k^3 - \frac32 k^2 - k}](https://img.qammunity.org/2023/formulas/mathematics/high-school/hzb92sew23uq2t8kg58k2kbzkvinfybhm4.png)