#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e5 + 5, M = 1e4 + 5, OO = 0x3f3f3f3f;
int n, arr[N], cnt = 1;
map<int, int> mp;
bool vis[N];
vector<vector<int>> ans;
vector<int> tmp;
void compress() {
  for (int i = 1; i <= n; i++) mp[arr[i]] = 0;
  for (auto& i : mp) i.second = cnt++;
  for (int i = 1; i <= n; i++) arr[i] = mp[arr[i]];
}
void dfs(int node) {
  if (vis[node]) return;
  vis[node] = true;
  tmp.push_back(node);
  dfs(arr[node]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  compress();
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      tmp.clear();
      dfs(i);
      ans.push_back(tmp);
    }
  cout << ans.size() << endl;
  for (auto i : ans) {
    cout << i.size() << " ";
    for (auto j : i) cout << j << " ";
    cout << endl;
  }
  return 0;
}
