#include <bits/stdc++.h>
 
using namespace std;
 
using i64 = long long;
#define forn(a, e) for (i64 a = 0; a < (i64)(e); a++)
#define forr(a, s, e) for (i64 a = s; a < (i64)(e); a++)
#define fore(e, a) for (auto& e : a)
 
#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logvff(a, f1, f2) {cerr << #a".{"#f1 << ", "#f2 << "} = \n"; fore(e, a) { cerr << "(" << e.f1 <<", " << e.f2 << ") ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logvff(a, f1, f2)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif
 
using iip = pair<int, int>;
using llp = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;
template<typename T> using vec = vector<T>;
 
template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }
 
template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }
 
template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }
template<typename T, size_t N>
istream& operator>>(istream& is, array<T, N>& c) { for (auto& e : c) is >> e; return is; }
 
template<typename ...T>
istream& read(T&... args) { return (cin >> ... >> args); }
 
static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }
 
constexpr i64 INF = 1e18;
// constexpr int MXB = 4;
constexpr int MXB = 9;
using bin = bitset<MXB>;
constexpr i64 M = 1e9 + 7;


struct AhoCorasick {
    static constexpr int ASIZE = 26;
    struct tnode {
        char c;
        bool used = false;
        vector<int> source;
        int p = -1;
        i64 cost = -1e18;
        array<int, ASIZE> anext;
        array<int, ASIZE> tnext;
        array<i64, ASIZE> cc;

        tnode() {
            anext.fill(-1);
            tnext.fill(-1);
            cc.fill(0);
        }
    };

    vector<int> suf;

    vector<tnode> trie;
    vector<int> used;
    int scount = 0;
    int st_ = 0;

    template<typename Container>
    static AhoCorasick OnStrings(const Container& strs) {
        AhoCorasick ac;
        for (const auto& str : strs) {
            ac.add_string(str);
        }
        ac.suf.resize(ac.trie.size(), -1);
        ac.used.resize(strs.size());
        return ac;
    }

    AhoCorasick(int size = 0) {
        trie.reserve(size);
        trie.emplace_back();
    }

    void reset_state() { st_ = 0; }
    void set_state(int st) { st_ = st; }
    int nstates() const { return trie.size(); }

    void build_all() {
        for (int i = 0; i < trie.size(); i++) {
            set_state(i);
            for (char c = 0; c < ASIZE; c++) {
                move_char('a' + c);
            }
        }
    }

    void add_string(const string& s) {
        int v = 0;
        auto cc = make_vec(0ll, s.size() + 1, 26);
        for (int i = s.size() - 1; i >= 0; i--) {
            forn(j, 26) {
                cc[i][j] = cc[i + 1][j] + (s[i] == j + 'a');
                uin(cc[i][j], 1ll);
            }            
        }

        for (int i = 0; i < s.size(); i++) {
            char c = s[i] - 'a';
            if (trie[v].anext[c] == -1) {
                trie[v].anext[c] = trie.size();
                trie.emplace_back();
                trie.back().p = v;
                trie.back().c = c;
            }
            forn(j, 26) {
                trie[v].cc[j] += cc[i][j];
            }
            v = trie[v].anext[c];
        }

        trie[v].source.push_back(scount);
        scount++;
    }

    const tnode& move_trie(const string& s) {
        int v = 0;
        forn(i, s.size()) {
            v = trie[v].anext[s[i] - 'a'];
        }
        return trie[v];
    }

    int slink(int p) {
        if (suf[p] != -1) {
            return suf[p];
        }

        int parent = trie[p].p;
        if (p == 0 || parent == 0) {
            suf[p] = 0;
        } else {
            suf[p] = move(slink(trie[p].p), trie[p].c);
        }

        return suf[p];
    }

    void finish(int st) {
        if (st == 0 || trie[st].used) {
            return;
        } else {
            for (int i = 0; i < trie[st].source.size(); i++) {
                used[trie[st].source[i]] = true;
            }
            trie[st].used = true;
            finish(slink(st));
        }
    }

    int move(int st, char c) {
        if (trie[st].tnext[c] != -1) {
            return trie[st].tnext[c];
        }

        int next_st;
        if (trie[st].anext[c] != -1) {
            next_st = trie[st].anext[c];
        } else if (st == 0) {
            next_st = 0;
        } else {
            next_st = move(slink(st), c);
        }
        trie[st].tnext[c] = next_st;
        return trie[st].tnext[c];
    }

    int move_char(char c) {
        st_ = move(st_, c - 'a');
        finish(st_);
        return st_;
    }
    int move_str(const string& s) {
        for (auto c : s) {
            move_char(c);
        }
        return st_;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    rande.seed(chrono::steady_clock::now().time_since_epoch().count());


    int n;
    while (read(n)) {
        svec ss(n);
        read(ss);
        fore(s, ss) {
            reverse(s.begin(), s.end());
        }
        AhoCorasick t = AhoCorasick::OnStrings(ss);
        i64 ans = 0;
        fore(s, ss) {
            auto node = t.move_trie(s.substr(0, s.size() - 1));
            // logs(s);
            // logv(node.anext);
            // logv(node.cc);
            ans += node.cc[s.back() - 'a'] - 1;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 714636