This is a 1000-points question which is relatively easy as it is not true competition problem. And basically I can finish it with almost no debugging as it is a kind of straight-forward. My idea is to avoid recursion by using a queue to push/pop context. I browse some other guys code, they are very condensed and short. Mine is always KISS with a lot of data structures. Their code is a sort of efficient.