#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 300001
const int BASE(1e8+7);
int n, ans;
string s[MAXN];
vector<unsigned int> ha[MAXN];
unordered_map<unsigned int, int> tms;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i(1); i<=n; ++i){
cin >> s[i];
for (int j(0), now(0); j<s[i].size(); ++j){
ha[i].push_back(now=now*BASE+(j+1)*(j+1)*s[i][j]);
++tms[now];
}
}
for (int i(1); i<n; ++i){
for (int j(0); j<s[i].size(); ++j) ans += --tms[ha[i][j]];
}
cout << ans;
return 0;
}
你会发现我的 now 是 long long 的,也就是说我写了一个有符号整型溢出哈希。