[SRM582] SemiPerfectSquare by Yanzhe Chen