PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000053. Sắp xếp bằng các dãy con (Sorting by Subsequences)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sắp xếp bằng các dãy con (Sorting by Subsequences)

Sorting by Subsequences

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array of nn pairwise distinct integers. Partition the entire set of indices {1,2,…,n}\{1,2,\ldots,n\} into nonempty groups, with every index belonging to exactly one group.

For each group, take the values currently stored at its indices and sort those values in increasing order, placing them back at the group's indices in increasing index order. Groups are disjoint, so they may be processed in any order. After every group is sorted, the whole array must be increasing.

Find a valid partition with the maximum possible number of groups. Print the number of groups and their index lists. If several optimal partitions exist, you may output any of them.

Input

The first line contains nn, then nn pairwise distinct integers aia_i with −109≤ai≤109-10^9\le a_i\le10^9.

Output

Print the number kk of subsequences, then one line per subsequence containing its size cic_i and its indices (1-based). Every index must appear exactly once; any optimal answer is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤401\le n\le40; −109≤ai≤109-10^9\le a_i\le10^9; the values aia_i are pairwise distinct.
  • Subtask 2 (30 points): 1≤n≤50001\le n\le5000; −109≤ai≤109-10^9\le a_i\le10^9; the values aia_i are pairwise distinct.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; −109≤ai≤109-10^9\le a_i\le10^9; the values aia_i are pairwise distinct.

Examples

Input

6
3 2 1 6 5 4

Output

4
2 1 3
1 2
2 4 6
1 5

Explanation

Sorting positions 1,31,3 and 4,64,6 gives 1,2,3,4,5,61,2,3,4,5,6. The two singleton groups leave the array unchanged. Four is the largest possible number of groups.