#include <bits/stdc++.h>
using namespace std;
struct array_index {
  int value, index;
};
bool compare_val(array_index a, array_index b) { return a.value < b.value; }
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  array_index p[n];
  bool visited[n];
  memset(visited, false, n);
  for (int i = 0; i < n; i++) {
    cin >> p[i].value;
    p[i].index = i;
  }
  sort(p, p + n, compare_val);
  vector<vector<int>> output;
  for (int i = 0; i < n; i++) {
    if (visited[i]) continue;
    int x = i;
    vector<int> cycle;
    while (visited[x] == false) {
      visited[x] = true;
      cycle.push_back(x + 1);
      x = p[x].index;
    }
    output.push_back(cycle);
  }
  cout << output.size() << endl;
  for (int i = 0; i < output.size(); i++) {
    cout << output[i].size() << " ";
    for (int j = 0; j < output[i].size(); j++) cout << output[i][j] << " ";
    cout << endl;
  }
}
