#include <bits/stdc++.h>
using namespace std;
long long binarys(long long *b, long long key, long long n) {
  long long bi = 0;
  long long e = n - 1;
  while (bi < e) {
    long long mid = (bi + e) / 2;
    if (b[mid] == key)
      return mid;
    else if (b[mid] > key)
      e = mid - 1;
    else
      bi = mid + 1;
  }
  return bi;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  bool bol[n];
  for (int i = 0; i < n; i++) bol[i] = false;
  sort(b, b + n);
  vector<int> p[n];
  int cat = 0;
  for (int i = 0; i < n; i++) {
    if (bol[i] == false) {
      long long l = i;
      p[cat].push_back(l + 1);
      while (a[l] != b[i]) {
        l = binarys(b, a[l], n);
        bol[l] = true;
        p[cat].push_back(l + 1);
      }
      cat++;
    }
  }
  cout << cat << "\n";
  for (int i = 0; i < n; i++) {
    if (p[i].empty()) break;
    cout << p[i].size() << " ";
    for (auto j : p[i]) cout << j << " ";
    cout << "\n";
  }
}
