#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > a;
vector<bool> used;
vector<vector<int> > res;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  used.assign(n, false);
  a.resize(n);
  res.resize(n + 1);
  for (int i = (0); i < (n); i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort((a).begin(), (a).end());
  for (int i = (0); i < (n); i++) {
    if (used[i]) continue;
    int v = i;
    while (!used[v]) {
      used[v] = true;
      res[m].push_back(v + 1);
      v = a[v].second;
    }
    m++;
  }
  cout << m << endl;
  for (int i = (0); i < (m); i++) {
    cout << res[i].size() << " ";
    for (int j = (0); j < (res[i].size()); j++) cout << res[i][j] << " ";
    cout << "\n";
  }
  return 0;
}
