#include <bits/stdc++.h>
using namespace std;
class DSU {
 public:
  int parent[100005];
  int sze[100005];
  int n;
  DSU() {
    for (int i = 0; i < 100005; i++) {
      parent[i] = i;
      sze[i] = 1;
    }
  }
  int findp(int x) {
    if (parent[x] == x) {
      return x;
    }
    return parent[x] = findp(parent[x]);
  }
  void mergep(int x, int y) {
    int p1 = findp(x);
    int p2 = findp(y);
    if (p1 != p2) {
      n--;
      if (sze[p1] >= sze[p2]) {
        parent[p2] = p1;
        sze[p1] += sze[p2];
      } else {
        parent[p1] = p2;
        sze[p2] += sze[p1];
      }
    }
  }
};
vector<int> vv[100005];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  pair<int, int> a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(a, a + n);
  DSU dsu;
  dsu.n = n;
  for (int i = 0; i < n; i++) {
    dsu.mergep(i + 1, a[i].second);
  }
  for (int i = 1; i <= n; i++) {
    vv[dsu.findp(i)].push_back(i);
  }
  cout << dsu.n << endl;
  for (int i = 0; i < 100005; i++) {
    if (vv[i].size()) {
      cout << vv[i].size();
      for (int j = 0; j < vv[i].size(); j++) {
        cout << " " << vv[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}
