#include <bits/stdc++.h>
long long int dp[300009];
int prev[300009];
long long int a[300009];
int f[300009];
int fn;
static const long long int INF = 1000000000000000000LL;
void desc(int i) {
  long long int val = std::min(a[i], a[i + 1]);
  if (val == 0) return;
  a[i] -= val, a[i + 1] -= val;
  f[fn++] = i;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", &a[i]);
  }
  dp[0] = a[0], prev[0] = -1;
  dp[1] = a[1], prev[1] = -1;
  for (int i = 2; i < n; ++i) {
    long long int ans = INF;
    int pre = -2;
    if (dp[i - 2] + a[i] < ans) {
      ans = dp[i - 2] + a[i];
      pre = i - 2;
    }
    if ((i == 2 ? 0 : dp[i - 3]) + std::max(a[i - 1], a[i]) < ans) {
      ans = (i == 2 ? 0 : dp[i - 3]) + std::max(a[i - 1], a[i]);
      pre = i - 3;
    }
    dp[i] = ans, prev[i] = pre;
  }
  int cur;
  if (dp[n - 1] < dp[n - 2])
    cur = n - 1;
  else
    cur = n - 2;
  while (cur != -1) {
    desc(cur - 1), desc(cur);
    if (prev[cur] == cur - 3) desc(cur - 2);
    cur = prev[cur];
  }
  printf("%d\n", fn);
  for (int i = 0; i < fn; ++i) printf("%d\n", f[i] + 1);
}
