# Arup Guha
# 7/18/2025
# Solution? to Kattis Problem: Dance Recital
# https://open.kattis.com/problems/dancerecital

'''
Key is to store number of quick changes between all pairs of routines
first, instead of recalculating them 30 million times.

10! is about 3 million
and each permutation has 9 transitions to calculate...
'''

'''
Storage of routines using bitwise operators...

ABF --> A = 0, B = 1, F = 5 also the binary number 000100011

for # of quick changes, we do a bitwise and, and then count the
# of bits on in the result.
'''

# Returns the number of bits on in n.
def bitson(n):

    i = 0
    res = 0

    # Go until bit i is too high.
    while (1<<i) <= n:

        # If bit i is on in n, add 1.
        if (n & (1<<i)) != 0:
            res += 1

        # Go to next bit.
        i += 1

    # Return the number of bits on.
    return res

# Returns a table with the number of
def numquicktable(routines):

    # Makes an n by n table of 0s.
    n = len(routines)
    table =[]
    for i in range(n):
        table.append([])
        for j in range(n):
            table[-1].append(0)

    # Calculate # of quick changes between all pairs of routines.
    for i in range(n):
        for j in range(n):
            table[i][j] = bitson(routines[i]&routines[j])

    return table

# Returns the cost of perm using the quick change info in table.
def evaluate(perm,table):

    res = 0

    # Loop through all transitions adding up costs and return.
    for i in range(len(perm)-1):
        res += table[perm[i]][perm[i+1]]
    return res
    
# Returns the best answer with the first k dance routines fixed.
def go(perm, used, table, k):

    # If we're done, return the number of quick changes here.
    if k == len(perm):
        return evaluate(perm, table)

    # This will get overwritten.
    res = 1000000

    # Try each routine in position k.
    for i in range(len(perm)):

        # This routine is already placed.
        if used[i]:
            continue

        # Place item i in slot k.
        used[i] = True
        perm[k] = i
        
        # Update our answer if this is better than anything we've seen.
        res = min(res, go(perm, used, table, k+1))

        # No long using i.
        used[i] = False

    # This is our answer.
    return res

def main():

    # Get number of routines.
    n = int(input())
    routines = []

    # Read in routines.
    for i in range(n):
        s = input().strip()

        # Convert s to a corresponding bitmask where bit i is on iff dancer i is in the routine.
        mask = 0
        for x in s:
            mask |= (1<<(ord(x)-ord('A')))

        # Add to array of routines.
        routines.append(mask)

    # Set these up.
    perm = [0]*n
    used = [False]*n

    # Run it and print best answer.
    print(go(perm, used, numquicktable(routines), 0))

# Run it.
main()

