#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[100005];
long long arr[100005];
long long n;
long long brr[100005];
long long visited[100005];
long long same = -1;
long long count(long long x) {
  if (visited[adj[x][0]] == 0) {
    visited[adj[x][0]] = 1;
    return 1 + count(adj[x][0]);
  } else
    return 0;
}
long long dfs(long long x) {
  cout << adj[x][0] + 1 << " ";
  if (same == adj[x][0])
    return 0;
  else
    dfs(adj[x][0]);
}
int main() {
  cin >> n;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]] = i;
    brr[i] = arr[i];
  }
  sort(arr, arr + n);
  for (long long i = 0; i < n; i++) {
    adj[i].push_back(mp[arr[i]]);
  }
  for (long long i = 0; i < n; i++) {
    visited[i] = 0;
  }
  long long xc = 0;
  for (long long i = 0; i < n; i++) {
    long long countx = count(i);
    if (countx > 0) xc++;
  }
  cout << xc << endl;
  for (long long i = 0; i < n; i++) {
    visited[i] = 0;
  }
  for (long long i = 0; i < n; i++) {
    long long countx = count(i);
    if (countx > 0) {
      cout << countx << " ";
      same = i;
      dfs(i);
      cout << endl;
    }
  }
  return 0;
}
