#include <bits/stdc++.h>
using namespace std;
int n, cnt;
vector<pair<int, int>> a;
vector<vector<int>> v;
struct DSU {
  vector<int> p;
  DSU(int n) : p() {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }
  int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }
  void join(int x, int y) { p[root(y)] = root(x); }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  cnt = n;
  DSU dsu(n + 1);
  a.resize(n + 1);
  v.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin() + 1, a.end());
  for (int i = 1; i <= n; i++) {
    cnt -= (dsu.root(a[i].second) != dsu.root(i));
    dsu.join(a[i].second, i);
  }
  for (int i = 1; i <= n; i++) v[dsu.root(i)].emplace_back(i);
  cout << cnt << "\n";
  for (auto val : v) {
    if (val.size() == 0) continue;
    cout << val.size() << ' ';
    for (int i = 0; i < (int)val.size(); i++)
      cout << val[i] << " \n"[i == val.size() - 1];
  }
}
