#include <bits/stdc++.h>
using namespace std;
int n, tot, cnt;
int b[100010];
struct Node {
  int num, id;
} a[100010], fa[100010];
vector<int> v[100010];
inline bool cmp(Node a, Node b) {
  if (a.num == b.num) return a.id < b.id;
  return a.num < b.num;
}
inline int find(int x) {
  if (fa[x].num == x) return x;
  return fa[x].num = find(fa[x].num);
}
inline void merge(int x, int y) {
  int fx = find(x);
  int fy = find(y);
  fa[fy].num = fx;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i].num);
    a[i].id = i;
    b[i] = a[i].num;
    fa[i].id = i;
    fa[i].num = i;
  }
  tot = n;
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; ++i) {
    if (a[i].num != b[i] && find(i) != find(a[i].id)) {
      merge(i, a[i].id);
      --tot;
    }
  }
  for (int i = 1; i <= n; ++i) {
    find(i);
  }
  printf("%d\n", tot);
  sort(fa + 1, fa + n + 1, cmp);
  for (int i = 1; i <= n; ++i) {
    if (fa[i].num != fa[i - 1].num) {
      v[++cnt].push_back(fa[i].id);
    } else
      v[cnt].push_back(fa[i].id);
  }
  for (int i = 1; i <= tot; ++i) {
    printf("%d ", v[i].size());
    for (int j = 0; j < v[i].size(); ++j) {
      printf("%d ", v[i][j]);
    }
    putchar('\n');
  }
  return 0;
}
