import numpy as np n = int(input()) lis = [] for _ in range(n): a = list(map(str,input())) flag = True for i in range(len(a)-1): if(a[i] > a[i+1]): flag = False break if(flag): lis.append(a) if(len(lis) == 0): print(0) else: lis_sort = np.sort(lis,axis=-1) i = 0 j = 1 ans = len(lis_sort[0]) while((i < len(lis)) & (j < len(lis))): if(lis_sort[i][-1] <= lis_sort[j][0]): ans += len(lis_sort[j]) i = j j += 1 print(ans)