solutions to some of the spoj problems