Need help in spooky sequences , starters 105

Can any one explain where am i messing up, i am getting tle in this problem

SPOOKYSEQ

Here is my submission
My submission