#include <bits/stdc++.h>
using namespace std;
long long a[500007], f[500007];
int pre[500007];
vector<int> ans;
void reunion(int x) {
  int v = min(a[x], a[x + 1]);
  if (v) {
    ans.push_back(x);
    a[x] -= v, a[x + 1] -= v;
  }
}
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  n++;
  a[n] = 0;
  f[1] = 0, f[2] = a[1];
  pre[2] = 0;
  pre[1] = -1, pre[0] = -1;
  for (i = 3; i <= n; i++) {
    long long f1 = f[i - 2] + a[i - 1];
    long long f2 = f[i - 3] + a[i - 2] + a[i - 1] - min(a[i - 2], a[i - 1]);
    if (f1 < f2)
      f[i] = f1, pre[i] = i - 2;
    else
      f[i] = f2, pre[i] = i - 3;
  }
  int cur;
  if (f[n - 1] < f[n])
    cur = n - 1;
  else
    cur = n;
  while (pre[cur] != -1) {
    int p = pre[cur];
    if (p == cur - 2) {
      reunion(cur - 1);
      reunion(p);
    } else {
      reunion(p + 1);
      reunion(cur - 1);
      reunion(p);
    }
    cur = p;
  }
  int s = ans.size();
  printf("%d\n", s);
  for (i = 0; i < s; i++) printf("%d\n", ans[i]);
  return 0;
}
