def get_index(refname, indices, max_order):
    """Get the index of a monomial."""
    if refname == "interval":
        return indices[0]
    if refname == "triangle":
        return sum(indices) * (sum(indices) + 1) // 2 + indices[1]
    if refname == "quadrilateral":
        return indices[1] * (max_order + 1) + indices[0]
    if refname == "tetrahedron":
        return (sum(indices) * (sum(indices) + 1) * (sum(indices) + 2) // 6
                + sum(indices[1:]) * (sum(indices[1:]) + 1) // 2 + indices[2])
    if refname == "hexahedron":
        return indices[2] * (max_order + 1) ** 2 + indices[1] * (max_order + 1) + indices[0]
    if refname == "prism":
        return ((max_order + 2) * (max_order + 1) * indices[2] // 2
                + sum(indices[:2]) * (sum(indices[:2]) + 1) // 2 + indices[1])