Solutions for SPOJ