Stones on the Table

CodeForces - 266A