SPOJ Problem Rectangles Solution