#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<int> > cycles;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<pair<int, int> > tmp(n);
  for (int i = 0; i < n; ++i) {
    tmp[i] = {a[i], i};
  }
  sort(tmp.begin(), tmp.end());
  for (int i = 0; i < n; ++i) {
    a[tmp[i].second] = i;
  }
  vector<bool> visited(n, false);
  for (int i = 0; i < n; ++i) {
    if (visited[i]) continue;
    vector<int> cycle = {i};
    visited[i] = 1;
    int cur = i;
    while (!visited[a[cur]]) {
      cur = a[cur];
      cycle.push_back(cur);
      visited[cur] = 1;
    }
    cycles.push_back(cycle);
  }
  cout << cycles.size() << endl;
  for (int i = 0; i < cycles.size(); ++i) {
    cout << cycles[i].size() << " ";
    for (auto e : cycles[i]) {
      cout << e + 1 << " ";
    }
    cout << endl;
  }
  return 0;
}
