A group of pirates have plundered one of his majesty's cargo ships and they all carried as much gold coins as each one could find. When they get back to their ship, they sit at a round table and pass their gold around to the person to their left or right until each person has an equal number of gold coins.
Suppose there are $n$ pirates, $n$ seats at the table, each pirate can only pass coins to the pirate on his (no female pirates on this ship) left or right, the total number of coins $M$ is an integer multiple of $n$, the pirates are arbitrarily numbered, say clockwise, starting from some pirate seated in some fixed seat and $a_i$ is the number of coins belonging to pirate $i$. Furthermore, assume all pirates can see how many coins each pirate has, so they know $a_1,...,a_n$ as well as $M=\sum_{i=1}^n a_i$.
One way to accomplish this would be to have every pirate who has more than $\frac{M}{n}$ coins pass their excess to the right; continue doing this at most $n$ times until everyone has exactly $\frac{M}{n}$ coins.
For example, suppose there are $5$ pirates and
$a_1=15, a_2=a_3=0,a_4=50,a_5=0$
After round one, they would have:
$a_1=13, a_2=2,a_3=0,a_4=13,a_5=37$
After each of the next rounds, they would have:
$a_1=37, a_2=2,a_3=0,a_4=13,a_5=13$
$a_1=13, a_2=26,a_3=0,a_4=13,a_5=13$
$a_1=13, a_2=13,a_3=13,a_4=13,a_5=13$
However, one pirate decides that there might be a more efficient way. He counts that there were $2+37$ coins passed in the first round, $24$ passed in the second, $100$ passed in all. He found a way so that a much smaller number of coin passes could be done:
$a_1=13, a_2=2, a_3=24,a_4=13,a_5=13$
$a_1=13, a_2=13, a_3=13,a_4=13,a_5=13$
This way only requires $50$ coin passes. Note: pirate $1$ can pass to either pirate $2$ or pirate $n$, pirate $n$ can pass to $1$ or $n-1$, any other pirate $i\in (2,...,n-1)$ can pass to either $i-1$ or $i+1$.
The captain hears this and says "Avast ye. As much as I love coin passing I love other things like drinking and plundering even more. Me and me hearties have been passing these doubloons like a bunch of landlubbers. If ye could devise a strategy that would pass the least amount of doubloons, I would be much obliged."
How should they pass the coins to have the least number of coin passes given any valid starting number of coins and pirates?
The theme is related to the puzzle here. But, that requires all to pass half of their coins to the right only and requires the captain (not sitting at the table) to give 1 coin to each pirate with an odd number of coins after each round (so all pirates will always have an even number of coins).