#include <bits/stdc++.h>
using namespace std;
int n, a[300005], pre[300005];
long long f[300005];
vector<int> ans;
void solve(int x) {
  if (x == n) return;
  if (!a[x] || !a[x + 1]) return;
  ans.push_back(x);
  int t = min(a[x], a[x + 1]);
  a[x] -= t, a[x + 1] -= t;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  f[2] = a[1];
  for (int i = 3; i <= n + 1; i++) {
    if (f[i - 3] + max(a[i - 1], a[i - 2]) <= f[i - 2] + a[i - 1])
      f[i] = f[pre[i] = i - 3] + max(a[i - 1], a[i - 2]);
    else
      f[i] = f[pre[i] = i - 2] + a[i - 1];
  }
  for (int now = f[n] < f[n + 1] ? n : n + 1; now; now = pre[now]) {
    if (pre[now] == now - 3) {
      solve(now - 2);
      solve(now - 1);
      if (now >= 3) solve(now - 3);
    } else {
      solve(now - 1);
      if (now >= 2) solve(now - 2);
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) printf("%d\n", ans[i]);
}
