#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <random>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl


using namespace std;

#ifdef LOCAL
static struct __timestamper {
    string what;
    __timestamper(const char* what) : what(what){};
    __timestamper(const string& what) : what(what){};
    ~__timestamper(){
        TIMESTAMPf("%s", what.data());
    }
} __TIMESTAMPER("end");
#else
struct __timestamper {};
#endif

typedef long long ll;
typedef long double dbl;

constexpr int SIGMA = 26;
struct node {
    vector<int> nxt;
    vector<int> cnt;
    int has;

    node() {
        nxt.assign(SIGMA, -1);
        cnt.assign(SIGMA, 0);
        has = 0;
    }
};

int main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    while (cin >> n) {
        vector<node> nodes;
        nodes.emplace_back();
        auto add = [&](const string &s) {
            int cur = 0;
            vector<int> last(SIGMA, -1);
            for (char cc : s) {
                int c = cc - 'a';
                if (nodes[cur].nxt[c] == -1) {
                    nodes[cur].nxt[c] = nodes.size();
                    nodes.emplace_back();
                }
                cur = nodes[cur].nxt[c];
                last[c] = cur;
            }
            nodes[cur].has = 1;
            for (int c = 0; c < SIGMA; c++) {
                if (last[c] != -1) {
                    nodes[last[c]].cnt[c]++;
                }
            }
        };
        for (int i = 0; i < n; i++) {
            string s;
            cin >> s;
            reverse(s.begin(), s.end());
            add(s);
        }
        for (int i = (int)nodes.size() - 1; i >= 0; i--) {
            for (int to : nodes[i].nxt) {
                if (to == -1) continue;
                for (int c = 0; c < SIGMA; c++) nodes[i].cnt[c] += nodes[to].cnt[c];
            }
        }

        ll ans = 0;
        function<void(int)> dfs = [&](int v) {
            for (int c = 0; c < SIGMA; c++) {
                int to = nodes[v].nxt[c];
                if (to == -1) continue;
                if (nodes[to].has) {
                    for (int nto : nodes[v].nxt) {
                        if (nto != -1) ans += nodes[nto].cnt[c];
                    }
                    ans--;
                }
                dfs(to);
            }
        };
        dfs(0);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 334160