Codeforces tasks solution on Java.