n=int(input()) ss=[] d={} B=1007 M=1000000007 P=[1] for i in range(1,10): P+=[P[-1]*B%M] for i in range(n): s=input() h=0 for j in range(len(s)): h+=ord(s[j])*P[j] h%=M if h not in d: d[h]=0 d[h]+=1 for j in range(len(s)): h-=ord(s[j])*P[j] h+=ord("?")*P[j] h%=M if h not in d: d[h]=0 d[h]+=1 h-=ord("?")*P[j] h+=ord(s[j])*P[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])*P[j] h%=M c=0 for j in range(len(s)): h-=ord(s[j])*P[j] h+=ord("?")*P[j] h%=M c+=d[h]-1 h-=ord("?")*P[j] h+=ord(s[j])*P[j] h%=M print(c)