OIG XIV - kin

// https://szkopul.edu.pl/problemset/problem/oqqeraT6_Ae_iZBWLQiXOwuG/site/

#include <bits/stdc++.h>

using namespace std;

#define int long long

constexpr int sizik = 1000 * 1001, INF = 1e9 + 7;

#define ar std::array
#define pr std::pair
#define vec std::vector

typedef vec<vec<int>> _kra;
#define _p pr<int, int>
#define PRO(x) std::priority_queue<x, vec<x>, std::greater<x>>

void solve() {
    int n, l = 1;
    std::cin >> n;

    std::set<int> km;
    std::vector<pr<int, pr<int, int>>> v(n);

    for (auto& [a, b] : v) {
        std::cin >> a >> b.first;

        km.insert(a);
        km.insert(b.first);

        b.second = l++;
    }

    PRO(_p) q;

    std::queue<int> wolni;

    std::sort(v.begin(), v.end());
    v.push_back({INF, {INF, INF}});

    int all = 1, curr = 1, j = 0;
    wolni.push(all);

    std::vector<std::vector<int>> ans(2);

    for (const auto& a : km) {
        while (!q.empty() && q.top().first <= a) {
            wolni.push(q.top().second);
            q.pop();
            curr++;
        }

        while (v[j].first <= a) {
            if (wolni.empty()) {
                all++;
                wolni.push(all);
                ans.push_back({});
            }
            int Tm = wolni.front();
            wolni.pop();

            curr--;
            q.push({v[j].second.first, Tm});
            ans[Tm].push_back(v[j].second.second);
            j++;
        }
    }

    std::cout << all << '\n';
    for (int i = 1; i <= all; i++) {
        std::cout << ans[i].size() << " ";
        for (const auto& a : ans[i]) {
            std::cout << a << " ";
        }
        std::cout << '\n';
    }
}

int32_t main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);

    int t = 1;
    // std::cin >> t;

    for (; t > 0; t--) {
        solve();
    }

    return 0;
}