#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
#define maxn 2000000
#define base 199
using namespace std;
int n,k;
ll hashmod,ans,tot;
ll h[maxn],ha[maxn];
int son[maxn][27],sum[maxn],f[maxn],len[maxn];
string s[maxn],ch;
int main()
{
h[0]=1;
for (int i=1; i<=maxn+10; i++) h[i]=h[i-1]*base;
cin>>n;
ans=-n;
for (int i=1; i<=n; i++)
{
cin>>len[i];
cin>>ch;
s[i]=‘ ‘+ch;
int p=0; hashmod=0;
for (int j=1; j<=len[i]; j++)
{
int x=s[i][j]-‘a‘+1;
if (!son[p][x]) son[p][x]=++tot;
p=son[p][x];
hashmod=hashmod*base+x;
}
//cout<<hashmod<<endl;
ha[i]=hashmod;
f[p]=i; sum[p]++;
}
//cout<<tot;
for (int i=1; i<=n; i++)
{
int p=0;
for (int j=1; j<=len[i]; j++)
{
int x=s[i][j]-‘a‘+1;
p=son[p][x];
// cout<<p<<endl;
//if (sum[p] && ha[f[p]]*h[len[i]]+ha[i]==ha[i]*h[j+1]+ha[f[p]]) ans+=(ll)sum[p]*2;
if(son[p]&&ha[f[p]]*h[len[i]]+ha[i]==ha[i]*h[j]+ha[f[p]])ans+=(ll)sum[p]*2;
}
}
printf("%lld\n",ans);
return 0;
}