#include <bits/stdc++.h>
using namespace std;
int n, m, vet[303030], aux[303030], jav[303030];
vector<vector<int> > ans;
vector<int> cur;
void dfs(int v) {
  cur.push_back(v + 1);
  jav[v] = 1;
  if (!jav[vet[v]]) dfs(vet[v]);
}
int main() {
  scanf("%d", &n);
  for (int(i) = (0); (i) < (n); (i)++) scanf("%d", &vet[i]), aux[i] = vet[i];
  sort(aux, aux + n);
  for (int(i) = (0); (i) < (n); (i)++)
    vet[i] = lower_bound(aux, aux + n, vet[i]) - aux;
  for (int(i) = (0); (i) < (n); (i)++)
    if (!jav[i]) {
      cur.clear();
      dfs(i);
      ans.push_back(cur);
    }
  printf("%d\n", ((int)(ans).size()));
  for (int(i) = (0); (i) < (((int)(ans).size())); (i)++) {
    printf("%d", ((int)(ans[i]).size()));
    for (int(j) = (0); (j) < (((int)(ans[i]).size())); (j)++)
      printf(" %d", ans[i][j]);
    printf("\n");
  }
}
