Ruby solutions for Spoj problems