def in_interval(seg, intervals):
    """Checks if the given (start, end) segment overlaps the list of intervals"""
    intervals = sorted(intervals)
    a, b = seg
    for s, t in intervals:
        if s > b: break
        if t < a: continue
        return 1
    return 0