#include <bits/stdc++.h>
using namespace std;
set<int> s;
pair<int, int> a[100005];
vector<int> v[100005];
int main() {
  int n, x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a[i] = {x, i + 1};
  }
  sort(a, a + n);
  int k = 0;
  for (int i = 0; i < n; i++) s.insert(i + 1);
  while (!s.empty()) {
    x = *s.begin();
    while (s.count(x)) {
      s.erase(x);
      v[k].push_back(x);
      x = a[x - 1].second;
    }
    k++;
  }
  cout << k << endl;
  for (int i = 0; i < k; i++) {
    cout << v[i].size() << " ";
    for (int j = 0; j < v[i].size(); j++) cout << v[i][j] << " ";
    cout << endl;
  }
}
