#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n], b[n];
  bool visited[n];
  map<int, int> indices;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
    visited[i] = false;
    indices[a[i]] = i;
  }
  sort(b, b + n);
  vector<vector<int>> ans;
  for (int i = 0; i < n; i++) {
    if (visited[i]) continue;
    vector<int> sub_vector;
    set<int> this_time_visit;
    int index = i;
    while (this_time_visit.empty() || !this_time_visit.count(index)) {
      visited[index] = true;
      this_time_visit.insert(index);
      sub_vector.push_back(index + 1);
      index = indices[b[index]];
    }
    ans.push_back(sub_vector);
  }
  cout << ans.size() << "\n";
  for (auto itr : ans) {
    cout << itr.size() << " ";
    for (auto itrt : itr) {
      cout << itrt << " ";
    }
    cout << "\n";
  }
  return 0;
}
