Solve this interesting problem

HDU - 5323