#include <iostream>
#include <vector>
int n;
int sorted = 0;
std::vector<int> reverses_k;
std::vector<int> sort(int index, std::vector<int> values) {
if (index != 0) {
reverses_k.push_back(index + 1);
std::reverse(values.begin(), values.begin() + index + 1);
}
reverses_k.push_back(n - sorted);
std::reverse(values.begin(), values.end() - sorted);
sorted += 1;
return values;
}
int main() {
std::cin >> n;
std::vector<int> values;
int x;
for(int i = 0; i < n; ++i) {
std::cin >> x;
values.push_back(x);
}
for(int v = n; v > 0; --v) {
for(int i = 0; i < n; ++i) {
if (i == n - sorted - 1) {
sorted += 1;
} else if (v == values[i] && i != n - 1) {
values = sort(i, values);
break;
}
}
}
std::cout << reverses_k.size() << "\n";
for(auto k: reverses_k) {
std::cout << k << " ";
}
return 0;
}