using DFA solved this issue. made some stupid mistakes. index should be less than n*n +1 , not n. stupid.