def paeth_predictor(left: int, above: int, upper_left: int) -> int:
    """Selected a value according to the Paeth predictor algorithm.

    See https://www.w3.org/TR/PNG-Filters.html for more information.

    :param left: The value of the pixel on the left of the current pixel.
    :type left: int
    :param above: The value of the pixel above the current pixel.
    :type above: int
    :param upper_left: The value of the pixel on the left and above of the
        current pixel.
    :type upper_left: int
    :return: The selected value
    :rtype: int
    """
    assert type(left) == int
    assert type(above) == int
    assert type(upper_left) == int

    total = left + above - upper_left
    dist_to_left = abs(total - left)
    dist_to_above = abs(total - above)
    dist_to_upper_left = abs(total - upper_left)

    if dist_to_left <= dist_to_above and dist_to_left <= dist_to_upper_left:
        return left
    elif dist_to_above <= dist_to_upper_left:
        return above
    else:
        return upper_left