def get_pad(shape, *, to):
    """Pad the shape to target size.

    Details
    -------
    Tries to pad symmetrically, but leans towards the origin
    if odd padding is required.
    """
    excess = [t - s for s, t in zip(shape, to)]
    assert all(e >= 0 for e in excess)  # safegurad
    pad = []
    # start from the last dimension and move forward (see `F.pad`)
    for exc in reversed(excess):
        div, mod = divmod(exc, 2)
        pad.extend((div, div + mod))
    # divmod guarantees that div + (div + mod) == exc, so no safeguard here
    return pad