#include <bits/stdc++.h>
char In[1 << 20], *ss = In, *tt = In;
using namespace std;
template <class T>
void readn(T &x) {
  x = 0;
  register char c =
      (ss == tt && (tt = (ss = In) + fread(In, 1, 1 << 20, stdin), ss == tt)
           ? EOF
           : *ss++);
  register bool f = 0;
  while (!isdigit(c))
    f ^= c == '-',
        c = (ss == tt &&
                     (tt = (ss = In) + fread(In, 1, 1 << 20, stdin), ss == tt)
                 ? EOF
                 : *ss++);
  while (isdigit(c))
    x = x * 10 + c - '0',
    c = (ss == tt && (tt = (ss = In) + fread(In, 1, 1 << 20, stdin), ss == tt)
             ? EOF
             : *ss++);
  if (f) x = -x;
}
void rd() {}
const int N = 1e5 + 9;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
int T, n, m, k, x, y;
int a[N], b[N];
int vis[N];
vector<int> v[N];
void dfs(int nowp, int i) {
  if (vis[nowp]) return;
  v[i].push_back(nowp);
  vis[nowp] = 1;
  dfs(a[nowp], i);
}
int main() {
  rd();
  for (T = 1; T; T--) {
    readn(n);
    for (int i = 1; i <= n; ++i) readn(a[i]), b[i] = a[i];
    sort(b + 1, b + n + 1);
    for (int i = 1; i <= n; ++i) {
      a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
    }
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
      if (vis[a[i]]) continue;
      dfs(a[i], ++cnt);
    }
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; ++i) {
      int sz = v[i].size();
      printf("%d ", sz);
      for (int j = 0; j < sz; ++j) {
        printf("%d%c", v[i][j], " \n"[j == sz - 1]);
      }
    }
  }
  return 0;
}
