#include <bits/stdc++.h>
using namespace std;
struct dat {
  long long a;
  long long n;
};
bool comp(struct dat a, struct dat b) { return a.a < b.a; }
int main() {
  ios::sync_with_stdio(false);
  long long a, b, c, i, j, k, l, m, t, x, y, n, z;
  vector<long long> a1;
  string s;
  cin >> n;
  vector<vector<long long> > arr(n, vector<long long>(2));
  struct dat arr1[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i][0];
    arr[i][1] = i;
    arr1[i].a = arr[i][0];
    arr1[i].n = i;
  }
  sort(arr1, arr1 + n, comp);
  for (i = 0; i < n; i++) {
    arr[arr1[i].n][1] = i;
  }
  vector<vector<long long> > ans;
  int arr3[n];
  for (i = 0; i < n; i++) {
    arr3[i] = 0;
  }
  for (i = 0; i < n; i++) {
    if (arr3[i] == 1)
      continue;
    else {
      j = i;
      vector<long long> q1;
      while (arr3[j] == 0) {
        arr3[j] = 1;
        q1.push_back(j);
        j = arr[j][1];
      }
      sort(q1.begin(), q1.end());
      ans.push_back(q1);
    }
  }
  cout << ans.size() << endl;
  for (i = 0; i < ans.size(); i++) {
    cout << ans[i].size() << " ";
    for (j = 0; j < ans[i].size(); j++) {
      cout << ans[i][j] + 1 << " ";
    }
    cout << endl;
  }
  return 0;
}
