# 公式解説による二重ループを避ける方法 # それぞれの名前の一字替えをdefaultdictに入れて数え上げる N = int(input()) from collections import defaultdict dic = defaultdict(int) S = [] for i in range(N): temp = input() S.append(temp) for j in range(len(temp)): s = temp[:j] + '?' + temp[j+1:] dic[s] += 1 #print(dic) for s in S: ans = 0 for j in range(len(s)): temp = s[:j] + '?' + s[j+1:] ans += max(0, dic[temp]-1) # 自らの変形分である1を引く必要ある print(ans)