Under construction

Still being built. Things may change

Kinomani

Interview

Time limit4sMemory limit1024 MB

Summary
Given N film screening intervals, find the fewest members needed to cover every film with non-overlapping viewings, and list each member's films.
Level

Medium4 of 10

Topics
Greedy, Intervals, Sorting, Heap
Solved
No attempts yet

Problem

Bajtek and his friends started a film club. Members go to cinemas to watch various films, then meet and tell each other about the films they saw. Their accounts are so detailed that a film told this way is practically the same as watching it.

The Silver Horizons film festival is coming up. Club members will be sent to watch films so that together they see all of them. Each film at the festival is screened only once, in a fixed time interval. To count a film as watched, a member must watch it in full, from start to finish. At any moment a member can watch only one film, but a member can finish one film and start another at the same moment. Tickets are expensive, so the club wants to send as few members as possible.

Write a program that reads the number of films and the time intervals in which each film is screened, finds the smallest number of club members to send to the festival, and prints the result to standard output.

Input

The first line contains a natural number NN, the number of films at the festival (1≤N≤2500001 \le N \le 250000). The next NN lines describe the films, one per line. Each line has two natural numbers SiS_i and TiT_i (1≤Si<Ti≤1091 \le S_i < T_i \le 10^9) separated by a single space. They mean that the ii-th film is screened from minute SiS_i to minute TiT_i of the festival.

Output

The first line contains a natural number RR, the smallest possible number of members needed to watch all films. The next RR lines describe one way to achieve this. Line i+1i+1 contains a natural number FiF_i, the number of films watched by the ii-th member, followed by a space and the FiF_i film numbers Mi,1,…,Mi,FiM_{i,1}, \ldots, M_{i,F_i}, separated by single spaces. Any valid assignment is accepted.

Examples2

  1. Example 1

    Input
    5
    1 5
    4 7
    1 3
    10 20
    12 15
    
    Expected output
    2
    2 1 5
    3 3 2 4
    
  2. Example 2

    Input
    5
    1 2
    5 6
    4 5
    2 3
    1 5
    
    Expected output
    2
    4 1 4 3 2
    1 5