import itertools


def all_segments(N):
    """Return (start, end) pairs of indexes that form segments of tour of length N."""
    return (
        (start, end)
        for (start, end) in itertools.combinations(range(N), 2)
        if end > start+1
        )