from typing import Counter


def permutation_rank(word):
    """
    Based on
    https://github.com/thedavidwells/Lexicographical-Word-Rank/blob/master/word_rank.py

    >>> permutation_rank("BBGGGG")
    0

    >>> permutation_rank("GBGGBG")
    7

    >>> permutation_rank("GGGGBB")
    14

    >>> permutation_rank("GGBGBBGBBBGBBBBGGGGGBBBBBGGGGBGGGBGGBGBB")
    114581417273
    """
    rank = 0
    permutations = 1

    word_length = len(word)
    myCounter = Counter()

    for i in range(word_length):
        permutationContainer = word[((word_length - 1) - i)]
        myCounter[permutationContainer] += 1

        for j in myCounter:

            if j < permutationContainer:
                rank += permutations * myCounter[j] // myCounter[permutationContainer]

        permutations = (permutations * (i + 1)) // myCounter[permutationContainer]

    return rank