#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Wed Aug 26 20:20:27 JST 2020
 **/

/// @docs src/String/RollingHash.md
template <class T> struct RollingHash {
    std::vector<int> hash, pows;
    int base, mod;
    RollingHash(const T &a, int base_, int mod_ = 1000000009)
        : hash(a.size() + 1), pows(a.size() + 1, 1), base(base_), mod(mod_) {
        for (int i = 0; i < a.size(); i++) {
            pows[i + 1] = (long long)pows[i] * base % mod;
            hash[i + 1] = ((long long)hash[i] * base % mod + a[i]) % mod;
            if (hash[i + 1] < 0) hash[i + 1] += mod;
        }
    }
    // 現在の文字列のサイズ
    int size() { return hash.size() - 1; }
    // [l, r)
    int get(int l, int r) {
        assert(l <= r);
        int ret = hash[r] + mod - (long long)hash[l] * pows[r - l] % mod;
        if (ret >= mod) ret -= mod;
        return ret;
    }
    void concat(const T &b) {
        int n = hash.size() - 1, m = b.size();
        pows.resize(n + m + 1);
        hash.resize(n + m + 1);
        for (int i = 0; i < m; i++) {
            pows[n + i + 1] = (long long)pows[n + i] * base % mod;
            hash[n + i + 1] = (long long)hash[n + i] * base % mod + b[i];
            if (hash[n + i + 1] >= mod) hash[n + i + 1] -= mod;
        }
    }
    void pop_back() {
        hash.pop_back();
        pows.pop_back();
    }
};

template <int HashNum> std::array<int, HashNum> make_rand_array() {
    std::array<int, HashNum> res;
    std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
    for (int i = 0; i < HashNum; i++) res[i] = rnd() % 1000000;
    return res;
}
template <class T, int HashNum = 4> struct MultiRollingHash {
    using multihash_t = std::array<int, HashNum>;
    static std::array<int, HashNum> bases;
    std::vector<RollingHash<T>> rhs;
    MultiRollingHash(const T &a) {
        for (int i = 0; i < HashNum; i++) {
            rhs.push_back(RollingHash<T>(a, bases[i]));
        }
    }
    multihash_t get(int l, int r) {
        multihash_t ret;
        for (int i = 0; i < HashNum; i++) ret[i] = rhs[i].get(l, r);
        return ret;
    }
    int size() { return rhs[0].size(); }
    void concat(const T &b) {
        for (auto &rh : rhs) rh.concat(b);
    }
    void pop_back() {
        for (auto &rh : rhs) rh.pop_back();
    }
};
template <class T, int HashNum>
std::array<int, HashNum> MultiRollingHash<T, HashNum>::bases = make_rand_array<HashNum>();

signed main() {
    Int n;
    std::cin >> n;
    std::vector<std::string> ss(n);
    REP(i, n) std::cin >> ss[i], std::reverse(ALL(ss[i]));
    std::sort(ALL(ss), [](const std::string &a, const std::string &b) { return a.size() < b.size(); });
    using Hash = std::array<int, 4>;
    std::map<Hash, std::vector<Int>> mp;
    Int ans = 0;
    for (const std::string &s : ss) {
        MultiRollingHash<std::string> rh(s);
        std::vector<bool> chars(26);
        for (Int i = s.size() - 1; i >= 0; i--) {
            chars[s[i] - 'a'] = true;
            Hash tmp = rh.get(0, i);
            if (mp.count(tmp)) {
                REP(c, 26) ans += chars[c] * mp[tmp][c];
            }
        }

        Hash tmp = rh.get(0, s.size() - 1);
        if (!mp.count(tmp)) mp[tmp] = std::vector<Int>(26);
        mp[tmp][s.back() - 'a']++;
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 50692