from typing import List


def erase_overlap_intervals(intervals: List[List[int]]):
    """
    a variant for LeetCode 435
    Given a list of intervals, remove minimal intervals to make the rest of the intervals non-overlapping.
    注意：剩余列表中允许打乱原列表的顺序。如果要求保持原顺序，则需要在排序前先记录index。
    Examples:
        1. intervals: [[1, 2], [2, 3], [3, 4], [1, 3]], return: [[1, 2], [2, 3], [3, 4]], [[1, 3]]
        2. intervals: [1, 2], [1, 2], [1, 2]], return: [[1, 2]], [[1, 2], [1, 2]]
    :param intervals:
    :return:
        left_intervals: List[List[int]]
        remove_intervals: List[List[int]]
    """
    l = len(intervals)
    if l <= 1:
        return l, []
    intervals = sorted(intervals, key=lambda x: x[1])

    left, remove = [], []
    interval = intervals[0]
    end = interval[1]
    for x in intervals[1:]:
        if x[0] >= end:
            left.append(interval)
            interval = x
            end = x[1]
        else:
            remove.append(x)
    left.append(interval)

    return left, remove