Help in Codeforces Perfect Security Round470

I’m getting runtime error (segmenation fault for n>250 on local compiler). I have used naive implementation of trie to solve the question. What’s wrong in my approach? Is this error due to consuming too much memory?

Code Link