Approach hintTry it first, then revealHide
For each direction keep an ordered set of cut positions and a multiset of segment lengths. A new cut replaces one length with two; the answer is the largest width times the largest height, in 64-bit arithmetic.