codeforces solution in perl