#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pp = pair<char,int>;

ll solve(ll N, vector<string>& S) {
    vector<map<char,int>> tr;
    vector<ll> vend;
    vector<int> subrt(N);
    int nx = 0;
    tr.push_back(map<char,int>());
    vend.push_back(0);
    nx++;
    for ( int i = 0; i < N; i++ ) {
        int cur = 0;
        for ( int j = S[i].size()-1; j >= 0; j-- ) {
            char c = S[i][j];
            if ( tr[cur].count(c) == 0 ) {
                tr[cur][c] = nx;
                tr.push_back(map<char,int>());
                vend.push_back(0);
                nx++;
            }
            subrt[i] = cur;
            cur = tr[cur][c];
        }
        vend[cur]++;
    }

    vector<ll> csub(tr.size());
    auto dfs1 = [&](auto self, int v) -> ll {
        ll ct = vend[v];
        for ( auto& p : tr[v] ) {
            ct += self(self, p.second);
        }
        csub[v] = ct;
        return ct;
    };
    dfs1(dfs1, 0);

    int C = 26;
    vector<vector<ll>> cc(tr.size(),vector<ll>(C));
    auto dfs2 = [&](auto self, int v) -> void {
        for ( auto& p : tr[v] ) {
            self(self, p.second);
            for ( int i = 0; i < C; i++ ) {
                cc[v][i] += i == (int)(p.first-'a') ? csub[p.second] : cc[p.second][i];
            }
        }
    };
    dfs2(dfs2,0);

    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        int c = (int)(S[i][0]-'a');
        ans += cc[subrt[i]][c] - 1;
    }
    return ans;
}


auto solve_small_1(ll N, vector<string>& S) {
    vector<string> rS(S);
    for ( int i = 0; i < N; i++ ) {
        reverse(rS[i].begin(), rS[i].end());
    }
    ll r = 0;
    for ( int i1 = 0; i1 < N; i1++ ) {
        for ( int i2 = i1+1; i2 < N; i2++ ) {
            int i,j;
            if ( rS[i1].size() == rS[i2].size() ) continue;
            if ( rS[i1].size() > rS[i2].size() ) {
                i = i1, j = i2;
            } else {
                i = i2, j = i1;
            }
            string t1 = rS[i], t2 = rS[j];
            char c = *t2.rbegin();
            t2.pop_back();
            if ( t1.substr(0, t2.size()) != t2 ) {
                continue;
            }
            bool ok = false;
            for ( int k = t2.size(); k < t1.size(); k++ ) {
                if ( t1[k] == c ) {
                    ok = true;
                    break;
                }
            }
            if ( ok ) r++;
        }
    }
    return r;
}
struct Data {
    int id;
    ll N;
    vector<string> S;
};
void test() {
    mt19937_64 mt64(0);
    uniform_int_distribution<ll> rnd_n(1, 5);
    uniform_int_distribution<ll> rnd_c(0, 4);

    ll a_max = 1000;

    int id = 0;
    vector<Data> ts;
    ts.push_back({++id,4,{"dd","eed","ccea","cce"}});
    ts.push_back({++id,6,{"b","a","abc","c","d","ab"}});
    ts.push_back({++id,3,{"abcxyx","cyx","abc"}});
    for ( int i = 0; i < 100; i++ ) {
        int m = 10;
        vector<string> s;
        for ( int j = 0; j < m; j++ ) {
            int n = rnd_n(mt64);
            string u;
            for ( int h = 0; h < n; h++ ) {
                u.push_back('a'+rnd_c(mt64));
            }
            if ( find(s.begin(), s.end(), u) != s.end() ) {
                j--;
                continue;
            }
            s.push_back(u);
        }
        ts.push_back({++id,m,s});
    }
    
    for ( Data& t : ts ) {
        auto ans0 = solve(t.N,t.S);
        auto ans1 = solve_small_1(t.N,t.S);
        cout << ans0 << " " << ans1 << "\n";

        if ( ans0 != ans1 ) {
            cout << t.id << " " << ans0 << " " << ans1 << "\n";
        }
    }
    cout << "end" << "\n";
}


int main() {
    // test();
    ll N;
    cin >> N;
    vector<string> S(N);
    for ( int i = 0; i < N; i++ ) cin >> S[i];
    
    auto ans = solve(N, S);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 427464