There are S people swimming in the pool.
At some point, the coach notices that their distribution over pool lanes is quite uneven, which is a nuisance for pool visitors. Changing the lane across ropes, however, poses a nuisance for a swimmer.
To form a nice distribution over the lanes the number of swimmers on each pair of adjacent lanes should differ by at most one. In particular, an empty lane should only be adjacent to another empty one or a lane occupied by only one swimmer.
Your task is to calculate the minimum number of swimmers’ lane changes needed to meet this condition.