The Ruby solution on codeforces