#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define un(x)           x.erase(unique(all(x)), x.end())
#define xx              first
#define yy              second
#define pb              push_back
#define all(v)          v.begin(), v.end()

#define D(x)            cerr << #x " = " << x << '\n'
#define DBG             cerr << "Hi!" << '\n'

#define CLR(a)          memset(a, 0, sizeof(a))
#define SET(a)          memset(a, -1, sizeof(a))

// inline int setBit(int n, int pos) { return n = n | (1 << pos); }
// inline int resetBit(int n, int pos) { return n = n & ~(1 << pos); }
// inline bool checkBit(int n, int pos) { return (bool)(n & (1 << pos)); }

// int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
// int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// unsigned int num = rng();
// shuffle(V.begin(), V.end(), rng);

/******************************************************************************************/

const int MAX = 200010;
// const int INF = 0x3f3f3f3f;
// const int MOD = 998244353;

// inline int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }
// inline int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; }
// inline int mul(int a, int b) { return (a * 1LL * b) % MOD; }

string s[MAX];
int cnt[26][MAX];
int cpy[26][MAX];

const int LIM = 1e6;

struct wavelet_tree {
    int lo, hi;
    wavelet_tree *l, *r;
    vector <int> b;

    wavelet_tree(int *from, int *to, int x, int y){
        lo = x, hi = y;
        if(lo == hi or from >= to) return;
        int mid = (lo+hi)/2;
        auto f = [mid](int x){ return x <= mid; };
        b.reserve(to-from+1);
        b.push_back(0);
        for(auto it = from; it != to; it++)
            b.push_back(b.back() + f(*it));
        auto pivot = stable_partition(from, to, f);
        l = new wavelet_tree(from, pivot, lo, mid);
        r = new wavelet_tree(pivot, to, mid+1, hi);
    }

    // number of elements <= k in subarray [l,r]
    int LTE(int l, int r, int k) {
        if(l > r or k < lo) return 0;
        if(hi <= k) return r - l + 1;
        int lb = b[l-1], rb = b[r];
        return this->l->LTE(lb+1, rb, k) + this->r->LTE(l-lb, r-rb, k);
    }

    ~wavelet_tree() {
        delete l;
        delete r;
    }
};


int lcp(int a, int b) {
    int ret = 0;
    for(int i = 0; i < (int)min(s[a].size(), s[b].size()); ++i) {
        if(s[a][i] == s[b][i]) ret++;
        else break;
    }
    return ret;
}

int n;

int getlb(int p) {
    int low = 1, high = p, ret = p;
    while(low <= high) {
        int mid = (low + high) >> 1;
        if(lcp(p, mid) >= (int)s[p].size() - 1) {
            ret = mid;
            high = mid - 1;
        }
        else low = mid + 1;
    }
    return ret;
}


int getub(int p) {
    int low = p, high = n, ret = p;
    while(low <= high) {
        int mid = (low + high) >> 1;
        if(lcp(p, mid) >= (int)s[p].size() - 1) {
            ret = mid;
            low = mid + 1;
        }
        else high = mid - 1; 
    }
    return ret;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    // freopen("in", "r", stdin); 
    // freopen("out", "w", stdout);

    
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> s[i];
        reverse(all(s[i]));
    }
    
    sort(s + 1, s + n + 1);

    for(int i = 1; i <= n; ++i) {
        for(char ch : s[i]) {
            cnt[ch - 'a'][i]++;
            cpy[ch - 'a'][i]++;
        }
    }

    wavelet_tree *Tree[26];
    for(int i = 0; i < 26; ++i) {
        Tree[i] = new wavelet_tree(cpy[i] + 1, cpy[i] + n + 1, 0, LIM);
    }
    ll ans = 0;
    for(int i = 1; i <= n; ++i) {
        int l = getlb(i);
        int r = getub(i);
        ans += (r - l) - Tree[s[i].back() - 'a']->LTE(l, r, cnt[s[i].back() - 'a'][i] - 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 456788