#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

struct Node {
    int count;
    map<char, Node*> nxt;
};

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

    Node* root = new Node;
    root->count = 0;

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        V<int> lidx(26, -1);
        for (int ii = 0; ii < s[i].size(); ii++) chmax(lidx[s[i][ii] - 'a'], ii);
        set<int> cidx;
        for (int ii = 0; ii < 26; ii++) cidx.insert(lidx[ii]);

        Node* tmp = root;
        bool ok = true;
        int j;
        for (j = 0; j < int(s[i].size()) - 1; j++) {
            int nxtc = s[i][j];
            if (tmp->nxt.find(nxtc) != tmp->nxt.end()) {
                tmp = tmp->nxt[nxtc];
                if (cidx.find(j) != cidx.end()) tmp->count++;
            } else {
                ok = false;
                break;
            }
        }
        // cout << i << ' ' << j << '\n';

        // s[i] を接頭辞に持つ文字列がある場合、縮約
        if (ok) {
            queue<Node*> que;
            for (P<char, Node*> p: tmp->nxt) que.push(p.second);
            while (!que.empty()) {
                Node* q = que.front(); que.pop();
                for (P<char, Node*> p: q->nxt) {
                    // cout << p.first << ' ' << p.second->count << '\n';
                    if (tmp->nxt.find(p.first) == tmp->nxt.end()) {
                        tmp->nxt[p.first] = new Node;
                        tmp->nxt[p.first]->count = 0;
                    }
                    tmp->nxt[p.first]->count += p.second->count;
                    que.push(p.second);
                }
                q->nxt.clear();
            }
            if (tmp->nxt.find(s[i].back()) != tmp->nxt.end()) {
                ans += ll(tmp->nxt[s[i].back()]->count);
                tmp->nxt[s[i].back()]->count++;
            } else {
                tmp->nxt[s[i].back()] = new Node;
                tmp->nxt[s[i].back()]->count = 1;
            }
        } else {
            for (int jj = j; jj < int(s[i].size()); jj++) {
                int nxtc = s[i][jj];
                tmp->nxt[nxtc] = new Node;
                if (cidx.find(jj) != cidx.end()) tmp->nxt[nxtc]->count = 1;
                else tmp->nxt[nxtc]->count = 0;
                tmp = tmp->nxt[nxtc];
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 129444