#include <bits/stdc++.h>
using namespace std;
int t[112345], parent[112345];
void scale(int c[], int nn) {
  pair<int, int> tab[112345];
  for (int i = 1; i <= nn; ++i) tab[i] = {c[i], i};
  sort(tab + 1, tab + 1 + nn);
  for (int i = 1; i <= nn; ++i) {
    c[tab[i].second] = i;
  }
}
int find(int x) {
  if (parent[x] != x) parent[x] = find(parent[x]);
  return parent[x];
}
void uni(int x, int y) {
  int a = find(x);
  int b = find(y);
  if (a != b) {
    parent[b] = a;
  }
}
void init() {
  for (int i = 1; i < 112345; ++i) {
    parent[i] = i;
  }
}
int n;
int pos[112345];
bool bylo[112345];
vector<int> v[112345];
int main() {
  scanf("%d", &n);
  init();
  for (int i = 1; i <= n; ++i) {
    scanf("%d", t + i);
  }
  scale(t, n);
  for (int i = 1; i <= n; ++i) pos[t[i]] = i;
  for (int i = 1; i <= n; ++i) {
    int x = t[i];
    while (1) {
      if (bylo[x]) break;
      bylo[x] = true;
      uni(x, pos[x]);
      if (pos[pos[x]] == x) {
        bylo[pos[x]] = true;
        break;
      }
      x = pos[x];
    }
  }
  for (int i = 1; i <= n; ++i) {
    v[find(i)].push_back(i);
  }
  int ile = 0;
  for (int i = 1; i <= n; ++i) {
    if (v[i].size() > 0) ile++;
  }
  printf("%d\n", ile);
  for (int i = 1; i <= n; ++i) {
    if (v[i].size()) {
      printf("%d ", (int)v[i].size());
      for (int j = 0; j < (int)v[i].size(); ++j) {
        printf("%d ", pos[v[i][j]]);
      }
      puts("");
    }
  }
}
