from collections import Counter

from string import ascii_lowercase



n = int(eval(input()))

sss = [eval(input()) for _ in range(n)]

flags = {c: 1 << (ord(c) - 97) for c in ascii_lowercase}



trie_chr = [-1]

trie_children = [{}]

trie_counter = [0]

trie_fin = [0]

l = 1



for s in sss:

    node = 0

    trie_counter[node] += 1

    for i in range(len(s) - 1, 0, -1):

        c = ord(s[i]) - 97

        if c in trie_children[node]:

            node = trie_children[node][c]

            trie_counter[node] += 1

        else:

            trie_chr.append(c)

            trie_children.append({})

            trie_fin.append(0)

            trie_children[node][c] = l

            trie_counter.append(1)

            node = l

            l += 1

    trie_fin[node] |= flags[s[0]]



ans = 0



for s in sss:

    cnt = Counter(s)

    flag = 0

    for c in cnt:

        flag |= flags[c]

    node = 0

    if len(s) > 1 and trie_fin[node] > 0:

        ans += bin(trie_fin[node] & flag).count('1')



    for i in range(len(s) - 1, 1, -1):

        c = s[i]

        cnt[c] -= 1

        if cnt[c] == 0:

            flag ^= flags[c]

        k = ord(c) - 97

        node = trie_children[node][k]

        if trie_counter[node] == 1:

            break

        if trie_fin[node] > 0:

            ans += bin(trie_fin[node] & flag).count('1')



print(ans)

from collections import Counter

from string import ascii_lowercase



n = int(eval(input()))

sss = [eval(input()) for _ in range(n)]

flags = {c: 1 << (ord(c) - 97) for c in ascii_lowercase}



trie_chr = [-1]

trie_children = [{}]

trie_fin = [0]

l = 1



for s in sss:

    node = 0

    for i in range(len(s) - 1, 0, -1):

        c = ord(s[i]) - 97

        if c in trie_children[node]:

            node = trie_children[node][c]

        else:

            trie_chr.append(c)

            trie_children.append({})

            trie_fin.append(0)

            trie_children[node][c] = l

            node = l

            l += 1

    trie_fin[node] |= flags[s[0]]



ans = 0



for s in sss:

    cnt = Counter(s)

    flag = 0

    for c in cnt:

        flag |= flags[c]

    node = 0

    if len(s) > 1 and trie_fin[node] > 0:

        ans += bin(trie_fin[node] & flag).count('1')



    for i in range(len(s) - 1, 1, -1):

        c = s[i]

        cnt[c] -= 1

        if cnt[c] == 0:

            flag ^= flags[c]

        k = ord(c) - 97

        node = trie_children[node][k]

        if trie_fin[node] > 0:

            ans += bin(trie_fin[node] & flag).count('1')



print(ans)

from collections import Counter
from string import ascii_lowercase

n = int(eval(input()))
sss = [eval(input()) for _ in range(n)]
flags = {c: 1 << (ord(c) - 97) for c in ascii_lowercase}
trie_chr = [-1]
trie_children = [{}]
trie_counter = [0]
trie_fin = [0]
l = 1
for s in sss:
    node = 0
    trie_counter[node] += 1
    for i in range(len(s) - 1, 0, -1):
        c = ord(s[i]) - 97
        if c in trie_children[node]:
            node = trie_children[node][c]
            trie_counter[node] += 1
        else:
            trie_chr.append(c)
            trie_children.append({})
            trie_fin.append(0)
            trie_children[node][c] = l
            trie_counter.append(1)
            node = l
            l += 1
    trie_fin[node] |= flags[s[0]]
ans = 0
for s in sss:
    cnt = Counter(s)
    flag = 0
    for c in cnt:
        flag |= flags[c]
    node = 0
    if len(s) > 1 and trie_fin[node] > 0:
        ans += bin(trie_fin[node] & flag).count("1")
    for i in range(len(s) - 1, 1, -1):
        c = s[i]
        cnt[c] -= 1
        if cnt[c] == 0:
            flag ^= flags[c]
        k = ord(c) - 97
        node = trie_children[node][k]
        if trie_counter[node] == 1:
            break
        if trie_fin[node] > 0:
            ans += bin(trie_fin[node] & flag).count("1")
print(ans)

from collections import Counter
from string import ascii_lowercase

n = int(eval(input()))
sss = [eval(input()) for _ in range(n)]
flags = {c: 1 << (ord(c) - 97) for c in ascii_lowercase}
trie_chr = [-1]
trie_children = [{}]
trie_fin = [0]
l = 1
for s in sss:
    node = 0
    for i in range(len(s) - 1, 0, -1):
        c = ord(s[i]) - 97
        if c in trie_children[node]:
            node = trie_children[node][c]
        else:
            trie_chr.append(c)
            trie_children.append({})
            trie_fin.append(0)
            trie_children[node][c] = l
            node = l
            l += 1
    trie_fin[node] |= flags[s[0]]
ans = 0
for s in sss:
    cnt = Counter(s)
    flag = 0
    for c in cnt:
        flag |= flags[c]
    node = 0
    if len(s) > 1 and trie_fin[node] > 0:
        ans += bin(trie_fin[node] & flag).count("1")
    for i in range(len(s) - 1, 1, -1):
        c = s[i]
        cnt[c] -= 1
        if cnt[c] == 0:
            flag ^= flags[c]
        k = ord(c) - 97
        node = trie_children[node][k]
        if trie_fin[node] > 0:
            ans += bin(trie_fin[node] & flag).count("1")
print(ans)

-trie_counter = [0] -    trie_counter[node] += 1 -            trie_counter[node] += 1 -            trie_counter.append(1) -        if trie_counter[node] == 1: -            break