#include <bits/stdc++.h>
using namespace std;
const int maxn = 100050;
int n;
struct node {
  int x, id;
} a[maxn];
struct ans {
  int num;
  vector<int> arr;
} ask[maxn];
int tot = 0;
int cnt = 0, pos = 1;
bool vis[maxn];
bool cmp(node a, node b) { return a.x < b.x; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x;
    a[i].id = i;
  }
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      pos = i;
      tot++;
      while (!vis[pos]) {
        ask[tot].arr.push_back(a[pos].id);
        ask[tot].num++;
        cnt++;
        vis[pos] = 1;
        pos = a[pos].id;
      }
    }
  }
  cout << tot << endl;
  for (int i = 1; i <= tot; i++) {
    cout << ask[i].num << " ";
    sort(ask[i].arr.begin(), ask[i].arr.end());
    for (int j = 0; j < ask[i].num; j++) cout << ask[i].arr[j] << " ";
    cout << '\n';
  }
  return 0;
}
