#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int INF = 1e9 + 10;
map<int, int> cc;
int v[MAXN];
bool ok[MAXN];
vector<vector<int>> ans;
vector<int> stk;
void dfs(int cur) {
  ok[cur] = 1;
  stk.push_back(cur);
  if (!ok[v[cur]]) dfs(v[cur]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v[i]);
    cc[v[i]] = 0;
  }
  int ix = 0;
  for (auto it = cc.begin(); it != cc.end(); it++) it->second = ++ix;
  for (int i = 1; i <= n; i++) v[i] = cc[v[i]];
  for (int i = 1; i <= n; i++) {
    if (!ok[i])
      dfs(i);
    else
      continue;
    ans.push_back(stk);
    stk.clear();
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) {
    printf("%d", ans[i].size());
    for (int k = 0; k < ans[i].size(); k++) printf(" %d", ans[i][k]);
    printf("\n");
  }
}
