def checksum(spreadsheet):
    """
    Calculate the checksum of a spreadsheet by summing up the ranges of all
    lines.
    >>> checksum([
    ...     [5, 1, 9, 5],
    ...     [7, 5, 3],
    ...     [2, 4, 6, 8]
    ... ])
    18
    """
    return sum(
        max(line) - min(line)
        for line in spreadsheet
    )