#include <iostream>
using namespace std;
int main() {
// your code goes here
int n, arr[1005], a, b[2005], count=0;
cin>>n;
for(int i=1; i<=n; i++) cin>>arr[i];
for(int i=1; i<=2005; i++) b[i]=true;
for(int i=1; i<=n; i++) {
if(b[i]) {
count++;
b[i]=false; a=arr[i];
while(a!=i) {b[a]=false; a=arr[a];}
}
}
cout<<count<<endl;
for(int i=1; i<=2005; i++) b[i]=true;
for(int i=1; i<=n; i++) {
if(b[i]) {
cout<<i<<" "; b[i]=false; a=arr[i]; cout<<a;
while(a!=i) {b[a]=false; a=arr[a]; cout<<" "<<a;}
cout<<endl;
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CgkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCglpbnQgbiwgYXJyWzEwMDVdLCBhLCBiWzIwMDVdLCBjb3VudD0wOwoJY2luPj5uOwoJZm9yKGludCBpPTE7IGk8PW47IGkrKykgY2luPj5hcnJbaV07Cglmb3IoaW50IGk9MTsgaTw9MjAwNTsgaSsrKSBiW2ldPXRydWU7Cglmb3IoaW50IGk9MTsgaTw9bjsgaSsrKSB7CgkJaWYoYltpXSkgewoJCQljb3VudCsrOyAKCQkJYltpXT1mYWxzZTsgYT1hcnJbaV07IAoJCQl3aGlsZShhIT1pKSB7YlthXT1mYWxzZTsgYT1hcnJbYV07fQoJCX0gCgl9Cgljb3V0PDxjb3VudDw8ZW5kbDsKCWZvcihpbnQgaT0xOyBpPD0yMDA1OyBpKyspIGJbaV09dHJ1ZTsKCWZvcihpbnQgaT0xOyBpPD1uOyBpKyspIHsKCQlpZihiW2ldKSB7CgkJCWNvdXQ8PGk8PCIgIjsgYltpXT1mYWxzZTsgYT1hcnJbaV07IGNvdXQ8PGE7CgkJCXdoaWxlKGEhPWkpIHtiW2FdPWZhbHNlOyBhPWFyclthXTsgY291dDw8IiAiPDxhO30KCQkJY291dDw8ZW5kbDsKCQl9Cgl9CglyZXR1cm4gMDsKfQ==