Solutions to SPOJ problems