#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, a[N], ans[N];
int fl[N], q[N];
long long f[N];
void work(int x) {
  int v = min(a[x], a[x + 1]);
  if (!v) return;
  a[x] -= v;
  a[x + 1] -= v;
  ans[++*ans] = x;
}
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &a[i]);
  for (int i = (int)(1); i <= (int)(n); i++) {
    long long v1 = f[max(i - 2, 0)] + a[i];
    long long v2 = f[max(i - 3, 0)] + max(a[i], a[i - 1]);
    f[i] = min(v1, v2);
    fl[i] = (f[i] != v1);
  }
  int v = n - (f[n - 1] < f[n]), cnt = 0;
  for (; v; v -= 2 + fl[v]) q[++cnt] = v;
  reverse(q + 1, q + cnt + 1);
  for (int i = (int)(1); i <= (int)(cnt); i++) {
    int x = q[i - 1], y = q[i];
    work(y - 1);
    work(x + 1);
    work(y);
  }
  for (int i = (int)(0); i <= (int)(*ans); i++) printf("%d\n", ans[i]);
}
