#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const long long N = 1e5 + 5, M = 1e9 + 7;
bool vis[N];
vector<pair<long long, long long>> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, i, j, k;
  cin >> n;
  vector<long long> ans[n + 1];
  for (i = 0; i < n; i++) {
    cin >> k;
    v.push_back({k, i});
  }
  sort(v.begin(), v.end());
  k = 0;
  for (i = 0; i < n; i++) {
    if (i == v[i].second) {
      k++;
      ans[i].push_back(i + 1);
      vis[i] = 1;
    } else {
      j = i;
      long long fl = 0;
      while (!vis[v[j].second]) {
        vis[v[j].second] = 1;
        ans[i].push_back(v[j].second + 1);
        j = v[j].second;
        fl = 1;
      }
      if (fl) k++;
    }
  }
  cout << k << endl;
  for (auto p : ans) {
    if (!p.empty()) {
      cout << p.size() << " ";
      for (auto x : p) cout << x << " ";
      cout << endl;
    }
  }
}
