#include <bits/stdc++.h>
using namespace std;
map<int, int> par;
map<int, vector<int> > m;
int find(int x) {
  if (par[x] != x)
    return (par[x] = find(par[x]));
  else
    return par[x];
}
void merge(int i, int j) {
  int x = find(i);
  int y = find(j);
  if (x == y) return;
  par[y] = x;
  find(y);
  find(x);
}
int main() {
  int n;
  cin >> n;
  par.clear();
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) {
    a[i].second = i;
    cin >> a[i].first;
    par[i] = i;
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) merge(i, a[i].second);
  for (int i = 0; i < n; i++) {
    int k = find(i);
    m[k].push_back(i);
  }
  map<int, vector<int> >::iterator it;
  cout << m.size() << endl;
  for (it = m.begin(); it != m.end(); it++) {
    cout << it->second.size() << " ";
    for (int i = 0; i < (it->second.size()); i++)
      cout << it->second[i] + 1 << " ";
    cout << endl;
  }
  return 0;
}
