solve the medium (10 power 14) case for fair and square problem