#include <bits/stdc++.h>
using namespace std;
int n;
int a[100003], b[100003];
int binsearch(int k) {
  int l = 0;
  int r = n - 1;
  int mid = (l + r) / 2;
  while (l <= r) {
    mid = (l + r) / 2;
    if (b[mid] == k) {
      return mid;
    } else if (k > b[mid]) {
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return mid;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  vector<int> v;
  sort(b, b + n);
  int ans = 0;
  int vis[100003] = {0};
  for (int i = 0; i < n; i++) {
    int ap = 0;
    int p = i;
    if (vis[p] == 0) {
      ans++;
    }
    while (vis[p] == 0) {
      vis[p] = 1;
      int key = a[p];
      int ind = binsearch(key);
      p = ind;
      ap++;
    }
    if (ap != 0) v.push_back(ap);
  }
  cout << ans << "\n";
  memset(vis, 0, sizeof(vis));
  int ind = 0;
  for (int i = 0; i < n; i++) {
    int p = i;
    int f = 0;
    if (vis[p] == 0) {
      cout << v[ind] << " ";
      ind++;
      f = 1;
    }
    while (vis[p] == 0) {
      cout << p + 1 << " ";
      vis[p] = 1;
      int key = a[p];
      p = binsearch(key);
    }
    if (f == 1) {
      cout << "\n";
    }
  }
}
