#include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
const int MAX = 1 << 20;
int A[MAX], B[MAX], n;
vector<vector<int> > ans;
int vis[MAX];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) scanf("%d", A + i);
  copy(A, A + n, B);
  sort(B, B + n);
  int m = unique(B, B + n) - B;
  for (int i = 0; i < (n); i++) A[i] = lower_bound(B, B + m, A[i]) - B;
  for (int i = 0; i < (n); i++)
    if (!vis[i]) {
      int cur = i;
      vector<int> aux;
      while (!vis[cur]) {
        vis[cur] = 1;
        aux.push_back(cur + 1);
        cur = A[cur];
      }
      ans.push_back(aux);
    }
  printf("%d\n", ((int)ans.size()));
  for (auto V : ans) {
    printf("%d", ((int)V.size()));
    for (int x : V) printf(" %d", x);
    puts("");
  }
  return 0;
}
