#include <bits/stdc++.h>
using namespace std;
const int N = 5000005;
using ll = long long;
ll f[N], pre[N];
int n, a[N];
vector<int> ans;
void move(int x) {
  if (x == n || a[x] == 0 || a[x + 1] == 0) return;
  ans.push_back(x);
  int t = min(a[x], a[x + 1]);
  a[x] -= t;
  a[x + 1] -= t;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  f[2] = a[1];
  for (int i = 3; i <= n + 1; i++)
    if (f[i - 3] + max(a[i - 1], a[i - 2]) < f[i - 2] + a[i - 1])
      f[i] = f[pre[i] = i - 3] + max(a[i - 1], a[i - 2]);
    else
      f[i] = f[pre[i] = i - 2] + a[i - 1];
  for (int i = f[n] < f[n + 1] ? n : n + 1; i > 1; i = pre[i])
    if (pre[i] == i - 3) {
      move(i - 2), move(i - 1);
      if (i > 3) move(i - 3);
    } else {
      move(i - 1);
      if (i > 2) move(i - 2);
    }
  cout << ans.size() << endl;
  for (auto &i : ans) cout << i << endl;
  return 0;
}
