#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
int n, a[maxn];
long long f[maxn];
bool chk[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    long long foo = f[max(0, i - 2)] + a[i];
    long long bar = f[max(0, i - 3)] + max(a[i], a[i - 1]);
    f[i] = min(foo, bar), chk[i] = f[i] == foo;
  }
  int pos = n;
  if (f[n - 1] < f[n]) pos--;
  vector<int> ans;
  auto red = [&](int pos) {
    if (pos < 1 || pos == n || !a[pos] || !a[pos + 1]) return;
    int t = min(a[pos], a[pos + 1]);
    ans.push_back(pos), a[pos] -= t, a[pos + 1] -= t;
  };
  while (pos > 0) {
    if (chk[pos]) {
      red(pos), red(pos - 1), pos -= 2;
    } else {
      red(pos - 1), red(pos - 2), red(pos), pos -= 3;
    }
  }
  printf("%d\n", ans.size());
  for (int x : ans) printf("%d\n", x);
  return 0;
}
