def countInversions(state):
    """
    Count the number of inversions in the given state
    :param state: Iterable (list of strings or ints expected, 'b' element accounted for)
    :return: number of inversions in the given state
    """
    n = len(state)
    invs = 0

    # Count inversions
    for i in range(n - 1):
        for j in range(i + 1, n):

            # Ignore blank tile 'b'
            if 'b' not in (state[i], state[j]):
                if state[i] > state[j]:
                    invs += 1
    return invs