#include <bits/stdc++.h>
using namespace std;
bool vis[100010];
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n), cc;
  for (int &t : a) scanf("%d", &t);
  cc = a;
  sort(cc.begin(), cc.end());
  for (int &t : a) t = lower_bound(cc.begin(), cc.end(), t) - cc.begin();
  vector<vector<int> > anw;
  for (int i = 0; i < n; i++) {
    if (vis[i]) continue;
    vector<int> p;
    p.push_back(i + 1);
    vis[i] = 1;
    int j = i;
    while (!vis[a[j]]) {
      j = a[j];
      vis[j] = 1;
      p.push_back(j + 1);
    }
    sort(p.begin(), p.end());
    anw.push_back(p);
  }
  printf("%d\n", int(anw.size()));
  for (vector<int> &p : anw) {
    printf("%d", int(p.size()));
    for (int i : p) printf(" %d", i);
    puts("");
  }
}
