Mex ception problem doubt

My link of solution to the problem Mex ception which appeared in july cook off is pasted below .
Please help to find out what is wrong in its submission.I am getting wrong answer but not able to figure out why.Please help someone .

Gives WA on 1 1.