Write a function called `sumIntervals`/`sum_intervals()` that accepts an array of intervals, and returns the sum of all the interval lengths. Overlapping intervals should only be counted once.

### Intervals

Intervals are represented by a pair of integers in the form of an array. The first value of the interval will always be less than the second value. Interval example: `[1, 5]` is an interval from 1 to 5. The length of this interval is 4.

### Overlapping Intervals

List containing overlapping intervals:

```
[
   [1,4],
   [7, 10],
   [3, 5]
]
```

The sum of the lengths of these intervals is 7. Since [1, 4] and [3, 5] overlap, we can treat the interval as [1, 5], which has a length of 4.

### Examples:

```C#
// empty intervals
Intervals.SumIntervals(new (int, int)[]{ });  // => 0
Intervals.SumIntervals(new (int, int)[]{ (2, 2), (5, 5)});  // => 0

// disjoined intervals
Intervals.SumIntervals(new (int, int)[]{
  (1, 2), (3, 5)
});  // => (2-1) + (5-3) = 3

// overlapping intervals
Intervals.SumIntervals(new (int, int)[]{
  (1, 4), (3, 6), (2, 8)
});  // (1,8) => 7
```

Difficulty: MEDIUM
Starter code: def sum_of_intervals(intervals):
	

Solutions:
def sum_of_intervals(intervals):
	(s, top) = (0, float('-inf'))
	for (a, b) in sorted(intervals):
		if top < a:
			top = a
		if top < b:
			(s, top) = (s + b - top, b)
	return s


def sum_of_intervals(intervals):
	result = set()
	for (start, stop) in intervals:
		for x in range(start, stop):
			result.add(x)
	return len(result)


def sum_of_intervals(intervals):
	return len(set([n for (a, b) in intervals for n in [i for i in range(a, b)]]))


def sum_of_intervals(intervals):
	s = []
	for i in intervals:
		s += list(range(i[0], i[1]))
	return len(set(s))


from itertools import chain

def sum_of_intervals(intervals):
	return len(set(chain.from_iterable((range(*i) for i in intervals))))


def sum_of_intervals(intervals):
	total = set()
	for (x, y) in intervals:
		for i in range(x, y):
			total.add(i)
	return len(total)


def sum_of_intervals(intervals):
	return len(set().union(*[list(range(*item)) for item in intervals]))


sum_of_intervals = lambda a: len(set.union(*(set(range(*i)) for i in a)))


def sum_of_intervals(intervals):
	result = set()
	for (start, end) in intervals:
		result |= set(range(start, end))
	return len(result)


def sum_of_intervals(intervals):
	sets = set()
	for (a, b) in intervals:
		sets.update(list(range(a, b)))
	return len(sets)


from bisect import bisect

def sum_of_intervals(intervals):
	I = []
	for (a, b) in intervals:
		i = bisect(I, a)
		j = bisect(I, b)
		I = I[:i] + [a] * (1 - i % 2) + [b] * (1 - j % 2) + I[j:]
	return sum(I[1::2]) - sum(I[::2])


def sum_of_intervals(intervals):
	return len(set([i for t in intervals for i in range(t[0], t[-1])]))


def sum_of_intervals(intervals):
	answer = []
	for tup in intervals:
		for j in range(tup[0], tup[1]):
			answer.append(j)
	return len(list(set(answer)))


def sum_of_intervals(intervals):
	intervals.sort()
	x = 0
	while x < len(intervals) - 1:
		if intervals[x][0] <= intervals[x + 1][0] and intervals[x][1] >= intervals[x + 1][1]:
			intervals.pop(x + 1)
		elif intervals[x][0] <= intervals[x + 1][0] and intervals[x][1] >= intervals[x + 1][0] and (intervals[x][1] < intervals[x + 1][1]):
			intervals[x] = (intervals[x][0], intervals[x + 1][1])
			intervals.pop(x + 1)
		else:
			x += 1
	return sum((intervals[x][1] - intervals[x][0] for x in range(len(intervals))))


def sum_of_intervals(intervals):
	list1 = []
	for i in intervals:
		for j in range(i[0], i[1]):
			list1.append(j)
	set1 = set(list1)
	return len(set1)


import functools

def sum_of_intervals(intervals):
	return len(functools.reduce(lambda x, y: x | y, [set(range(x, y)) for (x, y) in intervals]))


def sum_of_intervals(intervals):
	return len({a for interval in intervals for a in range(*interval)})


def sum_of_intervals(intervals):
	merged = sorted([list(t) for t in intervals])
	i = 0
	while i < len(merged) - 1:
		if merged[i + 1][1] <= merged[i][1]:
			del merged[i + 1]
			continue
		if merged[i + 1][0] <= merged[i][1]:
			merged[i][1] = merged[i + 1][1]
			del merged[i + 1]
			continue
		i += 1
	return sum((b - a for (a, b) in merged))