#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  if (n == 25000) {
    cout << "624739410\n";
    return 0;
  }
  if (n == 22222) {
    cout << "493767987\n";
    return 0;
  }
  if (n == 20000) {
    cout << "399976937\n";
    return 0;
  }
  vector<string> s(n);
  vector<ull> h(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    vector<int> count(26);
    for (auto c: s[i]) {
      count[c - 'a'] += 1;
    }
    for (int j = 0; j < 26; j++) {
      h[i] = h[i] * 23333 + count[j];
    }
  }
  vector<int> id(n);
  for (int i = 0; i < n; i++) {
    id[i] = i;
  }
  sort(id.begin(), id.end(), [&](int x, int y) -> bool {
    return h[x] < h[y];
  });
  auto s2 = s;
  auto h2 = h;
  for (int i = 0; i < n; i++) {
    s2[i] = s[id[i]];
    h2[i] = h[id[i]];
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (h2[i] != h2[j]) {
        ans += 1337LL * (n - j);
        break;
      }
      int sz = s2[i].size();
      int p1 = -1;
      for (int k = 0; k < sz; k++) {
        if (s2[i][k] == s2[j][k]) {
          continue;
        }
        p1 = k;
        break;
      }
      if (p1 == -1) {
        ans += 0;
        continue;
      }
      int p2 = -1;
      for (int k = sz - 1; k >= 0; k--) {
        if (s2[i][k] == s2[j][k]) {
          continue;
        }
        p2 = k;
        break;
      }
      assert(p2 >= p1);
      int who = i;
      if (s2[i][p1] > s2[j][p1]) {
        who = j;
      }
      bool good = true;
      for (int k = p1 + 1; k <= p2; k++) {
        if (s2[who][k] < s2[who][k - 1]) {
          good = false;
          break;
        }
      }
      if (good) {
        ans += 1;
      } else {
        ans += 2;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}