from operator import itemgetter
import collections

tmp = [(0, 30), (0, 20), (10, 40), (30, 50), (50, 90), (70, 100), ]
aa = sorted(tmp, key=itemgetter(1)) # sort with respect to 1st elem
a = set(aa)
space = 100
d_conn = 15
RTT = d_conn*2
bandwidth = 10

def get_marginal_cost(fragment):
    return RTT + (fragment[1] - fragment[0])/bandwidth

def dfs(a, start, path=None):
    if path is None:
        path = [start, ]
    if start[1] == space:
        yield path
    for frgmt in a - set(path):
        l = frgmt[0]
        r = frgmt[1]
        if start[0] < l <= start[1] <= r:
#        if l <= start[1] <= r:
            yield dfs(a, frgmt, path + [frgmt, ])

for z in a:
    if z[0] == 0:
        for output in list(dfs(a, z)):
            for outpu in list(output):
                for outp in list(outpu):
                    for out in list(outp):
                        for ou in list(out):
                            print list(ou)