#include <bits/stdc++.h>
using namespace std;
long long cc = 0;
unordered_map<long long, long long> c, rc;
vector<vector<long long> > graph(1e6);
vector<bool> visited(1e6, false);
vector<vector<long long> > answers(1e6);
void dfs(long long node) {
  visited[node] = true;
  answers[cc].push_back(node);
  for (auto i : graph[node])
    if (!visited[i]) dfs(i);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> nums(n);
  for (int i = 0; i < (int)(n); i++) cin >> (nums)[i];
  ;
  vector<long long> nums_copy((nums).begin(), (nums).end());
  sort((nums_copy).begin(), (nums_copy).end());
  for (int i = 0; i < n; i++) c[i] = nums_copy[i], rc[nums_copy[i]] = i;
  vector<long long> modified(n);
  for (int i = 0; i < n; i++) modified[i] = rc[nums[i]];
  for (int i = 0; i < n; i++) {
    graph[i].push_back(modified[i]);
  }
  for (int i = 0; i < n; i++) {
    if (!visited[i]) dfs(i), cc++;
  }
  cout << cc << endl;
  for (int i = 0; i < cc; i++) {
    long long k = answers[i].size();
    cout << k << " ";
    for (int j = 0; j < k; j++) cout << answers[i][j] + 1 << " ";
    cout << endl;
  }
}
