def sum_of_intervals(intervals):
length = 0
while intervals:
inter = intervals.pop()
print(inter)
print('outer')
for x in intervals:
print(x)
if (min(x) <= sum(set(inter)) <= max(x)) or (min(inter) <= sum(x) <= max(inter)):
inter = inter + x
intervals.remove(x)
print(intervals)
print(inter)
print('inner')
length = length + (max(inter) - min(inter))
return intervals, length
print(sum_of_intervals([[1, 5], [10, 20], [1, 6], [16, 19], [5, 11]]))