#include <bits/stdc++.h>
typedef unsigned int u32;
struct Trie{
struct Node{
u32 end = 0;
u32 pass = 0;
Node* next[50] = {nullptr};
};
Node *root = nullptr;
char base;
Trie(bool tag = true){
root = new Node;
base = (base ? 'a' : 'A');
}
void insert(std::string s){
Node* t = root;
t->pass++;
for (u32 i = 0, path;i < s.length();++i){
path = (u32)(s.at(i) - base);
if(t->next[path] == nullptr){
t->next[path] = new Node;
}
t = t->next[path];
t->pass++;
}
t->end++;
}
int query(std::string s){
Node* t = root;
for (u32 i = 0, path;i < s.length();++i){
path = (u32)(s[i] - base);
if(t->next[path] == nullptr){
return 0;
}
t = t->next[path];
}
return t->end;
}
void erase(std::string s){
if(query(s) > 0){
Node* t = root;
t->pass--;
for (u32 i = 0, path;i < s.length();++i){
path = s.at(i) - base;
if(--t->next[path]->pass == 0){
t->next[path] = nullptr;
return;
}
t = t->next[path];
}
t->end--;
}
}
int query_pre(std::string s){
Node* t = root;
int ans = 0;
for (u32 i = 0, path;i < s.length(); ++i){
path = (u32)(s.at(i) - base);
if(t->next[path] == nullptr){
return ans;
}
ans += t->end;
t = t->next[path];
}
ans += t->end;
return ans;
}
int query_pre1(std::string s){
Node* t = root;
for (u32 i = 0, path;i < s.length();++i){
path = (u32)(s.at(i) - base);
if(t->next[path] == nullptr){
return 0;
}
t = t->next[path];
}
return t->pass;
}
Node* getroot(){return root;}
int dfs(Node* t){
int temp = 0;
for (u32 i = 0;i < 26;++i){
if(t->next[i] != nullptr){
temp = std::max(dfs(t->next[i]) + t->next[i]->end, temp + t->next[i]->end);
}
}
return temp;
}
};
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int n;
struct Trie tree(true);
std::cin >> n;
if(n == 0){
std::cout << 0;
return 0;
}
std::string s[2005];
int i = 0;
while(n--){
std::cin >> s[i];
tree.insert(s[i]);
i++;
}
int ans = 0;
while(i--){
ans = std::max(ans, tree.query_pre(s[i]));
}
std::cout << ans << '\n';
}
这是记录https://www.luogu.com.cn/record/202010498