//                                       _____   ---===--   _____
//                             .    ''                              ``  -.
//                      .  '                                                  `   .
//                   .'       _ _  _                                                  ` .
//                 /  ' '                 ''    -- .                                       `\
//                |                                      ` -.                                /\
//                 \ ______  -----   ____                       ` -.                        .'|_
//                  \\mmmNNNNNNNNNNNNmm==____`   - . _                `.`  -  .......  - '  . ' |
//                   |"""""""""""""MNNNNNNNNNNNNNNNm==___ `  -  . _     \   .---====-- .. '     |
//                   -''''''''''' `   -  __   '"""MMNNNNNNNNNNNmm===______ "|       __  | | NN) (
//                 / ::::::::::::::::::::::::::`  -  .  __ '"""MNNNNNNNNNNNNN\   (NNN*  | |__...J
//               /  ::::::::::::::::::::::::::::::::::::::::::` -  .  __  '"""\       . ''|      ` .
//             /    :::::::::::::::::::::::::::::::::::::::::::::::::::  '''' / -- ' /  |::\  \ ,)   `.
//            /    ::'   ':::::::::/:::::::::::::::::::::''::  :::   ::::::::/    ( /   |:::\   "" _. ''
//           /    ::'   :/:'  ::  /    :::::    :::     :. .::\:::::::::::::< _        /::::::\  /\
//          / .:::::::::/::...:. /     :::::....:::::::::::::::\:::::::::::::::\:`:-  /::::\::::`:N\
//         / ::/:::::::/::::::::/::::::::::::::::::::::::::::::::\:::::::\::::::|::::|::::::|::::::N\
//        | ::|:::::::|:::::::/ |:::::::::/|:::::::::/:::::\::::::\:::::::\:::::|::::|:::::::|::::::N|
//        | ::|:::::::|::::::/  |:|::::::| |::::::::| |:::::\::::::\:::::::|:::/:::::]::::::::::::::N\
//        | ::|:::::::|:::::/   |:|::::::| |::::::::|  \:::::\\:::::\::::::|::/:::::/:::::::/:::::::NN|
//        | ::|:::::::|::::|     \:\:::::|  \::::::::\ --\::::\_\::::|:::::|:/:::::/:::::::/::::::::NN|
//         |::|:::::::|::::|-'""""\:\:::|    \::\-::::\   `-|\:\  `-:|:::::|:::::::::::::/:::::|:::::N|
//         |::|::::\::\::\::|  ___ \ `-_:\     "-\ `-__  --'''___;_   |::::|:::::::::.m'\:::::::|::::N|
//          \::\::::|:::\:\--\___  `- ` '"        ""   ggmm@@@@@@@@@m ):::/:::::::. @@XXL|:::::::\:::N|
//           \::\::::\:::\mN**@@@@@mm                  \    |::TT:::/::::/N:::::/ @@@@XXL|::::::::\::NN\
//            \N:NN\:::-.::\  |::TT::|                  ` . _\:::::/ /::7NN:::/::|@@@@XXL|:::::::::\::NN\
//             \NNN\\'n-:`N\ - \::::/                             / / /NN::::/:::|@@@XXL/:::::::::::\::NN\
//              `"NN\ `-NN''\                                    _7 "  \:::::\::|LXXXLL/:::::::::::::`.NNN\
//                `-NN\ \NNNN\                                          |\::::\:|<LLLL/\:::::::::::::\::`NN\
//                    ` '|NNNN\          '                             /NNN`m- >NN|::\NN\:::::\:::::::\:::::`.
//                       |NNNNNN\                                   .i'/:::::::/NN|:::\NN\::::::\:::::::\::::::`;-.
//                      |NNNNNN/:/`.          .__.              . '  |/::/::::/NNN|:::::\N\:::::::`.:::::`Nn::::::::`m-.
//                     /NNNNN/:n/:::|` .                    . '      /::y::::/NN::N|:::\::\|:::::::::`.:::::"-.::::::::::`m.
//                    /NNN.':://::::|NNNN/` .          . '          /:::/:::/"""">NN\::::\:::`.:::::.:::::::::::`-.:::::::::)
//                  /."':::.'N::::::|NNN/::\::__`'''\              /::::::::|@@@@||NN\::::::::::`.::::` .::::::::::::`.-.::/
//              -'::::::m':/:::::::/NN/:::::|ffffrrrrmmmmmmmm@@@@@|:::::::\N|@@@| \:\N\::::::::::::`.:::::`.::::::::::::::::`..
//           /::::::m'::.':::::/::/"':::::/ /\fffffffffffff@@@@@@@|::::::::\|@@@| N`.\NN`.::::::::::::`.:::::`-.::::::::.:::::::` .
//           \::::mT:':::::::/:.':::::::,'/MMM\N.   ffffffff    @@|:::::::::\@@/.  NNNNNNNNN`m.:::::::::"=::::::"Nn:::::::`.::::::::`.
//          -':':::::::::::.':/:::::::://MMM. ""*fffffffffffffffff@\:::::::::\"   gg`  -  . NNNN\`n.::::::".::::::"N:::::::"n::::::::|
//    .- ':::.:::::::.':.':::/::::::::/- ' Mng      """"""""""      `\::|::::::\M*",,,,,,,,,,,,` .\\N`.::::|:::::::|::::::::|:::::::/
// /':::::.'::::::.'::/::::n/::::::::|,,,,,, "**++g,,________,,,,,,mmm\::\:::::::\,,,,,,,,,,,,gnNN" ` .N)::/::.:::|::::::|::N|:::.''
//|:::. '::::::n":::/":::N" \:\::::::|,,,,,,,,,,,,,**/NN/*******,,,,,,,,`.|`.:::::|,,,,,, gnN*."'       \:.:::|::::\::::::\nN::/
//.|::::::::,n":::,":::,N    \:\:::::\,,,,,,,,,,,,,,/NN/,,,,,,,,,,,,,,,,,,|   `.  |ggnN**"   /           |::::|::::::::::::\Nm:|

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

typedef unsigned long long ull;
 
mt19937_64 r(std::chrono::high_resolution_clock::now().time_since_epoch().count());

ull const MASK30 = (1<<30)-1;
ull const MASK31 = INT_MAX;
ull const MOD = (1LL<<61)-1;
ull const MOD5 = MOD*5;
ull const base = r()%MOD;
 
struct RollingHash {
private:
    vector<ull> power,hash;
public:
    inline ull mul(ull a,ull b) {
        ull au = a>>31;
        ull ad = (a&MASK31);
        ull bu = b>>31;
        ull bd = (b&MASK31);
        ull mid = au*bd+ad*bu;
        return ((au*bu)<<1)+ad*bd+(mid>>30)+((mid&MASK30)<<31);
    }

    inline ull calcmod(ull a) {
        a = (a&MOD)+(a>>61);
        if (a > MOD) a -= MOD;
        return a;
    }

    RollingHash() {}
    RollingHash(string& s) {
        int n = s.size();
        power.resize(n+1);
        hash.resize(n+1);
        power[0] = 1;
        hash[0] = 0;
        for (int i = 0;i < n;++i) power[i+1] = calcmod(mul(power[i],base));
        for (int i = 0;i < n;++i) hash[i+1] = calcmod(mul(hash[i],base)+s[i]);
    }

    ull get(int l, int r)  {
        if (l) {
            return calcmod(hash[r]+MOD5-mul(hash[l],power[r-l]));
        }
        return hash[r];
    }
 
 
    ull connect(ull h1,int l,int r) {
        ull h2 = get(l,r);
        return calcmod(mul(h1,power[r-l])+h2);
    }
 
    int LCP(int l1,int r1,RollingHash& rh,int l2,int r2) {
        int ok = 0,ng = min(r1-l1,r2-l2)+1;
        while (ng-ok > 1) {
            int mid = (ok+ng)/2;
            if (get(l1,l1+mid) == rh.get(l2,l2+mid)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
};

struct BinaryIndexedTree {
private:
    int n,b;
    vector<int> bit;
public:
    BinaryIndexedTree() {}
    BinaryIndexedTree(int n_) {
        n = n_+10;
        b = 1;
        while (b < n) b <<= 1;
        b >>= 1;
        bit = vector<int>(n,0);
    }

    void add(int a,int w) {
        a++;
        for (int x = a;x < n;x += x&-x) bit[x] += w;
    }

    int sum(int a) {
        a++;
        int ret = 0;
        for (int x = a;x > 0;x -= x&-x) ret += bit[x];
        return ret;
    }

    void update(int a,int w) {
        // a++;
        int v = w-sum(a)+sum(a-1);
        add(a,v);
    }

    int lower_bound(int w) {
        if (w <= 0) return 0;
        int x = 0;
        for (int k = b;k > 0;k /= 2) {
            if (x+k < n && bit[x+k] < w) {
                w -= bit[x+k];
                x += k;
            }
        }
        return x;
    }
};

const char newl = '\n';

int main() {
    int n;
    cin >> n;
    vector<int> sz(n),sz_sum(n,0);
    vector<string> ss(n);
    vector<array<bool,26>> used(n);
    array<BinaryIndexedTree,26> sum;
    for (int i = 0;i < n;++i) used[i].fill(false);
    for (int i = 0;i < 26;++i) sum[i] = BinaryIndexedTree(n);
    for (int i = 0;i < n;++i) cin >> ss[i];
    for (int i = 0;i < n;++i) reverse(ss[i].begin(),ss[i].end());
    sort(ss.begin(),ss.end());
    for (int i = 0;i < n;++i) sz[i] = ss[i].size();
    for (int i = 0;i < n-1;++i) sz_sum[i+1] = sz_sum[i]+sz[i];
    string s = "";
    for (int i = 0;i < n;++i) s += ss[i];
    RollingHash rh(s);
    vector<P> a(n);
    priority_queue<P> pq;
    for (int i = 0;i < n;++i) a[i] = {-sz[i],i};
    sort(a.begin(),a.end());
    for (int i = 0;i < n;++i) pq.push({sz[i],i});
    ll ans = 0;
    for (P p : a) {
        while (!pq.empty() && pq.top().first >= -p.first) {
            P t = pq.top();pq.pop();
            for (int i = -p.first-1;i < t.first;++i) if (!used[t.second][ss[t.second][i]-'a']) {
                int c = ss[t.second][i]-'a';
                used[t.second][c] = true;
                sum[c].add(t.second+1,1);
            }
            if (-p.first > 1) pq.push({-p.first-1,t.second});
        }
        int ok = p.second,ng = n;
        while (abs(ok-ng) > 1) {
            int mid = (ok+ng)/2;
            (sz[mid] >= sz[p.second] && rh.get(sz_sum[p.second],sz_sum[p.second]+sz[p.second]-1) == rh.get(sz_sum[mid],sz_sum[mid]+sz[p.second]-1) ? ok : ng) = mid;
        }
        if (p.first == -1) ok = n-1;
        ans += sum[ss[p.second][sz[p.second]-1]-'a'].sum(ok+1);
        ok = p.second,ng = -1;
        while (abs(ok-ng) > 1) {
            int mid = (ok+ng)/2;
            (sz[mid] >= sz[p.second] && rh.get(sz_sum[p.second],sz_sum[p.second]+sz[p.second]-1) == rh.get(sz_sum[mid],sz_sum[mid]+sz[p.second]-1) ? ok : ng) = mid;
        }
        if (p.first == -1) ok = 0;
        ans -= sum[ss[p.second][sz[p.second]-1]-'a'].sum(ok);
        ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 56732