Under construction

Still being built. Things may change

Convention Center

Interview

Time limit2sMemory limit64 MB

Summary
Choose the largest set of non-overlapping day intervals, breaking ties by picking the set of group indices that is lexicographically smallest.
Level

Medium6 of 10

Topics
Greedy, Sorting, Binary search, Intervals
Solved
No attempts yet

Problem

The government of Siruseri has built a new convention center. Many groups want to use it to hold meetings. While one group is using the convention center, no other group may use it during that time. The director of the center wants to choose the groups so that as many groups as possible can use the center. Of course, there may be several ways to make such a choice.

For example, consider four groups that want to use the center for the day ranges [4,9][4, 9], [9,11][9, 11], [13,19][13, 19], and [10,17][10, 17] respectively (this is the sample below). At most two of these groups can use the center. The candidate choices are {1,3}\{1, 3\}, {2,3}\{2, 3\}, and {1,4}\{1, 4\}. Note that two groups conflict when the ending day of one and the starting day of another coincide: groups 1 and 2 both use day 99, so they cannot both be chosen.

When several maximum choices exist, the director selects the groups by the following rule. The groups are numbered in the order in which they applied, and each candidate set is written with its group numbers in ascending order. Among all such candidate sets, the one that comes first in lexicographical order is chosen. In the example, the three candidate sets {1,3}\{1, 3\}, {2,3}\{2, 3\}, {1,4}\{1, 4\} are ordered (1,3)<(1,4)<(2,3)(1, 3) < (1, 4) < (2, 3), so the first one, {1,3}\{1, 3\} (groups 1 and 3), is selected.

Your task is to help the director decide which groups will use the convention center.

Input

The first line contains one integer NN (N≤200000N \le 200000), the number of groups that want to use the convention center.

Each of the next NN lines contains two integers, given in order of group number: the starting day and the ending day for which that group wants to use the center. Every starting day is at least 11, and every ending day does not exceed 10910^9.

Output

On the first line, print the maximum number MM of groups that can use the convention center. On the second line, print in ascending order the numbers of the MM groups of the choice that comes first in lexicographical order.

Note

For two lists l1l_1 and l2l_2, l1l_1 is smaller than l2l_2 in lexicographical order if l1l_1 is a prefix of l2l_2, or if at the first position jj where they differ, l1[j]<l2[j]l_1[j] < l_2[j].

Examples1

  1. Example 1

    Input
    4
    4 9
    9 11
    13 19
    10 17
    
    Expected output
    2
    1 3