#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++) #define All(v) (v).begin(),(v).end() typedef long long ll; const int MAX = 500000,MS=2; const ll mod[] = {999999937LL, 1000000007LL}, base = 9973; struct rolling_hash{ int n; vector hs[MS],pw[MS]; rolling_hash(){}; rolling_hash(const string &s){ n=s.size(); for(int i=0;i> S; int N = S.size(); rolling_hash rh(S); map,ll> m[11]; for(int i=0;i=N)break; m[j+1][make_pair(rh.get_hash(i,i+j+1,0),rh.get_hash(i,i+j+1,1))]++; } } int M; cin >> M; ll res = 0; rep(i,M){ string C; cin >> C; rolling_hash cur(C); res+=m[C.size()][make_pair(cur.get_hash(0,C.size(),0),cur.get_hash(0,C.size(),1))]; } cout << res << endl; return 0; }