#include <bits/stdc++.h>
using namespace std;
int arr[100000], p[100000], b[100000];
vector<int> v[100000];
set<int> s;
int main() {
  int n, cnt = -1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    p[i] = arr[i];
  }
  sort(p, p + n);
  int i, j = 0;
  while (s.size() != n) {
    i = j;
    if (b[i] != -1) cnt++;
    while (b[i] != 1) {
      b[i] = 1;
      v[cnt].push_back(i);
      s.insert(i);
      i = lower_bound(p, p + n, arr[i]) - p;
    }
    j++;
  }
  int ans = 0;
  for (int i = 0; i <= cnt; i++) {
    if (v[i].size() > 0) ans++;
  }
  cout << ans << endl;
  for (int i = 0; i <= cnt; i++) {
    if (v[i].size() > 0) {
      cout << v[i].size() << " ";
      for (int j = 0; j < v[i].size(); j++) cout << v[i][j] + 1 << " ";
      cout << endl;
    }
  }
}
