#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int mod = 1e9 + 7;
int a[maxn], v[maxn];
bool c[maxn];
long long dp[maxn];
vector<int> f;
void del(int k) {
  int x = min(a[k], a[k + 1]);
  if (x) {
    f.push_back(k);
    a[k] -= x;
    a[k + 1] -= x;
  }
}
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) {
    dp[i] = min(dp[i - 2] + a[i], dp[i - 3] + max(a[i - 1], a[i]));
    if (dp[i] == dp[i - 2] + a[i])
      v[i] = 2;
    else
      v[i] = 3;
  }
  for (i = dp[n - 1] < dp[n] ? n - 1 : n; i > 0; i -= v[i]) {
    c[i] = 1;
    if (v[i] == 3 && a[i - 1] > a[i]) c[i - 1] = 1;
  }
  for (i = 1; i < n; i++) {
    if (c[i] && c[i + 1]) del(i);
  }
  for (i = 1; i <= n; i++) {
    if (c[i]) {
      del(i - 1);
      del(i);
    }
  }
  n = f.size();
  printf("%d\n", n);
  for (auto x : f) printf("%d\n", x);
  return 0;
}
