def merge(match):
    dep = dict([(e[0], 0) for e in match])
    match = list(match)
    for (i, ma) in enumerate(match):
        for (j, mb) in enumerate(match[(i + 1):]):
            (ra, rb) = pairwise_merge((ma, mb))
            if (ra or rb):
                if (not ra):
                    dep[ma[0]] = 1
                if (not rb):
                    dep[mb[0]] = 1
    return ([k for (k, v) in dep.items() if (v == 0)], [k for (k, v) in dep.items() if (v != 0)])
def merge(match):
    dep = dict([(e[0], 0) for e in match])
    match = list(match)
    for (i, ma) in enumerate(match):
        for (j, mb) in enumerate(match[(i + 1):]):
            (ra, rb) = pairwise_merge((ma, mb))
            if (ra or rb):
                if (not ra):
                    dep[ma[0]] = 1
                if (not rb):
                    dep[mb[0]] = 1
    return ([k for (k, v) in dep.items() if (v == 0)], [k for (k, v) in dep.items() if (v != 0)])