Watching Fireworks is Fun

CodeForces - 372C