#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 50;
int n, p[N], v[N];
long long f[N];
vector<int> ans;
void up(int x) {
  int w = min(p[x], p[x + 1]);
  if (w) ans.push_back(x), p[x] -= w, p[x + 1] -= w;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  f[1] = 0, f[2] = p[1];
  for (int i = 3; i <= n + 1; i++) {
    f[i] = f[v[i] = i - 2] + p[i - 1];
    if (f[i - 3] + max(p[i - 1], p[i - 2]) < f[i])
      f[i] = f[v[i] = i - 3] + max(p[i - 1], p[i - 2]);
  }
  for (int i = n + (f[n + 1] < f[n]); i > 1; i = v[i]) {
    if (v[i] == i - 3)
      up(i - 2), up(i - 1), up(i - 3);
    else
      up(i - 1), up(i - 2);
  }
  cout << ans.size() << '\n';
  for (int z : ans) cout << z << '\n';
  return 0;
}
