#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n;
vector<pair<int, int> > vec;
int num[maxn];
int color[maxn];
int cnt_color;
vector<int> G[maxn];
inline void dfs(int x) {
  while (!color[x]) {
    color[x] = cnt_color;
    G[cnt_color].push_back(x);
    x = num[x];
  }
}
int main() {
  scanf(" %d", &n);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf(" %d", &a);
    vec.push_back(pair<int, int>(a, i));
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < vec.size(); i++) {
    num[vec[i].second] = i + 1;
  }
  for (int i = 1; i <= n; i++) {
    if (!color[i]) {
      ++cnt_color;
      dfs(i);
    }
  }
  printf("%d\n", cnt_color);
  for (int i = 1; i <= cnt_color; i++) {
    sort(G[i].begin(), G[i].end());
    cout << G[i].size() << " ";
    for (int j = 0; j < G[i].size(); j++) cout << G[i][j] << " ";
    cout << endl;
  }
  return 0;
}
