First note that if any ai=1, then ci is always 0, so the total score sum is 0, which is certainly divisible by S. Hence in what follows we only discuss the case where every color of mantou has at least 2 pieces, in which case S≥2n.
1. We first compute the total score sum by double counting. For convenience of explanation, let Mji denote the mantou of color i numbered j, and an arrangement is then a string obtained by lining up all S of the Mji. For each arrangement, its score is equivalent to the number of ways of choosing, from this arrangement, an adjacent pair for each color.
Therefore we can instead compute, for each color, the number of arrangements facing a designated (ordered) adjacent pair:
- The number of ways to place n pairs into S slots is (S−2n)!(S−n)!.
- The remaining S−2n positions have (S−2n)! arrangements in total.
Hence for each color's designated (ordered) adjacent pair, the number of arrangements facing it is (S−2n)!, and the number of designated (ordered) adjacent pairs for each color in total is ∏iai(ai−1), so the total score sum is
P=(S−n)!(a1)(a1−1)(a2)(a2−1)⋯(an)(an−1).
2. Next we prove that S∣P.
- Lemma: If S is composite, and S∤⌊2S⌋!, then S=4 or 9.
Proof: If S is not the square of a prime, find S=pq,p=q, then p,q are both within ⌈2S⌉, so S∣⌈2S⌉!.
If S=p2 with p≥5, then p,2p are both within ⌈2S⌉, so S∣⌈2S⌉!.
So the only remaining counterexamples are S=4 or 9.
- Since (S−n)≥⌈2S⌉, we only need to discuss S=4 or 9.
When S=4, if n=1 the score is 72, if n=2 then it must be that a1=a2=2, and the score is 8.
When S=9, note that 9∣6!, so n>3⟹n=4.
Splitting 9 into a sum of four positive integers each at least 2, one of them must be 3, so (9−4)!(a1)(a1−1)(a2)(a2−1)…(a4)(a4−1) is a multiple of 9, which completes the proof.