#include <bits/stdc++.h>
const int maxx = 100005;
const int INF = 1 << 30;
using namespace std;
int n, ans;
bool flag[maxx];
vector<int> aa[maxx];
struct num {
  int a, add;
  bool operator<(const num &i) { return a < i.a; }
} a[maxx];
int comp(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int cmp(const int &a, const int &b) { return a < b; }
int main() {
  std::ios::sync_with_stdio(false);
  int i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i].a);
    a[i].add = i;
  }
  qsort(a, n, sizeof(num), comp);
  for (i = 0; i < n; i++) {
    if (!flag[i]) {
      if (a[i].add != i) {
        int j = i;
        do {
          aa[ans].push_back(a[j].add);
          flag[j] = true;
          j = a[j].add;
        } while (j != i);
      } else
        aa[ans].push_back(i), flag[i] = true;
      ans++;
    }
  }
  for (i = 0; i < ans; i++) sort(aa[i].begin(), aa[i].end(), cmp);
  printf("%d\n", ans);
  for (i = 0; i < ans; i++) {
    int siz = aa[i].size();
    printf("%d", siz);
    for (int j = 0; j < siz; j++) printf(" %d", aa[i][j] + 1);
    putchar('\n');
  }
  return 0;
}
