Need help with painless scripting

In your script you have 2 lists. e and c. The error is that you are referencing a list item that is not there. You need to test if the lists are filled before you de-reference them.

This might help: