def pad(traces, fill=0, end=None):
    """Pads all the traces signals have the same duration.

    If ``end`` parameter is not provided the traces are padded to have
    the same duration as the longest given trace.

    Parameters
    ----------
    traces : list[list[int]]
        2D list of numbers representing the trace signal.
    fill : int, optional
        Padding value to insert after the end of traces.
    end : int, optional
        New count of samples of the traces.
        Must be greater than the length of the longest trace.
    Returns
    -------
    list[list[int]]
        Padded traces.

    """
    samples = list(map(len, traces))
    m = max(samples)
    m = max(end or m, m)
    return [trace + [fill] * (m - read) for trace, read in zip(traces, samples)]