solutions for spoj problems