#include <bits/stdc++.h>   #define MP make_pair   using namespace std;      #define rep(i, n) for (int i = 0; i < (int)(n); ++ i)   #define rep1(i, n) for (int i = 1; i <= (int)(n); ++ i)   #define foreach(itr, c) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++ itr)      typedef long long LL;   typedef pair<int, int> pii;      const int MAXN = 2e5 + 5;      int N;   string str[MAXN];   map<string, vector<string> > grps;   LL ans;      int solve_pair(const string& s1, const string& s2)   {       int prefix = 0, suffix = 0, n = s1.size();          while (s1[prefix] == s2[prefix]) prefix ++;       while (s1[n - suffix - 1] == s2[n - suffix - 1]) suffix ++;          return is_sorted(s1.begin() + prefix, s1.end() - suffix) || is_sorted(s2.begin() + prefix, s2.end() - suffix) ? 1ll : 2ll;   }   void solve(vector<string>& grp)   {       int n = grp.size(), len = grp[0].size();       ans -= 1ll * (n - 1) * n / 2 * 1337;          if (n <= 200 * len) {           rep(i, n) for (int j = i + 1; j < n; ++ j) {               ans += solve_pair(grp[i], grp[j]);           }       } else {           sort(grp.begin(), grp.end());           ans += 1ll * (n - 1) * n / 2 * 2;              for (auto& s : grp) {               rep(i, len) for (int j = i + 2; j <= len; ++ j) {                   string sorted = s;                   sort(sorted.begin() + i, sorted.begin() + j);                   ans -= (sorted[i] != s[i] && sorted[j - 1] != s[j - 1] && binary_search(grp.begin(), grp.end(), sorted));               }           }       }   };      int main()   {       scanf( %d , &N);       rep(i, N) {           cin >> str[i];           string sorted = str[i];           sort(sorted.begin(), sorted.end());           grps[sorted].push_back(str[i]);       }          ans = 1ll * (N - 1) * N / 2 * 1337;          for (auto& grp : grps) solve(grp.second);          printf( %lld n , ans);              return 0;   }