#include #include #include using namespace std; struct node{ int cnt; node* e[27]; node(){ cnt = 0; for(int i=0; i<27; i++){ e[i] = nullptr; } } node*& operator[](char index){ return e[index-'a']; } }; class Trie_Tree{ vector v; node* root; public: Trie_Tree(){ root = new node(); v.push_back(root); } ~Trie_Tree(){ for(int i=0; icnt++; if( (*ptr)[ s[i] ] == nullptr){ (*ptr)[ s[i] ] = new node(); v.push_back( (*ptr)[ s[i] ] ); } ptr = (*ptr)[s[i]]; } ptr->cnt++; } int find(string& s){ node* ptr = root; for(int i=0; i<=s.size(); i++){ ptr->cnt--; if(ptr->cnt == 0) return i; ptr = (*ptr)[s[i]]; } return -1; } }; int main(){ int n; cin >> n; vector s(n); Trie_Tree trie; for(int i=0; i> s[i]; s[i] += 'z'+1; trie.insert(s[i]); } for(int i=0; i> x; x--; cout << max(1,trie.find(s[x])) << endl; } return 0; }