Help me resolve a run-time error please.

Following is my solution to the deputy chef problem.An NZEC run-time error is occuring when I submit this solution.I read a little about NZEC but could not figure out why it is occuring in my prrogram and what should I do to remove it.Please can anyone help me with this?Thanks.Here is my solution.

In line 9 : n should be n-1 as n will cause out of range error.
In line 11 : You should compare with n-1 as range function iterates till n-1
In line 12 : n-1 should be n-2 and similarly n should be n-1
In line 15&16 : you have used i => it should be j