#include <bits/stdc++.h>
using namespace std;
int ans, i, j, k, n, m, a[210001], b[210001], p[210001], v[210001], q[210001];
bool cmp(int x, int y) { return a[x] < a[y]; }
int main() {
  scanf("%d", &n);
  memset(v, 0, sizeof(v));
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), b[i] = i;
  sort(b + 1, b + 1 + n, cmp);
  for (i = 1; i <= n; i++) p[b[i]] = i;
  for (i = 1, ans = 0; i <= n; i++) {
    if (v[i]) continue;
    ans++;
    for (j = i; !v[j]; j = p[j]) v[j] = 1;
  }
  printf("%d\n", ans);
  memset(v, 0, sizeof(v));
  for (i = 1, ans = 0; i <= n; i++) {
    if (v[i]) continue;
    for (q[0] = 0, j = i; !v[j]; j = p[j]) v[j] = 1, q[++q[0]] = j;
    for (j = 0; j <= q[0]; j++) printf("%d ", q[j]);
    puts("");
  }
  return 0;
}
