Solutions for SPOJ problems