Equalize the Remainders

CodeForces - 999D