#include <bits/stdc++.h>
using namespace std;
const int Maxn = int(1e5);
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n;
struct Num {
  int val, id;
} k[Maxn + 5];
inline int cmp(Num x, Num y) { return x.val < y.val; }
struct Node {
  int to, nxt;
} Edge[Maxn + 5];
int tot, Head[Maxn + 5];
inline void Addedge(int x, int y) {
  Edge[++tot] = (Node){y, Head[x]};
  Head[x] = tot;
}
vector<int> vec[Maxn + 5];
int dfn[Maxn + 5], low[Maxn + 5], nowd;
int st[Maxn + 5], vis[Maxn + 5], siz;
int nowcol;
inline void Tarjan(int x) {
  dfn[x] = low[x] = ++nowd;
  st[++siz] = x, vis[x] = 1;
  for (register int i = Head[x]; i; i = Edge[i].nxt) {
    int y = Edge[i].to;
    if (!dfn[y]) {
      Tarjan(y);
      low[x] = min(low[x], low[y]);
    } else if (vis[y])
      low[x] = min(low[x], dfn[y]);
  }
  if (dfn[x] == low[x]) {
    ++nowcol;
    while (1) {
      int y = st[siz--];
      vec[nowcol].push_back(y);
      if (y == x) break;
    }
  }
}
int main() {
  n = read();
  for (register int i = 1; i <= n; ++i) k[i].val = read(), k[i].id = i;
  sort(k + 1, k + n + 1, cmp);
  for (register int i = 1; i <= n; ++i) Addedge(k[i].id, i);
  for (register int i = 1; i <= n; ++i)
    if (!dfn[i]) Tarjan(i);
  printf("%d\n", nowcol);
  for (register int i = 1; i <= nowcol; ++i) {
    printf("%d ", vec[i].size());
    for (register int j = 0; j < vec[i].size(); ++j) printf("%d ", vec[i][j]);
    printf("\n");
  }
  return 0;
}
