#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
int n, a[maxn], cnt, p[maxn], ans[maxn];
long long f[maxn];
bool v[maxn];
int Get(int pos) {
  int t = min(a[pos], a[pos + 1]);
  if (t) ans[++ans[0]] = pos;
  a[pos] -= t;
  a[pos + 1] -= t;
  return t;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    long long t1 = f[max(i - 2, 0)] + a[i],
              t2 = f[max(i - 3, 0)] + max(a[i - 1], a[i]);
    f[i] = min(t1, t2);
    v[i] = (f[i] != t1);
  }
  long long res = min(f[n - 1], f[n]);
  for (int i = n - (res == f[n - 1]); i > 0; i -= 2 + v[i]) p[++cnt] = i;
  reverse(p + 1, p + cnt + 1);
  for (int i = 1; i <= cnt; i++) {
    int pre = p[i - 1], cur = p[i], ctr = 0;
    if (v[cur]) ctr += Get(cur - 1);
    ctr += Get(pre + 1);
    ctr += Get(cur);
  }
  printf("%d\n", ans[0]);
  for (int i = 1; i <= ans[0]; i++) printf("%d\n", ans[i]);
  return 0;
}
