Working fast solution
Simpler solution as SPOJ cannot measure difference in speed