Counting Rectangles is Fun

CodeForces - 372B