#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n, a[N], dex[N];
bool mark[N];
vector<vector<int>> ans;
vector<int> vec;
void dfs(int x) {
  vec.push_back(x);
  mark[x] = true;
  if (mark[a[x]] == false) dfs(a[x]);
  if (mark[dex[x]] == false) dfs(dex[x]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    vec.push_back(a[i]);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < n; i++)
    dex[a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin()] = i;
  for (int i = 0; i < n; i++)
    if (mark[i] == false) {
      vec.clear();
      dfs(i);
      sort(vec.begin(), vec.end());
      ans.push_back(vec);
    }
  cout << ans.size() << "\n";
  for (vector<int> vec : ans) {
    cout << vec.size() << ' ';
    for (int x : vec) cout << ++x << ' ';
    cout << "\n";
  }
  return 0;
}
