#include <bits/stdc++.h>
using namespace std;
constexpr int sz = 100005;
pair<int, int> a[sz];
int b[sz];
vector<set<int> > ans(sz);
int v[sz];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    a[i] = {b[i], i};
  }
  sort(a, a + n);
  int ans_sz = 0;
  for (int i = 0; i < n; ++i) {
    if (!v[i]) {
      int cur = i;
      ans[ans_sz].insert(cur + 1);
      int supposed = a[i].second;
      while (supposed != cur && !v[supposed]) {
        ans[ans_sz].insert(supposed + 1);
        v[supposed] = 1;
        cur = supposed;
        supposed = a[cur].second;
      }
      ans_sz++;
    }
  }
  cout << ans_sz << endl;
  for (int i = 0; i < ans_sz; ++i) {
    cout << ans[i].size() << " ";
    copy(ans[i].begin(), ans[i].end(), ostream_iterator<int>(cout, " "));
    cout << endl;
  }
}
