Seven matchboxes are arranged in a circle. The first contains 19 matches, the second contains 9 matches, and the remaining ones contain 26, 8, 18, 11 and 14 matches respectively. It is permissible to move the matches from any box to any adjacent box. The matches must be shifted in such a way that the number of matches in all boxes becomes the same. How can this be done, shifting as few matches as possible?
from "Functions and Graphs" by Gelfand
So each box should contain $\frac{105}{7} = 15$ matches. I had a look at the solution of the problem, it says:
Let $x$ denote the number of matches that must be shifted from the first to the second box. [...] After we have shifted $x$ matches from the first box to the second, there will be $x+9$ matches in the second box.
That makes intuitively sense, we might need to shift $x$ matches (where $x$ can be positive or negative) from the first box, and as the second box contains 9, after the shift occurred, we will have $x+9$ matches there. It continues:
Therefore it is necessary to move $x-6$ matches from the second to the third, $x+5$ matches from the third to the fourth. [...]
Let $S$ denote the total number of shifted matches:
$$S= |x| + |x-6| + |x+5| + |x-2| + |x+1| + |x-3| + |x-4|$$
I got stuck there, because I can't make sense of why we would need to shift $x-6$ from the second to the third? I would have expected to move $6$ from the third to the second.
I got this.............................