#include <bits/stdc++.h>
using namespace std;
vector<long long> A[100010];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  map<long long, long long> m, mm;
  long long n, c = 0, p = -1, e = 0, k;
  cin >> n;
  vector<long long> a(n), b(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b.begin(), b.end());
  for (long long i = 0; i < n; i++) {
    m[b[i]] = i;
  }
  for (long long i = 0; i < n; i++) {
    a[i] = m[a[i]];
  }
  for (long long i = 0; i < n; i++) {
    k = i;
    e = 0;
    if (mm[a[i]] == 0)
      while (1) {
        if (e == 0) p++;
        e++;
        if (mm[a[k]] > 0) break;
        A[p].push_back(a[k]);
        mm[a[k]]++;
        k = a[k];
      }
  }
  for (long long i = 0; i < 100000; i++) {
    if (A[i].size() > 0) c++;
  }
  cout << c << endl;
  for (long long i = 0; i < 100000; i++) {
    if (A[i].size() == 0) break;
    sort(A[i].begin(), A[i].end());
    cout << A[i].size() << " ";
    for (long long j = 0; j < A[i].size(); j++) cout << A[i][j] + 1 << " ";
    cout << endl;
  }
}
