Accepted solution in SPOJ with 1.81s and 1399M