#include
using namespace std;
typedef set
struct cus { int l, r, i; }; inline bool rCmp(const cus& a, const cus& b) { if (a. r == b. r) return a. l > b. l; else return a. r < b. r; } inline bool iCmp(const cus& a, const cus& b) { return a. i < b. i; }
const int maxn = 400009; const int maxl = 19;
int n, m, t, v[maxn], tv, ut[maxn][maxl]; int ts[maxn]; cus a[maxn], b[maxn]; rbt le, re;
inline int succ(rbt& t, int v) { return *t. upper_bound(v); } inline int prev(rbt& t, int v) { rbt_it it(t. lower_bound(v)); if (it == t. end()) return *t. rbegin(); else return *(– it); }
int checkMax(int l, int r) { int s(0); for (int i = maxl - 1; i >= 0; – i) if (ut[l][i] <= tv && ut[l][i] <= r + 1) { s += 1 « i; l = ut[l][i]; } return s; }
int btQry(int* t, int p) { int s(0); for (++ p; p; p -= (p & -p)) s += t[p]; return s; } void btChg(int* t, int p, int v) { for (++ p; p < maxn; p += (p & -p)) t[p] += v; }
int main() { #ifndef ONLINE_JUDGE freopen(".in", “r”, stdin); #endif
scanf("%d", &n);
tv = 0;
for (int i = 0; i < n; ++ i) {
scanf("%d%d", &a[i]. l, &a[i]. r);
a[i]. i = i;
v[tv ++] = a[i]. l;
v[tv ++] = a[i]. r;
}
sort(v, v + tv);
tv = unique(v, v + tv) - v;
for (int i = 0; i < n; ++ i) {
a[i]. l = lower_bound(v, v + tv, a[i]. l) - v;
a[i]. r = lower_bound(v, v + tv, a[i]. r) - v;
}
sort(a, a + n, rCmp);
t = 0;
for (int i = 0; i < n; ++ i)
if (!t || a[i]. l > b[t - 1]. l)
b[t ++] = a[i];
m = 0;
for (int i = 0, l = -1; i < t; ++ i)
if (b[i]. l > l)
l = b[i]. r, ++ m;
for (int i = 0, j = 0; i < tv; ++ i) {
for (; j < t && i > b[j]. l; ++ j);
if (j == t)
ut[i][0] = tv + 1;
else
ut[i][0] = b[j]. r + 1;
}
ut[tv][0] = tv + 1;
for (int i = 0; i < maxl; ++ i)
ut[tv + 1][i] = tv + 1;
for (int i = tv; i >= 0; -- i)
for (int j = 1; j < maxl; ++ j)
ut[i][j] = ut[ut[i][j - 1]][j - 1];
re. insert(-1);
le. insert(tv);
sort(a, a + n, iCmp);
printf("%d\n", m);
memset(ts, 0, sizeof(ts));
for (int i = 0; i < n; ++ i)
if (btQry(ts, a[i]. r) - btQry(ts, a[i]. l - 1) == 0) {
int l(prev(re, a[i]. l)), r(succ(le, a[i]. r));
if (checkMax(l + 1, r - 1) == checkMax(l + 1, a[i]. l - 1) + checkMax(a[i]. r + 1, r - 1) + 1) {
for (int j = a[i]. l; j <= a[i]. r; ++ j)
btChg(ts, j, 1);
printf("%d ", i + 1);
le. insert(a[i]. l);
re. insert(a[i]. r);
}
}
}