#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
int i, j;
long long int ceil_div(long long int x, long long int y) {
  return (x + y - 1) / y;
}
void test_cases() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  vector<vector<int>> answers;
  sort(a.begin(), a.end());
  for (i = 0; i < n; i++) {
    if (a[i].first == 0) {
      continue;
    }
    int prev = a[i].second;
    int curr = a[prev].second;
    vector<int> temp;
    temp.push_back(a[prev].second + 1);
    while (prev != curr) {
      a[curr].first = 0;
      curr = a[curr].second;
      temp.push_back(curr + 1);
    }
    a[prev].first = 0;
    a[curr].first = 0;
    answers.push_back(temp);
  }
  cout << answers.size() << "\n";
  for (auto x : answers) {
    cout << x.size() << " ";
    for (auto &x : x) cout << x << " ";
    cout << "\n";
    ;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  while (T--) {
    test_cases();
  }
  return 0;
}
