#include <bits/stdc++.h>
using namespace std;

const int N = 1000001;
int g[N][26], h[N][26], c = 0;

typedef long long ll;

int main(void) {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<string> sv(n);
    for (string& s : sv) cin >> s;
    sort(sv.begin(), sv.end(), [](const string& s1, const string& s2) { return s1.size() > s2.size(); });
    ll ans = 0;
    for (string& s : sv) {
        reverse(s.begin(), s.end());
        bool fail = 0;
        int p = 0;
        for (int i = 0; i + 1 < s.size(); ++i) {
            p = g[p][s[i] - 'a'];
            if (!p) fail = 1;
        }
        if (!fail) ans += h[p][s.back() - 'a'];
        int z[26] = { 0 };
        for (char ch : s) z[ch - 'a']++;
        p = 0;
        for (int i = 0; i < s.size(); ++i) {
            for (int j = 0; j < 26; ++j)
                if (z[j]) h[p][j]++;
            int o = s[i] - 'a';
            z[o]--;
            if (!g[p][o]) g[p][o] = ++c;
            p = g[p][o];
        }
    }
    printf("%lld\n", ans);
    


    return 0;
}