#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef double db;
#define ls(x) ((x)<<1)
#define rs(x) ((x)<<1|1)
#define low(x) ((x)&-(x))
#define all(x) x.begin(),x.end()
#define mp make_pair
#define X first
#define Y second
#ifdef _DEBUG
    const int N=1e3+10;
#else
    const int N=1e6+10;
#endif
const ll mod=1e9+7;
//const ll mod=998244353;
inline ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
inline ll q_pow(ll a,ll x){ll ans=1,tmp=a;while(x){if(x&1)(ans*=tmp)%=mod;(tmp*=tmp)%=mod;x>>=1;}return ans;}
template<typename T> inline void re(T &N){int f=1;char c;while((c=getchar())< '0'||c> '9')if(c=='-')f=-1;N=c-'0';while((c=getchar())>='0'&&c<='9')N=N*10+c-'0';N*=f;}
int m,n,t=1,st,en;
string s[N];

namespace s1{
    int c1[30],c2[30];
    ll solve()
    {
        ll ans=0;
        for(int i=1;i<=n;i++)
            for(int j=i+1;j<=n;j++)
            {
                memset(c1,0,sizeof(c1));
                memset(c2,0,sizeof(c2));
                for(int k=0;k< m;k++)
                {
                    c1[s[i][k]-'a']++;
                    c2[s[j][k]-'a']++;
                }
                int res=2;
                for(int k=0;k< 26;k++)
                    if(c1[k]!=c2[k]){res=1337;break;}
                if(res==1337){ans+=1337;continue;}
                int pre=-1,suf=m;
                for(int k=0;k< m;k++)
                {
                    if(s[i][k]==s[j][k])pre=k;
                    else break;
                }
                for(int k=m-1;k>=0;k--)
                {
                    if(s[i][k]==s[j][k])suf=k;
                    else break;
                }
                int ok=3;
                for(int k=pre+1;k< suf-1&&ok;k++)
                {
                    if(s[i][k]> s[i][k+1])ok&=2;
                    if(s[j][k]> s[j][k+1])ok&=1;
                }
                ans+=res-(ok> 0);
            }
        return ans;
    }
}
namespace s2{
    int c1[30],c2[30];
    inline int cmp(const string &a,const string &b)
    {
        memset(c1,0,sizeof(c1));
        memset(c2,0,sizeof(c2));
        for(int i=0;i< m;i++)
        {
            c1[a[i]-'a']++;
            c2[b[i]-'a']++;
        }
        for(int i=0;i< 26;i++)
            if(c1[i]!=c2[i])return c1[i]< c2[i];
        return a< b;
    }
    inline int check(const string &a,const string &b)
    {
        memset(c1,0,sizeof(c1));
        memset(c2,0,sizeof(c2));
        for(int i=0;i< m;i++)
        {
            c1[a[i]-'a']++;
            c2[b[i]-'a']++;
        }
        for(int i=0;i< 26;i++)
            if(c1[i]!=c2[i])return 0;
        return 1;
    }
    ll solve()
    {
        ll ans=0;
        sort(s+1,s+n+1,cmp);
        for(int l=1,r=1;l<=n;l=r=r+1)
        {
            while(r< n&&check(s[l],s[r+1]))r++;
            ans+=1337ll*(r-l+1)*(n-r);
            int sum=0;
            for(int i=0;i< m;i++)
                for(int j=i+1;j< m;j++)
                    for(int k=l;k<=r;k++)
                    {
                        string tmp=s[k];
                        sort(tmp.begin()+i,tmp.begin()+j+1);
                        if(tmp[i]!=s[k][i]&&tmp[j]!=s[k][j]&&binary_search(s+l,s+r+1,tmp))sum++;
                    }
            ans+=1ll*(r-l+1)*(r-l)-sum;
        }
        return ans;
    }
}
int main()
{
    #ifdef _DEBUG
        freopen("data.txt","r",stdin);
    #endif
    ios::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>s[i];
    m=s[1].length();
    
    if(n<=5000)cout<<s1::solve()<<'\n';
    else cout<<s2::solve()<<'\n';
}
