The Fair Nut and Rectangles

CodeForces - 1083E