#include <iostream>
const int maxn = 1000000;
using namespace std;
int n,a,d[maxn+2],dd[maxn+1],p,tplt,m;
int main() {
cin >> n;
for (int i=1; i<=n; i++)
{
cin >> a;
d[a] = i;
}
tplt = 0;
p = n;
m = n;
for (int i=n; i>=1; i--)
{
if (d[i]==p)
{
tplt++;
dd[m]=p-m+1;
p = m-1;
m = p;
}
else
{
if (d[i]<m) m = d[i];
}
}
cout << tplt;
for (int i=1; i<=n; i++)
{
if (dd[i]!=0)
{
cout << '\n' << dd[i] << ' ';
}
cout << i << ' ';
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgpjb25zdCBpbnQgbWF4biA9IDEwMDAwMDA7CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBuLGEsZFttYXhuKzJdLGRkW21heG4rMV0scCx0cGx0LG07CmludCBtYWluKCkgewoJY2luID4+IG47Cglmb3IgKGludCBpPTE7IGk8PW47IGkrKykKCXsKCSAgY2luID4+IGE7CgkgIGRbYV0gPSBpOwoJfQoJdHBsdCA9IDA7CglwID0gbjsKCW0gPSBuOwoJZm9yIChpbnQgaT1uOyBpPj0xOyBpLS0pCgl7CgkJaWYgKGRbaV09PXApCgkJewoJCQl0cGx0Kys7CgkJCWRkW21dPXAtbSsxOwoJCQlwID0gbS0xOwoJCQltID0gcDsKCQl9CgkJZWxzZSAKCQl7CgkJCWlmIChkW2ldPG0pIG0gPSBkW2ldOwoJCX0KCX0KCWNvdXQgPDwgdHBsdDsKCWZvciAoaW50IGk9MTsgaTw9bjsgaSsrKQoJewoJCWlmIChkZFtpXSE9MCkKCQl7CgkJCWNvdXQgPDwgJ1xuJyA8PCBkZFtpXSA8PCAnICc7CgkJfQoJCWNvdXQgPDwgaSA8PCAnICc7Cgl9CglyZXR1cm4gMDsKfQ==