Solution to some SPOJ problems