def merge_update_lists(xs, ys):
    """
    Merge two update lists:

    - adding where `xs[i] is not None and ys[i] is not None`
    - copying `xs[i]` if `xs[i] is not None`
    - copying `ys[i]` otherwise
    """

    assert len(xs) == len(ys), "%i %i" % (len(xs), len(ys))
    ret = []

    for x, y in zip(xs, ys):
        if y is None:
            ret.append(x)
        elif x is None:
            ret.append(y)
        else:
            # Merge.
            ret.append(x + y)

    return ret