def group_ends(ends):
    return ([e for (e, s) in ends if (s == 0)], [e for (e, s) in ends if (s == (- 1))])
def group_ends(ends):
    return ([e for (e, s) in ends if (s == 0)], [e for (e, s) in ends if (s == (- 1))])