#include <bits/stdc++.h>
using namespace std;
const int max_N = 1e5 + 10;
int inp[max_N], vis[max_N];
vector<vector<int> > ans;
int main() {
  map<int, int> coord;
  int N;
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", inp + i);
    coord[inp[i]];
  }
  int j = 1;
  for (auto &x : coord) {
    x.second = j++;
  }
  for (int i = 1; i <= N; ++i) {
    inp[i] = coord[inp[i]];
  }
  for (int i = 1; i <= N; ++i) {
    if (!vis[i]) {
      vector<int> temp;
      int u = i;
      while (!vis[u]) {
        vis[u] = 1;
        temp.push_back(u);
        u = inp[u];
      }
      ans.push_back(temp);
    }
  }
  printf("%lu\n", ans.size());
  for (auto &v : ans) {
    printf("%lu ", v.size());
    for (auto &x : v) {
      printf("%d ", x);
    }
    printf("\n");
  }
}
