Codeforces Solution In Java