#include<bits/stdc++.h>
using namespace std;
int ch[1000005][26],sum[1000005][26],s[200005],c[200005],tot,
siz[1000005],le[26];
string str[200005];
bool cmp(int x,int y){return s[x]>s[y];}
int main()
{
    int n;
    long long ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)cin>>str[i],s[i]=str[i].size(),c[i]=i;
    sort(c+1,c+n+1,cmp);
    for(int i=1;i<=n;i++)
    {
        int now=0;
        for(int j=0;j<str[c[i]].size();j++)
            le[str[c[i]][j]-'a']++;
        for(int j=str[c[i]].size()-1;j>0;j--)
            if(!ch[now][str[c[i]][j]-'a'])goto nxt;
            else now=ch[now][str[c[i]][j]-'a'];
        ans+=siz[ch[now][str[c[i]][0]-'a']]+sum[now][str[c[i]][0]-'a'];
        nxt:;
        now=0;
        for(int j=str[c[i]].size();j>=0;j--)
        {
            if(j!=s[c[i]])
            {
                if(!ch[now][str[c[i]][j]-'a'])ch[now][str[c[i]][j]-'a']=++tot;
                now=ch[now][str[c[i]][j]-'a'];
                siz[now]++;
                le[str[c[i]][j]-'a']--;
            }
            for(int k=0;k<=25;k++)
                if(le[k]&&str[c[i]][j-1]-'a'!=k)
                    sum[now][k]++;
        }
    }
    printf("%lld",ans);
    return 0;
}