n=int(input()) ss=[] d={} M=1000000007 from random import randrange B=randrange(M) for i in range(n): s=input() h=0 for j in range(len(s)): h+=ord(s[j])*(B**j) h%=M if h not in d: d[h]=0 d[h]+=1 for j in range(len(s)): h-=ord(s[j])*(B**j) h+=ord("?")*(B**j) h%=M if h not in d: d[h]=0 d[h]+=1 h-=ord("?")*(B**j) h+=ord(s[j])*(B**j) h%=M ss+=[s] for i in range(n): s=ss[i] h=0 for j in range(len(s)): h+=ord(s[j])*(B**j) h%=M c=0 for j in range(len(s)): h-=ord(s[j])*(B**j) h+=ord("?")*(B**j) h%=M c+=d[h] h-=ord("?")*(B**j) h+=ord(s[j])*(B**j) h%=M c-=d[h]*len(s) print(c)