#include <bits/stdc++.h>
int main() {
  size_t n;
  std::cin >> n;
  std::vector<int> v(n);
  for (int& num : v) std::cin >> num;
  std::vector<int> sv(v);
  std::sort(sv.begin(), sv.end());
  std::vector<bool> mask(n, false);
  std::ostringstream os;
  std::vector<size_t> subseq;
  size_t i, count;
  for (i = 0, count = 0; i < n; ++i) {
    if (mask[i]) continue;
    subseq.clear();
    for (size_t cur = i;;) {
      subseq.push_back(cur);
      mask[cur] = true;
      cur = std::lower_bound(sv.begin(), sv.end(), v[cur]) - sv.begin();
      if (cur == i) break;
    }
    os << subseq.size();
    for (size_t& index : subseq) os << ' ' << index + 1;
    os << std::endl;
    ++count;
  }
  std::cout << count << std::endl << os.str();
}
