#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  int f = 0;
  x = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) f |= (ch == '-');
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  if (f) x = -x;
}
const int N = 300005;
int p[N], g[N], n;
long long f[N], res;
vector<int> ans;
void doit(int k) {
  int x = min(p[k], p[k + 1]);
  if (!x) return;
  ans.push_back(k), p[k] -= x, p[k + 1] -= x;
}
int main() {
  read(n);
  for (int i = (1); i <= (n); i++) read(p[i]);
  memset(f, 0x3f, sizeof f);
  f[0] = 0;
  for (int i = (1); i <= (n); i++) {
    long long A = f[max(i - 2, 0)] + p[i];
    long long B = f[max(i - 3, 0)] + max(p[i], p[i - 1]);
    if (A < B)
      f[i] = A;
    else
      f[i] = B, g[i] = 1;
  }
  res = min(f[n], f[n - 1]);
  for (int i = n - (res == f[n - 1]); i > 0; i = i - 2 - g[i]) {
    doit(i - 1);
    if (g[i]) doit(i - 2);
    doit(i);
  }
  cout << ans.size() << endl;
  for (auto x : ans) printf("%d\n", x);
  return 0;
}
