#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 10;
const long long BINF = 1e18 + 10;
const long long LINF = 1e18 + 10;
const long double EPS = 1e-10;
const long double PI = acos(-1);
inline void error() {
  cout << -1;
  exit(0);
}
vector<vector<int> > ans, g;
vector<int> comp;
bool used[MAXN];
void dfs(int v) {
  used[v] = true;
  comp.push_back(v);
  for (auto u : g[v]) {
    if (!used[u]) {
      dfs(u);
    }
  }
}
int n;
vector<int> arr;
map<int, int> pos;
inline void source() {
  cin >> n;
  arr.resize(n);
  g.resize(n + 1);
  for (register int i(0); i < n; i++) {
    cin >> arr[i];
    pos[arr[i]] = i + 1;
  }
  sort((arr).begin(), (arr).end());
  for (int i = 0; i < n; i++) {
    g[i + 1].push_back(pos[arr[i]]);
  }
  for (register int i(1); i <= n; i++) {
    if (!used[i]) {
      comp.clear();
      dfs(i);
      ans.push_back(comp);
    }
  }
  cout << ans.size() << endl;
  for (register int i(0); i < ans.size(); i++) {
    cout << ans[i].size() << " ";
    copy(ans[i].begin(), ans[i].end(), ostream_iterator<int>(cout, " "));
    cout << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  source();
  return 0;
}
