C solutions for Spoj problems