#include <bits/stdc++.h>
using namespace std;
int n, comp = 0, a[100005], b[100005], v[100005];
bool vis[100005];
set<int> s[100005];
void dfs(int u) {
  if (vis[u]) return;
  vis[u] = true;
  s[comp].insert(u);
  dfs(v[u]);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  for (int i = 0; i < n; i++) {
    int l = 0, r = n - 1;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (b[mid] == a[i]) {
        v[i] = mid;
        break;
      } else if (b[mid] < a[i]) {
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      dfs(i);
      comp++;
    }
  }
  cout << comp << endl;
  for (int i = 0; i < comp; i++) {
    cout << s[i].size();
    for (set<int>::iterator it = s[i].begin(); it != s[i].end(); it++) {
      cout << ' ' << (*it + 1);
    }
    cout << endl;
  }
  return 0;
}
