#include <bits/stdc++.h>
using namespace std;
int maxarr(vector<int> &arr);
int minarr(vector<int> &arr);
long long modulo(long long base, long long exponent, long long modulus);
long long choose(long long n, long long k);
bool isprime(long long n);
long long inverse(long long a, long long m);
long long fastmult(long long a, long long b, long long c);
vector<long long> a(1000010);
vector<long long> prime;
long long sum[1000010];
vector<bool> aprime(1000010);
void setprime();
long long divCeil(long long a, long long b);
long long arrceil(vector<long long> a, long long k);
int main() {
  long long n;
  cin >> n;
  vector<long long> b(n);
  for (int i = 0; i < n; i++) scanf("%lld", &b[i]);
  ;
  vector<long long> c = b;
  sort(c.begin(), c.end());
  vector<long long> a(n);
  map<long long, long long> mymap;
  for (int i = 0; i < n; i++) {
    mymap[c[i]] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    a[i] = mymap[b[i]];
  }
  long long ans = 0;
  vector<long long> aa[n];
  set<long long> main;
  long long j;
  for (int i = 0; i < n; i++) {
    if (!main.count(i)) {
      set<long long> temp;
      temp.insert(i);
      main.insert(i);
      aa[ans].push_back(i);
      j = a[i] - 1;
      while (i != j) {
        temp.insert(j);
        main.insert(j);
        aa[ans].push_back(j);
        j = a[j] - 1;
      }
      ans++;
    }
  }
  cout << ans << endl;
  for (int i = 0; i < ans; i++) {
    cout << aa[i].size() << " ";
    for (int j = 0; j < aa[i].size(); j++) cout << aa[i][j] + 1 << " ";
    cout << endl;
  }
  return 0;
}
int maxarr(vector<int> &arr) {
  int maxi = INT_MIN;
  for (int i = 0; i < arr.size(); i++) maxi = max(arr[i], maxi);
  return maxi;
}
int minarr(vector<int> &arr) {
  int mini = INT_MAX;
  for (int i = 0; i < arr.size(); i++) mini = min(arr[i], mini);
  return mini;
}
long long modulo(long long base, long long exponent, long long modulus) {
  if (modulus == 1) return 0;
  long long result = 1;
  base = base % modulus;
  while (exponent > 0) {
    if (exponent % 2 == 1) {
      result = (result * base) % modulus;
    }
    exponent = exponent >> 1;
    base = (base * base) % modulus;
  }
  return result;
}
long long choose(long long n, long long k) {
  if (k == 0) return 1;
  return (n * choose(n - 1, k - 1)) / k;
}
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
void EE(long long a, long long b, long long &co1, long long &co2) {
  if (a % b == 0) {
    co1 = 0;
    co2 = 1;
    return;
  }
  EE(b, a % b, co1, co2);
  long long temp = co1;
  co1 = co2;
  co2 = temp - co2 * (a / b);
}
long long inverse(long long a, long long m) {
  long long x, y;
  EE(a, m, x, y);
  if (x < 0) x += m;
  return x;
}
long long fastmult(long long a, long long b, long long c) {
  if (b == 0) return 0;
  long long res = fastmult(a, b >> 1, c);
  res = (res + res) % c;
  if (b % 2 == 1) {
    res = (res + a) % c;
  }
  return res;
}
void setprime() {
  aprime[0] = true;
  for (int i = 2; i * i <= 1000010; i++) {
    if (aprime[i - 1] == false) {
      for (int j = i * 2; j <= 1000010; j += i) {
        aprime[j - 1] = true;
      }
    }
  }
}
long long divCeil(long long a, long long b) { return (a + b - 1) / b; }
long long arrceil(vector<long long> a, long long k) {
  long long n = a.size();
  long long low = 0;
  long long high = n - 1;
  if (a[0] > k) return -1;
  while (low < high) {
    long long mid = (low + high + 1) / 2;
    if (a[mid] <= k)
      low = mid;
    else
      high = mid - 1;
  }
  return low;
}
