#include <bits/stdc++.h>
using namespace std;
int d[100010];
bool visited[100010] = {0};
vector<int> dsu(int second, int find) {
  vector<int> r;
  if (second == find) {
    r.push_back(second);
    return r;
  }
  r.push_back(second);
  r.push_back(find);
  visited[second] = 1;
  visited[find] = 1;
  while (d[second] != find) {
    second = d[second];
    visited[second] = 1;
    r.push_back(second);
  }
  sort(r.begin(), r.end());
  return r;
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > data;
  int t;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t);
    data.push_back({t, i});
  }
  sort(data.begin(), data.end());
  for (int i = 0; i < data.size(); i++) {
    d[data[i].second] = i + 1;
  }
  vector<vector<int> > ans;
  for (int i = 1; i <= n; i++) {
    if (visited[i] == 0) {
      vector<int> r = dsu(d[i], i);
      ans.push_back(r);
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    printf("%d ", ans[i].size());
    for (int j = 0; j < ans[i].size(); j++) {
      printf("%d ", ans[i][j]);
    }
    printf("\n");
  }
  return 0;
}
