#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(T t) {
  cout << t << std::endl;
}
template <typename T, typename... Args>
void print(T t, Args... args) {
  cout << t << " ";
  print(args...);
}
const int INF = 1 << 29;
pair<int, int> arr[500005];
int temp[500005];
bool visited[500005];
int parent[500005];
int ranks[500005];
int find(int);
void merge(int a, int b) {
  int x = find(a);
  int y = find(b);
  if (ranks[x] > ranks[y]) {
    parent[y] = x;
  } else if (ranks[x] < ranks[y]) {
    parent[x] = y;
  } else {
    ranks[x] += 1;
    parent[y] = x;
  }
}
int find(int a) {
  if (parent[a] == a) {
    return a;
  }
  return parent[a] = find(parent[a]);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    parent[i] = i;
    ranks[i] = 1;
  }
  for (int i = 0; i < n; ++i) {
    cin >> arr[i].first;
    arr[i].second = i;
    temp[i] = arr[i].first;
  }
  sort(arr, arr + n);
  vector<vector<int> > ans;
  for (int i = 0; i < n; ++i) {
    if (!visited[i]) {
      vector<int> res;
      int index = i;
      while (true) {
        visited[index] = 1;
        res.push_back(arr[index].second);
        if (find(index) == find(arr[index].second)) {
          break;
        }
        merge(index, arr[index].second);
        index = arr[index].second;
      }
      ans.push_back(res);
    }
  }
  print(ans.size());
  for (auto i : ans) {
    cout << i.size() << " ";
    for (auto j : i) {
      cout << j + 1 << " ";
    }
    cout << endl;
  }
  return 0;
}
