/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 200002;
const int L_MAX = 1000002;

const int BITS = 18;

int n;

string s[N_MAX];

vector <int> v[L_MAX];

int cnt1[26];

int lastc[N_MAX][26];

int lcp[N_MAX];

int rm[N_MAX][BITS];

int p2[N_MAX];

int rmq (int l, int r)
{
    int lg = r - l + 1;
    int p2lg = p2[lg];
    return min(rm[l][p2lg], rm[r - (1 << p2lg) + 1][p2lg]);
}

int flcp (int i, int j)
{
    return rmq(i, j - 1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s[i];
        reverse(s[i].begin(), s[i].end());
    }
    sort(s + 1, s + n + 1);
    for(int i = 1; i <= n; i++)
        for(int j = 0; j <= (int)s[i].size(); j++)
            v[j].push_back(i);
    for(int i = 1; i <= n; i++)
        for(int j = 0; j < (int)s[i].size(); j++)
            lastc[i][s[i][j] - 'a'] = j + 1;
    for(int i = 1; i < n; i++)
    {
        while(lcp[i] < min((int)s[i].size(), (int)s[i + 1].size()) && s[i][lcp[i]] == s[i + 1][lcp[i]])
            lcp[i]++;
    }
    for(int i = 1; i < n; i++)
        rm[i][0] = lcp[i];
    for(int b = 1; b < BITS; b++)
        for(int i = 1; i + (1 << b) - 1 < n; i++)
            rm[i][b] = min(rm[i][b - 1], rm[i + (1 << (b - 1))][b - 1]);
    for(int i = 1; i <= n; i++)
        while((1 << (p2[i] + 1)) <= i)
            p2[i]++;
    ll ans = 0;
    for(int lg = 0; lg <= 1000000; lg++)
    {
        if(v[lg].empty())
            continue;
        for(int c = 0; c < 26; c++)
            cnt1[c] = 0;
        int last = -1;
        int cnt0 = 0;
        for(int i : v[lg])
        {
            if(last != -1 && flcp(last, i) < lg)
            {
                for(int c = 0; c < 26; c++)
                    cnt1[c] = 0;
                cnt0 = 0;
            }
            ans += cnt0;
            if(lg + 1 <= (int)s[i].size())
            {
                for(int c = 0; c < 26; c++)
                    if(lastc[i][c] > lg && char('a' + c) != s[i][lg])
                        ans += cnt1[c];
            }
            if(lg + 1 == (int)s[i].size())
                cnt1[s[i][lg] - 'a']++;
            if(lg == (int)s[i].size())
                cnt0++;
            last = i;
        }
        for(int c = 0; c < 26; c++)
            cnt1[c] = 0;
        last = -1;
        cnt0 = 0;
        reverse(v[lg].begin(), v[lg].end());
        for(int i : v[lg])
        {
            if(last != -1 && flcp(i, last) < lg)
            {
                for(int c = 0; c < 26; c++)
                    cnt1[c] = 0;
                cnt0 = 0;
            }
            if(lg != (int)s[i].size())
                ans += cnt0;
            if(lg + 1 <= (int)s[i].size())
            {
                for(int c = 0; c < 26; c++)
                    if(lastc[i][c] > lg && char('a' + c) != s[i][lg])
                        ans += cnt1[c];
            }
            if(lg + 1 == (int)s[i].size())
                cnt1[s[i][lg] - 'a']++;
            if(lg == (int)s[i].size())
                cnt0++;
            last = i;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 73640