My attempt to solve SPOJ Questions