#include <bits/stdc++.h>
using namespace std;
int n;
int a[100055];
int g[100055];
int main() {
  scanf("%d", &n);
  vector<int> vec;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    vec.push_back(a[i]);
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  for (int i = 0; i < n; i++) {
    a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin();
  }
  memset(g, -1, sizeof(g));
  int k = 0;
  for (int i = 0; i < n; i++)
    if (g[i] < 0) {
      int u = i;
      while (g[u] < 0) {
        g[u] = k;
        u = a[u];
      }
      k++;
    }
  printf("%d\n", k);
  for (int i = 0; i < n; i++)
    if (g[i] >= 0) {
      int u = i;
      vector<int> vs;
      while (g[u] >= 0) {
        g[u] = -1;
        vs.push_back(u);
        u = a[u];
      }
      printf("%d", (int)vs.size());
      for (auto u : vs) printf(" %d", u + 1);
      puts("");
    }
  return 0;
}
