def follows(trace, distance=1):
    """Returns a mapping (aka. dict) from pairs of activities to frequency.
    A pair (a, b) is part of the mapping if activity b directly follows activity a,
    in any of the traces.

    Parameters
    ----------
    distance: int
        Distance two activities have to be appart to be counted in the mapping.
    """

    if not isinstance(trace, tuple):
        raise ValueError("Trace has to be a tuple of activities.")
    if not float(distance).is_integer():
        raise ValueError("Distance has to be an integer.")
    if not distance >= 1:
        raise ValueError("Distance has to be greater or equal to 1.")

    pairs = dict()

    for i in range(len(trace) - distance):
        ai = trace[i]
        aj = trace[i + distance]

        if (ai, aj) not in pairs:
            pairs[(ai, aj)] = 0

        pairs[(ai, aj)] += 1

    return pairs