My code for tackling some of the better spoj problems