#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> ans[N];
int n;
pair<int, int> a[N];
bool vis[N];
bool cmp(pair<int, int> u, pair<int, int> v) { return u.first < v.first; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1);
  int idx = 0;
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      int cur = i;
      while (!vis[cur]) {
        vis[cur] = true;
        ans[idx].push_back(a[cur].second);
        cur = a[cur].second;
      }
      idx++;
    }
  }
  cout << idx << endl;
  for (long long i = 0; i <= idx - 1; i++) {
    cout << ans[i].size() << " ";
    for (long long j = 0; j <= ans[i].size() - 1; j++) cout << ans[i][j] << " ";
    cout << endl;
  }
  return 0;
}
