#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > out;
vector<bool> visited;
vector<int> a, b;
unordered_map<int, int> m;
void dfs(int id) {
  visited[id] = 1;
  out.back().push_back(id + 1);
  if (!visited[a[id]]) {
    dfs(a[id]);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  a.resize(n);
  b.resize(n);
  visited.resize(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < n; i++) m[b[i]] = i;
  for (int i = 0; i < n; i++) a[i] = m[a[i]];
  out.reserve(n);
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      out.push_back(vector<int>());
      dfs(i);
    }
  }
  cout << out.size() << '\n';
  for (vector<int> v : out) {
    cout << v.size() << ' ';
    for (int x : v) cout << x << ' ';
    cout << '\n';
  }
}
