#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > num;
int pos[100005], vis[100005];
vector<vector<int> > record, v2, v3;
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, t;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    num.emplace_back(i + 1, t);
  }
  sort(num.begin(), num.end(), cmp);
  for (int i = 0; i < n; i++) pos[num[i].first] = i + 1;
  t = 1;
  vector<int> vec;
  while (t <= n) {
    while (!vis[t]) {
      vec.push_back(t);
      vis[t] = 1;
      t = pos[t];
    }
    if (vec.size() > 1) record.push_back(vec);
    vec.clear();
    t++;
  }
  int cnt = 0, cnt2 = 0, cnt3 = 0;
  for (int i = 0; i < record.size(); i++) {
    if (record[i].size() == 4 || record[i].size() == 5)
      cnt++;
    else if (record[i].size() > 5) {
      cnt += record[i].size() / 4;
      int k = record[i].size() % 4;
      if (k == 2)
        cnt2++;
      else if (k == 3)
        cnt3++;
    } else if (record[i].size() == 2)
      cnt2++;
    else
      cnt3++;
  }
  if (cnt2 >= cnt3) {
    cnt += cnt3;
    cnt2 -= cnt3;
    cnt += (cnt2 + 1) / 2;
  } else {
    cnt += cnt2;
    cnt3 -= cnt2;
    cnt += cnt3 / 3 * 2;
    cnt += cnt3 % 3;
  }
  cout << cnt << endl;
  for (int i = 0; i < record.size(); i++) {
    if (record[i].size() == 4 || record[i].size() == 5) {
      cout << record[i].size() << endl;
      for (int j = 0; j < record[i].size(); j++) cout << record[i][j] << ' ';
      cout << endl;
      int k = record[i].size();
      for (int j = 1; j <= k; j++) cout << record[i][j % k] << ' ';
      cout << endl;
    } else if (record[i].size() > 5) {
      int k = record[i].size();
      int sign = 1;
      while (k >= 5) {
        cout << "5" << endl;
        cout << record[i][0] << ' ';
        for (int j = sign; j < sign + 4; j++) cout << record[i][j] << ' ';
        cout << endl;
        for (int j = sign; j < sign + 4; j++) cout << record[i][j] << ' ';
        cout << record[i][0] << endl;
        sign += 4;
        k -= 4;
      }
      t = record[i].size();
      if (k == 2) {
        vec.clear();
        vec.push_back(record[i][0]);
        vec.push_back(record[i][t - 1]);
        v2.push_back(vec);
      } else if (k == 3) {
        vec.clear();
        vec.push_back(record[i][t - 2]);
        vec.push_back(record[i][t - 1]);
        vec.push_back(record[i][0]);
        v3.push_back(vec);
      } else if (k == 4) {
        cout << "4" << endl;
        cout << record[i][0] << ' ';
        for (int j = t - 3; j < t; j++) cout << record[i][j] << ' ';
        cout << endl;
        for (int j = t - 3; j < t; j++) cout << record[i][j] << ' ';
        cout << record[i][0] << endl;
      }
    } else if (record[i].size() == 2)
      v2.push_back(record[i]);
    else
      v3.push_back(record[i]);
  }
  for (int i = 0; i < min(v2.size(), v3.size()); i++) {
    cout << "5" << endl;
    cout << v2[i][0] << ' ' << v2[i][1] << ' ' << v3[i][0] << ' ' << v3[i][1]
         << ' ' << v3[i][2] << endl;
    cout << v2[i][1] << ' ' << v2[i][0] << ' ' << v3[i][1] << ' ' << v3[i][2]
         << ' ' << v3[i][0] << endl;
  }
  if (v2.size() == v3.size()) return 0;
  if (v2.size() > v3.size()) {
    t = v3.size();
    while (t < v2.size()) {
      if (v2.size() > 1 && t < v2.size() - 1) {
        cout << "4" << endl;
        cout << v2[t][0] << ' ' << v2[t][1] << ' ' << v2[t + 1][0] << ' '
             << v2[t + 1][1] << endl;
        cout << v2[t][1] << ' ' << v2[t][0] << ' ' << v2[t + 1][1] << ' '
             << v2[t + 1][0] << endl;
        t += 2;
      } else {
        cout << "2" << endl;
        cout << v2[t][0] << ' ' << v2[t][1] << endl;
        cout << v2[t][1] << ' ' << v2[t][0] << endl;
        t += 1;
      }
    }
  } else {
    t = v2.size();
    while (t < v3.size()) {
      if (v3.size() > 2 && t < v3.size() - 2) {
        cout << "5" << endl;
        cout << v3[t][0] << ' ' << v3[t][1] << ' ' << v3[t][2] << ' '
             << v3[t + 1][0] << ' ' << v3[t + 1][1] << endl;
        cout << v3[t][1] << ' ' << v3[t][2] << ' ' << v3[t][0] << ' '
             << v3[t + 1][1] << ' ' << v3[t + 1][0] << endl;
        cout << "5" << endl;
        cout << v3[t + 1][0] << ' ' << v3[t + 1][2] << ' ' << v3[t + 2][0]
             << ' ' << v3[t + 2][1] << ' ' << v3[t + 2][2] << endl;
        cout << v3[t + 1][2] << ' ' << v3[t + 1][0] << ' ' << v3[t + 2][1]
             << ' ' << v3[t + 2][2] << ' ' << v3[t + 2][0] << endl;
        t += 3;
      } else {
        cout << "3" << endl;
        cout << v3[t][0] << ' ' << v3[t][1] << ' ' << v3[t][2] << endl;
        cout << v3[t][1] << ' ' << v3[t][2] << ' ' << v3[t][0] << endl;
        t++;
      }
    }
  }
  return 0;
}
