#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<int> arr_c = arr;
  sort(arr_c.begin(), arr_c.end());
  map<int, int> val_to_idx, idx_to_val;
  for (int i = 0; i < arr_c.size(); i++) {
    val_to_idx[arr_c[i]] = i;
    idx_to_val[i] = arr_c[i];
  }
  vector<bool> vis(n);
  vector<list<int>> ans;
  for (int i = 0; i < n; i++) {
    if (vis[i]) continue;
    if (val_to_idx[arr[i]] != i) {
      list<int> group;
      int cur = i;
      while (!vis[cur]) {
        vis[cur] = true;
        group.push_back(cur);
        int next_idx = val_to_idx[arr[cur]];
        cur = next_idx;
      }
      ans.push_back(group);
    } else {
      ans.push_back({i});
    }
  }
  cout << ans.size() << '\n';
  for (list<int> &l : ans) {
    cout << l.size() << ' ';
    for (int val : l) {
      cout << val + 1 << ' ';
    }
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
