#include <bits/stdc++.h>

#define MAX 200010

using namespace std;

const uint64_t base = mt19937_64(chrono::system_clock::now().time_since_epoch().count())();

int n, m, k;
char str[MAX];
bitset<16> dp[MAX][16];

uint64_t get_sh(string s){
    sort(s.begin(), s.end());
    uint64_t h = 0;
    for (auto c: s) h = h * base + c;
    return h;
}

inline bool check(int idx1, int idx2, const string& s1, const string& s2, bool small){
    int i = 0, j = k - 1;
    while (s1[i] == s2[i]) i++;
    while (s1[j] == s2[j]) j--;
    if (small) return dp[idx1][i][j] | dp[idx2][i][j];

    int l, flag1 = 0, flag2 = 0;
    for (l = i; l < j && !(flag1 & flag2); l++){
        flag1 |= (s1[l + 1] < s1[l]);
        flag2 |= (s2[l + 1] < s2[l]);
    }

    return !(flag1 & flag2);
}

int main(){
    int i, j, l;

    scanf("%d", &n);
    unordered_map<uint64_t, vector<string>> mp;
    long long cnt1 = 0, cnt2 = 0, total = (long long)n * (n - 1) / 2;

    while(n--){
        scanf("%s", str);
        auto s = string(str);
        auto h = get_sh(s);
        mp[h].push_back(s);
    }

    for (auto it: mp){
        auto v = it.second;
        sort(v.begin(), v.end());
        m = v.size(), k = v[0].length();

        long long c1 = 0;
        if (k <= 16){
            for (i = 0; i < m; i++){
                for (j = 0; j < k; j++){
                    dp[i][j][j] = 1;
                    for (l = j + 1; l < k; l++){
                        dp[i][j][l] = dp[i][j][l - 1] & (v[i][l] >= v[i][l - 1]);
                    }
                }
            }

            for (i = 0; i < m; i++){
                for (j = i + 1; j < m; j++){
                    c1 += check(i, j, v[i], v[j], true);
                }
            }
        }
        else{
            for (i = 0; i < m; i++){
                for (j = i + 1; j < m; j++){
                    c1 += check(i, j, v[i], v[j], false);
                }
            }
        }

        cnt1 += c1;
        cnt2 += ((long long)m * (m - 1) / 2 - c1);
    }

    long long res = 1337 * (total - cnt1 - cnt2) + cnt1 + cnt2 * 2;
    printf("%lld\n", res);
    return 0;
}
