#include <bits/stdc++.h>
using namespace std;
int inf_int = 1e8;
long long inf_ll = 4e18;
const double pi = 3.1415926535898;
const int MAXN = 1e5 + 10;
int a[MAXN];
int parent[MAXN];
int find_parent(int v) {
  if (parent[v] == v) return v;
  return parent[v] = find_parent(parent[v]);
}
void union_set(int a, int b) {
  a = find_parent(a);
  b = find_parent(b);
  if (a != b) {
    if (rand() % 2) swap(a, b);
    parent[b] = a;
  }
}
vector<int> ans[MAXN];
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int> > c;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    c.push_back({a[i], i});
    parent[i] = i;
  }
  sort(c.begin(), c.end());
  for (int i = 1; i <= n; ++i) {
    union_set(i, c[i - 1].second);
  }
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    ans[find_parent(i)].push_back(i);
    if (find_parent(i) == i) res++;
  }
  cout << res << "\n";
  for (int i = 1; i <= n; ++i) {
    if (ans[i].size()) {
      cout << ans[i].size() << " ";
      for (int v : ans[i]) {
        cout << v << " ";
      }
      cout << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
