#!/usr/bin/python


class FilterRanges:
    def __init__(self):
        self.ranges = []

    def add_range(self, new):
        assert len(new) >= 2
        assert isinstance(new[0], (int, long))
        assert isinstance(new[1], (int, long))
        assert new[0] <= new[1]

        def overlap(r):
            if new[0] <= r[1] and new[1] >= r[0]:
                new[0] = min(r[0], new[0])
                new[1] = max(r[1], new[1])
                return True
            return False

        self.ranges = [r for r in self.ranges if not overlap(r)]

        self.ranges.append(new)

    def print_ranges(self):
        for r in self.ranges:
            print r


if __name__ == "__main__":
    a = FilterRanges()
    a.add_range([1, 5])
    print "1, 5"
    a.print_ranges()
    a.add_range([40, 41])
    print "\n40, 41"
    a.print_ranges()
    a.add_range([10, 15])
    print "\n10, 15"
    a.print_ranges()
    a.add_range([3, 12])
    print "\n3, 12"
    a.print_ranges()
    a.add_range([22, 23])
    print "\n22, 23"
    a.print_ranges()
    a.add_range([22, 23])
    print "\n22, 23"
    a.print_ranges()
    a.add_range([22, 24])
    print "\n22, 24"
    a.print_ranges()
    a.add_range([21, 24])
    print"\n21, 24"
    a.print_ranges()
    a.add_range([22, 23])
    print"\n22, 23"
    a.print_ranges()
    a.add_range([20, 25])
    print "\n20, 25"
    a.print_ranges()
    a.add_range([19, 26])
    print "\n19, 26"
    a.print_ranges()
    a.add_range([0, 24])
    print "\n0, 24"
    a.print_ranges()
