Solutions to SPOJ (Sphere Online Judge) problems