#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
  char c;
  int sign = 1;
  x = 0;
  do {
    c = getchar();
    if (c == '-') sign = -1;
  } while (!isdigit(c));
  do {
    x = x * 10 + c - '0';
    c = getchar();
  } while (isdigit(c));
  x *= sign;
}
const int N = 3e5 + 50;
int a[N], g[N], n;
int res[N], tot;
long long f[N];
void work(int i) {
  int x = min(a[i], a[i + 1]);
  if (!x) return;
  res[++tot] = i;
  a[i] -= x;
  a[i + 1] -= x;
}
int main() {
  read(n);
  for (register int i = 1; i <= n; ++i) read(a[i]);
  for (register int i = 1; i <= n; ++i) {
    f[i] = min(f[max(i - 2, 0)] + a[i], f[max(i - 3, 0)] + max(a[i], a[i - 1]));
    if (f[i] == f[max(i - 3, 0)] + max(a[i], a[i - 1])) g[i] = 1;
  }
  long long ans = min(f[n], f[n - 1]);
  for (int i = n - (ans == f[n - 1]); i > 0; i = i - 2 - g[i]) {
    work(i - 1);
    if (g[i]) work(i - 2);
    work(i);
  }
  printf("%d\n", tot);
  for (register int i = 1; i <= tot; ++i) printf("%d\n", res[i]);
  return 0;
}
