#include <bits/stdc++.h>
using namespace std;
void find(int a[], int i, bool vis[], int b[], int &x, int &y) {
  if (a[i] == i) {
    b[y++] = i;
    vis[i] = true;
    return;
  }
  while (i != a[i] && !vis[i]) {
    vis[i] = true;
    b[y++] = i;
    i = a[i];
  }
}
vector<int> v[100010];
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, i, j, x, y;
  cin >> n;
  int a[n + 2], b[n + 10];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  j = 0;
  map<int, int> m;
  for (i = 1; i <= n; i++) {
    j++;
    m[b[i]] = j;
  }
  for (i = 1; i <= n; i++) a[i] = m[a[i]];
  bool vis[100010] = {false};
  x = 0;
  y = 0;
  int res = 0;
  for (i = 1; i <= n; i++) {
    if (vis[i]) continue;
    find(a, i, vis, b, x, y);
    res++;
    v[i].push_back(y - x);
    for (j = x; j < y; j++) v[i].push_back(b[j]);
    x = y;
  }
  cout << res << "\n";
  for (i = 1; i <= n; i++) {
    if (v[i].size() == 0) continue;
    sort(v[i].begin() + 1, v[i].end());
    for (int j : v[i]) cout << j << " ";
    cout << "\n";
  }
  return 0;
}
