#include <bits/stdc++.h>
using namespace std;
int n, w[301000], Path[301000];
long long D[301000], cc;
vector<int> res;
void Do(int a) {
  if (a >= n || a <= 0) return;
  if (!w[a] || !w[a + 1]) return;
  res.push_back(a);
  int M = min(w[a], w[a + 1]);
  cc += M;
  w[a] -= M;
  w[a + 1] -= M;
}
int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &w[i]);
    D[i] = 1e18;
  }
  D[1] = w[1];
  D[2] = w[2];
  Path[1] = 1, Path[2] = 1;
  for (i = 3; i <= n; i++) {
    long long t2 = max(w[i - 1], w[i]) + D[i - 3];
    long long t1 = w[i] + D[i - 2];
    if (t2 < t1) {
      Path[i] = 2;
      D[i] = t2;
    } else
      Path[i] = 1, D[i] = t1;
  }
  int x;
  if (D[n - 1] <= D[n])
    x = n - 1;
  else
    x = n;
  while (x > 0) {
    if (Path[x] == 1) {
      Do(x);
      Do(x - 1);
      x -= 2;
    } else {
      Do(x - 1);
      if (w[x - 1] < w[x]) {
        Do(x);
      } else {
        Do(x - 2);
      }
      x -= 3;
    }
  }
  printf("%d\n", res.size());
  for (auto &t : res) printf("%d\n", t);
}
