#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int p[N], g[N], n;
long long f[N];
vector<int> ans;
inline void clear(int x) {
  if (p[x] <= 0 || p[x + 1] <= 0) return;
  ans.push_back(x);
  int tmp = min(p[x], p[x + 1]);
  p[x] -= tmp;
  p[x + 1] -= tmp;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
  memset(f, 0x3f, sizeof(f));
  f[0] = 0;
  long long x;
  for (int i = 1; i <= n; ++i) {
    if ((x = f[max(i - 2, 0)] + p[i]) < f[i]) f[i] = x, g[i] = i - 2;
    if ((x = f[max(i - 3, 0)] + max(p[i - 1], p[i])) < f[i])
      f[i] = x, g[i] = i - 3;
  }
  int st = f[n] < f[n - 1] ? n : n - 1;
  for (int i = st; i >= 1; i = g[i]) {
    clear(i - 1);
    if (g[i] == i - 3) clear(i - 2);
    clear(i);
  }
  printf("%d\n", ans.size());
  for (int v : ans) printf("%d\n", v);
  return 0;
}
