#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, a[N], g[N];
long long f[N];
int main() {
  memset(f, 63, sizeof(f));
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]);
  f[0] = 0;
  for (int i = (1); i <= (n); ++i) {
    long long w1 = f[max(i - 2, 0)] + a[i];
    long long w2 = f[max(i - 3, 0)] + max(a[i], a[i - 1]);
    if (w1 < w2) {
      f[i] = w1;
    } else {
      f[i] = w2;
      g[i] = 1;
    }
  }
  vector<pair<int, int> > ans;
  auto fun = [&](int x) {
    if (x >= 1) {
      int t = min(a[x], a[x + 1]);
      a[x] -= t, a[x + 1] -= t;
      if (t) {
        ans.emplace_back(x, t);
      }
    }
  };
  for (int i = n - (f[n - 1] < f[n]); i >= 1; i -= 2 + g[i]) {
    fun(i - 1);
    if (g[i]) fun(i - 2);
    fun(i);
  }
  printf("%d\n", ((int)(ans).size()));
  for (auto x : ans) printf("%d\n", x.first);
  return 0;
}
