#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x;
  cin >> n;
  vector<pair<long long, long long>> a, b;
  bitset<100010> v;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a.push_back({x, i + 1});
  }
  b = a;
  sort(b.begin(), b.end());
  vector<vector<long long>> ans;
  for (int i = 0; i < n; i++) {
    vector<long long> sol;
    long long t = b[i].second;
    while (v[t] == 0) {
      sol.push_back(t);
      v[t] = 1;
      t = b[t - 1].second;
    }
    if (!sol.empty()) ans.push_back(sol);
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].size() << " ";
    for (auto x : ans[i]) cout << x << " ";
    cout << "\n";
  }
}
