#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[100010];
map<int, int> orig, order;
int vis[100010], _count = 0;
vector<vector<int> > ans;
void dfs(int u) {
  vis[u] = true;
  ans[_count].push_back(u);
  int w = order[orig[u]];
  if (!vis[w]) {
    dfs(w);
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  ans.assign(n + 1, vector<int>());
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
    orig[i] = a[i].first;
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    order[a[i].first] = i;
  }
  for (int i = 1; i <= n; i++) {
    int o = a[i].second;
    if (!vis[o]) {
      int w = order[a[i].first];
      if (o == w) {
        ans[_count++].push_back(a[i].second);
      } else {
        dfs(o);
        _count++;
      }
    }
  }
  cout << _count << "\n";
  for (int i = 0; i < _count; i++) {
    sort(ans[i].begin(), ans[i].end());
    cout << ans[i].size();
    for (int j = 0; j < ans[i].size(); j++) {
      cout << " " << ans[i][j];
    }
    cout << "\n";
  }
  return 0;
}
