solutions to spoj problems