def check_marking(p, marking):
    """
    Tiny internal function that checks that ``marking`` is compatible with ``p``.

    OUTPUT:

        A 3-tuple.

    EXAMPLES::

        sage: import surface_dynamics.interval_exchanges.rauzy_class_cardinality as rcc
        sage: p = Partition([3,2,2])
        sage: rcc.check_marking(p, (1,3,1))
        (1, 3, 1)
        sage: rcc.check_marking(p, (1,3,2))
        (1, 3, 2)
        sage: rcc.check_marking(p, (1,3,3))
        Traceback (most recent call last):
        ...
        ValueError: marking[2] is not good
        sage: rcc.check_marking(p, (1,3,-1))
        Traceback (most recent call last):
        ...
        ValueError: marking[2] is not good
        sage: rcc.check_marking(p, (2,3,2))
        (2, 3, 2)
        sage: rcc.check_marking(p, (2,3,3))
        Traceback (most recent call last):
        ...
        ValueError: wrong marking type 2
    """
    if len(marking) != 3:
        raise ValueError('marking must be a 3-tuple (t,i,j)')
    if marking[0] == 1:
        if marking[1] not in p:
            raise ValueError('marking[1] not in p')
        if marking[2] < 0 or marking[2] > marking[1] - 1:
            raise ValueError('marking[2] is not good')
    elif marking[0] == 2:
        if marking[1] == marking[2]:
            if not p.to_exp()[marking[1] - 1] > 1:
                raise ValueError('wrong marking type 2')
        elif marking[1] not in p or marking[2] not in p:
            raise ValueError('marking not in p')
    else:
        raise ValueError('marking[0] must be 1 or 2')
    return tuple(marking)
