#include <bits/stdc++.h>
using namespace std;
int n, a[100001], used[100001];
vector<pair<int, int>> b;
vector<vector<int>> ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    b.emplace_back(a[i], i);
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < n; ++i) {
    a[b[i].second] = i + 1;
  }
  for (int i = 1; i <= n; ++i)
    if (!used[i]) {
      vector<int> cyc;
      for (int u = i; !used[u]; u = a[u]) {
        used[u] = 1;
        cyc.emplace_back(u);
      }
      ans.emplace_back(cyc);
    }
  printf("%d\n", ans.size());
  for (int i = 0; i < (int)ans.size(); ++i) {
    printf("%d ", ans[i].size());
    for (int j = 0; j < (int)ans[i].size(); ++j) {
      printf("%d ", ans[i][j]);
    }
    puts("");
  }
}
