#include <bits/stdc++.h>
using namespace std;
const long long N = 101101;
long long a[N], n, p[N], ans;
map<long long, long long> h;
pair<long long, long long> b[N];
vector<long long> now;
vector<vector<long long> > k;
bool mark[N];
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    b[i].first = a[i];
    b[i].second = i;
    h[a[i]] = i;
  }
  sort(b + 1, b + n + 1);
  for (long long i = 1; i <= n; i++) {
    if (mark[i]) continue;
    long long x = i;
    while (!mark[x]) {
      mark[x] = 1;
      now.push_back(a[x]);
      x = b[x].second;
    }
    ans++;
    k.push_back(now);
    now.clear();
  }
  cout << ans << endl;
  for (long long i = 0; i < k.size(); i++) {
    now = k[i];
    cout << now.size() << ' ';
    for (long long j = 0; j < now.size(); j++) cout << h[now[j]] << " ";
    cout << endl;
  }
}
