#define __AVX__ 1
#define __AVX2__ 1
#define __SSE__ 1
#define __SSE2__ 1
#define __SSE2_MATH__ 1
#define __SSE3__ 1
#define __SSE4_1__ 1
#define __SSE4_2__ 1
#define __SSE_MATH__ 1
#define __SSSE3__ 1
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")

#include <bits/stdc++.h>

using namespace std;
#define rep(i, l, r) for(auto i=(l);i<=(r);++i)
#define per(i, r, l) for(auto i=(r);i>=(l);--i)
#define N 200020
#define ll long long
const int P1 = 31, D1 = 1000173169, P2 = 61, D2 = 1e9 + 7;
int f1[26][N], f2[26][N];
int pw1[N], pw2[N];

struct pair_hash {
    inline size_t operator()(const pair<int, int> &p) const {
        auto h1 = hash<int>{}(p.first);
        auto h2 = hash<int>{}(p.second);
        return h1 ^ h2;
    }
};

vector<int> ff1[N], ff2[N];

inline void build(int idx, string &s) {
    ff1[idx].resize(s.size() + 1), ff2[idx].resize(s.size() + 1);
    ff1[idx][0] = ff2[idx][0] = 0;
    rep(i, 1, s.size())ff1[idx][i] = 1ll * (1ll * ff1[idx][i - 1] * P1 + s[i - 1]) % D1;
    rep(i, 1, s.size())ff2[idx][i] = 1ll * (1ll * ff2[idx][i - 1] * P2 + s[i - 1]) % D2;
}

inline pair<int, int> hsh(int idx, int l, int r) {
    int h1 = 1ll * (ff1[idx][r] - 1ll * ff1[idx][l - 1] * pw1[r - l + 1] % D1 + D1) % D1;
    int h2 = 1ll * (ff2[idx][r] - 1ll * ff2[idx][l - 1] * pw2[r - l + 1] % D2 + D2) % D2;
    return {h1, h2};
}

struct node {
    int ct[26];
    string s;

    inline void read() {
        cin >> s;
        for (auto v:s)++ct[v - 97];
    }

    inline bool operator==(const node &b) const {
        rep(i, 0, 25)if (ct[i] != b.ct[i])return 0;
        return 1;
    }

    inline bool operator<(const node &b) const {
        rep(i, 0, 25)if (ct[i] != b.ct[i])return ct[i] > b.ct[i];
        return 0;
    }
} S[N];

int n;
unordered_map<pair<int, int>, int, pair_hash> mp, mmp;
map<node, int> MP;
vector<int> sm[N];

inline void solve() {
    cin >> n;
    rep(i, 1, n)S[i].read();
    int m = S[1].s.size();

    pw1[0] = pw2[0] = 1;
    rep(i, 1, m + 1)pw1[i] = 1ll * pw1[i - 1] * P1 % D1;
    rep(i, 1, m + 1)pw2[i] = 1ll * pw2[i - 1] * P2 % D2;

    rep(i, 1, n)build(i, S[i].s);

    if (n <= 4000) {
        rep(i, 1, n) {
            sm[i].resize(m + 1);
            sm[i][0] = 0;
            rep(j, 1, m) {
                sm[i][j] = sm[i][j - 1];
                if (j < m)sm[i][j] += S[i].s[j] < S[i].s[j - 1];
            }
        }
        auto f = [&](int &x, node &a, int &y, node &b) {
            if (!(a == b))return 1337;
            if (hsh(x, 1, m) == hsh(y, 1, m))return 0;
            /*int l = 1, r = m;
            while (l <= r) {
                int m = l + r >> 1;
                if (hsh(x, 1, m) == hsh(y, 1, m))l = m + 1;
                else r = m - 1;
            }
            int L = l;
            l = 1, r = m;
            while (l <= r) {
                int mid = l + r >> 1;
                if (hsh(x, mid, m) == hsh(y, mid, m))r = mid - 1;
                else l = mid + 1;
            }
            int R = r;*/
            //为啥二分过不了，暴力就过了
            int l = 0, r = a.s.size() - 1;
            while (l <= r && a.s[l] == b.s[l])++l;
            while (l <= r && a.s[r] == b.s[r])--r;
            int L = l + 1, R = r + 1;
            int res = 0;
            if (sm[x][R - 1] - sm[x][L - 1] == 0)++res;
            if (sm[y][R - 1] - sm[y][L - 1] == 0)++res;
            if (res > 0)return 1;
            return 2;
        };
        ll ans = 0;
        rep(i, 1, n)rep(j, i + 1, n)ans += f(i, S[i], j, S[j]);
        printf("%lld\n", ans);
        return;
    }
    rep(i, 1, n) {
        ++mp[hsh(i, 1, S[i].s.size())];
        ++MP[S[i]];
    }
    rep(j, 0, 25) {
        f1[j][0] = f2[j][0] = 0;
        rep(i, 1, N - 1)f1[j][i] = 1ll * (1ll * f1[j][i - 1] * P1 + j + 97) % D1;
        rep(i, 1, N - 1)f2[j][i] = 1ll * (1ll * f2[j][i - 1] * P2 + j + 97) % D2;
    }

    auto mix = [&](int *ct) {
        int x = f1[0][ct[0]], y = f2[0][ct[0]];
        rep(i, 1, 25) if (ct[i]) {
                x = (1ll * x * pw1[ct[i]] % D1 + f1[i][ct[i]]) % D1;
                y = (1ll * y * pw2[ct[i]] % D2 + f2[i][ct[i]]) % D2;
            }
        return pair<int, int>{x, y};
    };
    ll ans = 0;
    ll Ans = 0;
    auto hsmix = [&](pair<int, int> l, int len1, pair<int, int> r) {
        return pair<int, int>{(1ll * l.first * pw1[len1] % D1 + r.first) % D1,
                              (1ll * l.second * pw2[len1] % D2 + r.second) % D2};
    };
    int ct[26];
    rep(i, 1, n) {
        mmp.clear(), mmp[hsh(i, 1, m)] = 1;
        rep(l, 1, m) {
            rep(k, 0, 25)ct[k] = 0;
            ++ct[S[i].s[l - 1] - 97];
            int p = l + 1;
            while (p <= m && S[i].s[p - 1] >= S[i].s[p - 2])++ct[S[i].s[p - 1] - 97], ++p;
            rep(r, p, m) {
                ++ct[S[i].s[r - 1] - 97];
                auto mid = mix(ct);
                auto x = hsmix(hsh(i, 1, l - 1), r - l + 1, mid);
                x = hsmix(x, m - r, hsh(i, r + 1, m));
                if (mmp.count(x))continue;
                if (mp.count(x))ans -= mp[x];
                mmp[x] = 1;
            }
        }
        ans -= mp[hsh(i, 1, m)];
    }
    for (auto[u, v]:MP)Ans += 1337ll * v * (n - v), ans += 1ll * v * v;
    //printf("%d\n", ans);
    printf("%lld\n", ans + Ans / 2);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    //scanf("%d",&T);
    while (T--)solve();
}