def interval_union(intervals):
    """
    Returns total size of intervals, expect interval as (chr, left, right)
    """
    intervals.sort()

    total_len = 0
    cur_chr, cur_left, cur_right = intervals[0] # left-most interval
    for interval in intervals:
        # open a new interval if left > cur_right or chr != cur_chr
        if interval[1] > cur_right or interval[0] != cur_chr:
            total_len += cur_right - cur_left + 1
            cur_chr, cur_left, cur_right = interval
        else:
            # update cur_right
            cur_right = max(interval[2], cur_right)

    # the last one
    total_len += cur_right - cur_left + 1

    return total_len