#include <bits/stdc++.h>
using namespace std;
long long int MOD = (1e9 + 7);
long long int nCr[1001][1001];
void Cnr() {
  long long int i, j;
  for (i = 1; i <= 1000; i++) nCr[i][0] = 1;
  for (i = 0; i <= 1000; i++) nCr[0][i] = 0;
  nCr[0][0] = 1;
  for (i = 1; i <= 1000; i++) {
    for (j = 1; j <= i; j++)
      nCr[i][j] = (nCr[i - 1][j - 1] % MOD + nCr[i - 1][j] % MOD) % MOD;
  }
}
long long int power(long long int a, long long int x) {
  if (a == 0) return 0;
  if (a == 1) return 1;
  if (x == 0) return 1;
  return a * power(a, x - 1);
}
vector<long long int> par;
vector<long long int> rnk;
void make_set(long long int n) {
  long long int i;
  for (i = 1; i <= n; i++) par[i] = i;
}
long long int find_set(long long int i) {
  if (par[i] == i) return i;
  par[i] = find_set(par[i]);
  return par[i];
}
void merge_set(long long int a, long long int b) {
  long long int p1, p2;
  p1 = find_set(a);
  p2 = find_set(b);
  if (p1 == p2) return;
  if (rnk[p1] < rnk[p2]) {
    par[p1] = p2;
    rnk[p2] += rnk[p1];
    rnk[p1] = 0;
  } else {
    par[p2] = p1;
    rnk[p1] += rnk[p2];
    rnk[p2] = 0;
  }
}
int32_t main() {
  long long int n, i, j;
  cin >> n;
  par.resize(n + 1);
  rnk.resize(n + 1);
  long long int a[n + 1];
  long long int b[n + 1];
  a[0] = -1e18;
  map<long long int, long long int> m;
  make_set(n);
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a, a + n + 1);
  for (i = 1; i <= n; i++) {
    m[a[i]] = i;
  }
  for (i = 1; i <= n; i++) {
    if (m[b[i]] != i) {
      merge_set(i, m[b[i]]);
    }
  }
  map<long long int, set<long long int> > M;
  for (i = 1; i <= n; i++) {
    M[find_set(i)].insert(i);
  }
  cout << (long long int)M.size() << endl;
  for (auto j : M) {
    set<long long int> k = j.second;
    cout << (long long int)k.size() << ' ';
    for (auto i : k) {
      cout << i << ' ';
    }
    cout << endl;
  }
}
