#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 10;
long long a[N], p[N], ans[N], c;
long long f[N];
bool v[N];
long long calc(long long x) {
  long long val = min(a[x], a[x + 1]);
  if (val) {
    ans[++c] = x;
  }
  a[x] -= val;
  a[x + 1] -= val;
  return val;
}
signed main() {
  long long n;
  cin >> n;
  for (register long long i = 1; i <= n; i++) {
    cin >> a[i];
    long long x = f[max(0LL, i - 2)] + a[i],
              y = f[max(0LL, i - 3)] + max(a[i], a[i - 1]);
    f[i] = min(x, y);
    v[i] = (f[i] != x);
  }
  long long cnt = 0, k = n;
  if (f[n - 1] <= f[n]) {
    k--;
  }
  for (long long i = k; i >= 1; i -= v[i] + 2) {
    p[++cnt] = i;
  }
  for (register long long i = 1; i <= cnt / 2; i++) {
    swap(p[i], p[cnt - i + 1]);
  }
  for (register long long i = 1; i <= cnt; i++) {
    long long l = p[i - 1], r = p[i];
    long long sum = 0;
    if (v[r]) {
      sum += calc(r - 1);
    }
    sum += calc(l + 1) + calc(r);
  }
  cout << c << endl;
  for (register long long i = 1; i <= c; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
