#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000 * 1000 * 1000 + 7;
const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const long long MOD2 = 998244353;
const long long N = 1000 * 1000 + 10;
const long long N2 = 70;
const long double PI = 3.14159265358979323846;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long power(long long x, long long y, long long p = LLONG_MAX) {
  long long res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
void solve() {}
long long a[N];
map<long long, long long> mp;
long long vis[N] = {0};
vector<long long> v[N];
void dfs(long long i, long long co) {
  vis[i] = 1;
  v[co].push_back(i + 1);
  while (vis[mp[a[i]]] != 1) {
    dfs(mp[a[i]], co);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long b[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  for (long long i = 0; i < n; i++) {
    mp[b[i]] = i;
  }
  long long co = 0;
  for (long long i = 0; i < n; i++) {
    if (vis[i] == 0) {
      co++;
      dfs(i, co);
    }
  }
  cout << co << "\n";
  for (long long i = 1; i <= co; i++) {
    cout << v[i].size() << " ";
    for (long long j = 0; j < v[i].size(); j++) {
      cout << v[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
