On SPOJ or elsewhere? I took some hours to solve and this problem and really enjoyed it. I want to practice solving some more problem of this kind.