#include <bits/stdc++.h>
using namespace std;
int n;
int a[100007];
int b[100007];
bool visited[100007];
bool visited1[100007];
map<int, int> idx;
map<int, int> idx2;
vector<vector<int> > graph;
set<int> s;
void dfs(int v) {
  s.insert(v);
  if (visited[v]) {
    return;
  }
  visited[v] = true;
  for (int i = 0; i < graph[v].size(); ++i) {
    dfs(graph[v][i]);
  }
}
int main() {
  cin >> n;
  graph.resize(n + 1);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    idx2[a[i]] = i;
  }
  for (int i = 0; i < n; ++i) {
    b[i] = a[i];
  }
  sort(b, b + n);
  for (int i = 0; i < n; ++i) {
    idx[b[i]] = i;
  }
  for (int i = 0; i < n; ++i) {
    int x = idx[b[i]];
    int y = idx2[b[i]];
    graph[x].push_back(y);
  }
  int cnt1 = 0;
  for (int i = 0; i < n; ++i) {
    if (!visited[i]) {
      dfs(i);
      cnt1++;
    }
  }
  for (int i = 0; i < n; ++i) {
    visited[i] = false;
  }
  cout << cnt1 << endl;
  for (int i = 0; i < n; ++i) {
    s.clear();
    if (!visited[i]) {
      dfs(i);
      cout << s.size();
      cout << " ";
      set<int>::iterator i;
      for (i = s.begin(); i != s.end(); ++i) {
        cout << *i + 1 << " ";
      }
      cout << endl;
    }
  }
}
