#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
const int N = 300010;
int a[N], p[N], t[N], lt, flag[N], ans[N];
long long f[N];
inline void calc(int x) {
  int d = min(a[x], a[x + 1]);
  if (d) {
    ans[++ans[0]] = x;
    a[x] -= d, a[x + 1] -= d;
  }
}
int main() {
  int n = read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
    long long p1 = f[max(i - 2, 0)] + a[i],
              p2 = f[max(i - 3, 0)] + max(a[i - 1], a[i]);
    f[i] = min(p1, p2);
    if (f[i] == p2)
      p[i] = max(i - 3, 0), flag[i] = 1;
    else
      p[i] = max(i - 2, 0);
  }
  for (int i = f[n - 1] <= f[n] ? n - 1 : n; i; i = p[i]) t[++lt] = i;
  for (int i = lt; i; --i) {
    int now = t[i], lst = t[i + 1];
    if (flag[now]) calc(now - 1);
    calc(lst + 1), calc(now);
  }
  printf("%d\n", ans[0]);
  for (int i = 1; i <= ans[0]; ++i) printf("%d\n", ans[i]);
  return 0;
}
