#include #include #include using namespace std; const int alphabet_size = 2; struct node { node * children_of_node[alphabet_size]; bool is_end_of_word; node () { is_end_of_word = false; for(int i = 0; i < alphabet_size; i++) { children_of_node[i] = NULL; } } }; void insert_word(node * trie, string word) { node * tmp = trie; for(int i = 0; i < (int) word.size(); i++) { int c = word[i] - 'a'; if(tmp -> children_of_node[c] == NULL) { tmp -> children_of_node[c] = new node(); } tmp = tmp -> children_of_node[c]; } tmp -> is_end_of_word = true; } bool search_word(node * trie, string word) { node * tmp = trie; for(int i = 0; i < (int) word.size(); i++) { int c = word[i] - 'a'; if(tmp -> children_of_node[c] == NULL) { return false; } tmp = tmp -> children_of_node[c]; } return tmp -> is_end_of_word; } void delete_word(node * trie, string word) { node * tmp = trie; for(int i = 0; i < (int) word.size(); i++) { int c = word[i] - 'a'; if(tmp -> children_of_node[c] == NULL) { return; } tmp = tmp -> children_of_node[c]; } tmp -> is_end_of_word = false; } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector v(n); for(int i = 0; i < n; i++) { cin >> v[i]; } for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { if((int) v[i].size() > (int) v[j].size()) { swap(v[i], v[j]); } } } node * trie[n + 1]; for(int i = 0; i < n; i++) { trie[i] = new node(); } for(int i = 1; i < n; i++) { for(int j = 0; j < (int) v[i].size(); j++) { string tmp = ""; for(int k = j; k < min(j + 60, (int) v[i].size()); k++) { tmp += v[i][k]; insert_word(trie[i], tmp); } } } int res = 0; for(int i = 0; i < (int) v[0].size(); i++) { string tmp = ""; for(int j = i; j < min(i + 60, (int) v[0].size()); j++) { tmp += v[0][j]; bool ok = true; for(int k = 1; k < n; k++) { if(!search_word(trie[k], tmp)) { ok = false; break; } } if(ok) { res = max(res, (int) tmp.size()); } } } cout << res << endl; return 0; }