Insane Problem Codeforces Solution In Python