#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
vector<int> t[100100];
int in[100100], stn[100100], check[100100], v[100100], secnd;
int cnt, pred, n;
vector<int> cc[100100];
stack<int> st;
void kek(int u) {
  stn[u] = in[u] = cnt++;
  check[u] = 1;
  st.push(u);
  for (auto v : t[u]) {
    if (!check[v]) {
      kek(v);
      stn[u] = min(stn[u], stn[v]);
    } else
      stn[u] = min(stn[u], in[v]);
  }
  if (stn[u] == in[u]) {
    int ll;
    do {
      ll = st.top();
      st.pop();
      in[ll] = 1 << 30;
      cc[pred].push_back(ll);
    } while (ll != u);
    pred++;
  }
}
int main() {
  cin >> n;
  int v[n];
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mp[v[i]] = 1;
  }
  for (auto &m : mp) m.second = secnd++;
  for (auto &ll : v) ll = mp[ll];
  for (int i = 0; i < n; i++) t[i].push_back(v[i]);
  for (int i = 0; i < n; i++)
    if (!check[i]) kek(i);
  cout << pred << '\n';
  for (int i = 0; i < pred; i++) {
    cout << cc[i].size() << " ";
    for (auto ll : cc[i]) cout << ll + 1 << " ";
    cout << '\n';
  }
}
