#include <bits/stdc++.h>
using namespace std;
int minSwaps(int arr[], int n) {
  pair<int, int> arrPos[n];
  for (int i = 0; i < n; i++) {
    arrPos[i].first = arr[i];
    arrPos[i].second = i;
  }
  sort(arrPos, arrPos + n);
  vector<bool> vis(n, false);
  int ans1 = 0;
  vector<int> ans[100001];
  int count = 1;
  for (int i = 0; i < n; i++) {
    if (vis[i]) continue;
    if (arrPos[i].second == i) {
      ans[count].push_back(i);
      count++;
      continue;
    }
    int cycle_size = 0;
    int j = i;
    while (!vis[j]) {
      ans[count].push_back(j);
      vis[j] = 1;
      j = arrPos[j].second;
      cycle_size++;
    }
    count++;
    ans1 += (cycle_size - 1);
  }
  cout << count - 1 << endl;
  for (int i = 1; i < count; i++) {
    cout << ans[i].size() << " ";
    for (int j = 0; j < ans[i].size(); j++) {
      cout << ans[i][j] + 1 << " ";
    }
    cout << endl;
  }
  return ans1;
}
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  minSwaps(arr, n);
  return 0;
}
