#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

#ifdef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

struct Trie {
    const char base;
    struct Node {
        vector<int> child; // 子の頂点番号 存在しなければ-1
        vector<int> ac;    // 受理状態になる文字列のid集合
        vector<ll> cnt;
        char c;     // 頂点を表す文字
        int common; // このnodeを共有する文字列の個数
        Node(char c) : c(c), common(0) {
            child.assign(26, -1);
            cnt.assign(26, 0);
        }
    };
    vector<Node> nodes;
    char root;
    Trie(char base) : root(0), base(base) { nodes.emplace_back(Node(root)); }
    void insert(const string &s, int wid) {
        int now = 0;
        int n = (int)s.size();
        for(int i = 0; i < n - 1; i++) {
            int &nxt = nodes[now].child[s[i] - base];
            if(nxt == -1) {
                nxt = (int)nodes.size();
                nodes.emplace_back(Node(s[i]));
            }
            nodes[now].common++;
            now = nxt;
        }
        nodes[now].common++;
        nodes[now].cnt[s.back() - base]++;
        nodes[now].ac.emplace_back(wid);
    }
    void insert(const string &s) { insert(s, nodes[0].common); }
    ll get(const string &s, vector<int> &exist) {
        ll res = 0;
        int now = 0;
        int n = (int)s.size();
        for(int i = 0; i < n; i++) {
            for(int k = 0; k < 26; k++) {
                if(exist[i] & (1 << k)) {
                    res += nodes[now].cnt[k];
                }
            }
            int &nxt = nodes[now].child[s[i] - base];
            if(nxt == -1) {
                return res;
            }
            now = nxt;
        }
        return res;
    }
    int count() const { return (nodes[0].common); }
    int size() const { return ((int)nodes.size()); }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<string> s(N);
    for(int i = 0; i < N; i++) {
        cin >> s[i];
        reverse(ALL(s[i]));
    }
    sort(ALL(s), [](const string &a, const string &b) {
        return (a.size() < b.size());
    });

    Trie trie('a');
    ll ans = 0;
    for(int i = 0; i < N; i++) {
        int n = (int)s[i].size();
        vector<int> exist(n + 1, 0);
        for(int j = n - 1; j >= 0; j--) {
            exist[j] = exist[j + 1] | (1 << (s[i][j] - 'a'));
        }
        ans += trie.get(s[i], exist);
        trie.insert(s[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 409660