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

template<typename T> struct BIT {
    int mxn;
    vector<T> data;
    const bool zi;
    const T un;
    BIT<T>(int max_n, bool zero_indexed = false, T unit = T(0)) : mxn(max_n), zi(zero_indexed), un(unit) {
        if ( zi ) mxn++;
        data.assign(mxn + 1, unit);
    }
    void add(int i, T x) {
        if ( zi ) i++;
        assert( i > 0 );
        while ( i <= mxn ) {
            data[i] += x;
            i += i & -i;
        }
    }
    T sum(int i) {
        if ( zi ) i++;
        assert( i > 0 );
        T s = un;
        while ( i > 0 ) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }
    vector<T> get_sum_list(int l, int r) {
        vector<T> a;
        for ( int i = l; i <= r; i++ ) {
            a.push_back(sum(i));
        }
        return a;
    }
};

ll solve(ll N, vector<string>& SS) {
    vector<string> S(SS);
    for ( int i = 0; i < N; i++ ) {
        reverse(S[i].begin(), S[i].end());
    }
    sort(S.begin(), S.end());
    priority_queue<pic> q;
    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < S[i].size(); j++ ) {
            q.push(pic(j,pp(S[i][j],i)));
        }
    }    
    vector<int> il(N), ir(N), lg(N);  // [l,r)
    for ( int i = 0; i < N; i++ ) {
        string t1 = S[i];
        t1.pop_back();
        string t2(t1);
        t2.push_back('}');
        il[i] = lower_bound(S.begin(), S.end(), t1) - S.begin();
        ir[i] = upper_bound(S.begin(), S.end(), t2) - S.begin();
        lg[i] = (int)t1.size();
    }
    vector<ll> ix(N);
    for ( int i = 0; i < N; i++ ) ix[i] = i;
    sort(ix.begin(), ix.end(), [&](int a, int b) { return lg[a] > lg[b];});

    // // debug
    // cout << "debug\n";
    // for ( int i = 0; i < N; i++ ) {
    //     cout << lg[ix[i]] << " ";
    // }
    // cout << "\n";

    ll ans = 0;
    ll C = 26;
    vector<BIT<int>> ct(C, BIT<int>(N+2,true)); // ct[][i+1]= value of S[i]
    vector<vector<int>> ctn(C, vector<int>(N));
    for ( int j = 0; j < N; j++ ) {
        int i = ix[j];
        while ( !q.empty() && q.top().first >= lg[i] ) {
            int c = (int)(q.top().second.first - 'a');
            int ii = q.top().second.second;
            if ( ctn[c][ii] == 0 )  {
                ctn[c][ii] = 1;
                ct[c].add(ii+1,1);
            }
            q.pop();
        }
        int cc = (int)((*S[i].rbegin()) - 'a');
        ll ctpr = ct[cc].sum(ir[i]) - ct[cc].sum(il[i]) - 1;
        ans += ctpr;
    }
    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,6,{"b","a","abc","c","d","ab"}});
    ts.push_back({++id,3,{"abcxyx","cyx","abc"}});
    for ( int i = 0; i < 3; 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));
            }
            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: 72280