#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c;
  int sign = 1, res = 0;
  while ((c = getchar()) > '9' || c < '0')
    if (c == '-') sign = -1;
  res += c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  return res * sign;
}
int n, first[100010], cnt, tot;
bool vis[100010];
struct edge {
  int to, next;
} a[200010];
struct node {
  int val, num;
} x[100010];
priority_queue<int, vector<int>, greater<int> > q[100010];
bool cmp(node l, node r) { return l.val < r.val; }
inline void add(int u, int v) {
  a[++cnt] = (edge){v, first[u]};
  first[u] = cnt;
}
void dfs(int u, int now) {
  vis[u] = 1;
  q[now].push(u);
  int i, v;
  for (i = first[u]; ~i; i = a[i].next) {
    v = a[i].to;
    if (vis[v]) return;
    dfs(v, now);
  }
}
int main() {
  memset(first, -1, sizeof(first));
  int i, j;
  n = read();
  for (i = 1; i <= n; i++) {
    x[i].val = read();
    x[i].num = i;
  }
  sort(x + 1, x + n + 1, cmp);
  for (i = 1; i <= n; i++) {
    add(i, x[i].num);
  }
  for (i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i, ++tot);
  }
  printf("%d\n", tot);
  for (i = 1; i <= tot; i++) {
    printf("%d", q[i].size());
    while (!q[i].empty()) printf(" %d", q[i].top()), q[i].pop();
    printf("\n");
  }
}
