#include <bits/stdc++.h>

using namespace std;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(bool a) {
  return a ? "T" : "F";
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = long long;
using ld = long double;

const ll inf = (ll)1e18 + 10;

int n;
vector <ll> a;
vector <ll> f;
vector <int> pre;
vector <int> ps;

void go(int i) {
  ps.push_back(i);
  if (pre[i] >= 0)
    go(pre[i]);
}

int find_101(vector < pair <ll, int> > &a, vector <int> &ret) {
  int who = -1;
  ll sum = -inf;
  for (int i = 0; i + 2 < (int)a.size(); ++i) {
    if (a[i].second == 1 && a[i + 1].second == 0 && a[i + 2].second == 1) {
      who = i + 1;
      sum = a[i].first + a[i + 2].first;
      break;
    }
  }
  if (who != -1) {
    ret.push_back(who);
    a.erase(a.begin() + who + 1);
    a.erase(a.begin() + who - 1);
    a[who - 1].first = sum;
    a[who - 1].second = 1;
    return 1;
  }
  return 0;
}

int find_000(vector < pair <ll, int> > &a, vector <int> &ret) {
  int who = -1;
  ll sum = -inf;
  for (int i = 0; i + 2 < a.size(); ++i) {
    if (a[i].second == 0 && a[i + 1].second == 0 && a[i + 2].second == 0) {
      who = i + 1;
      sum = a[i].first + a[i + 2].first;
      break;
    }
  }
  if (who != -1) {
    ret.push_back(who);
    a.erase(a.begin() + who + 1);
    a.erase(a.begin() + who - 1);
    a[who - 1].first = sum;
    a[who - 1].second = 0;
    return 1;
  }
  return 0;
}

vector <int> get_from_ps(const vector <int> &ps) {
  vector <int> ret;
  vector < pair <ll, int> > ap(n);
  vector <int> fl(n, 0);
  for (auto p : ps) fl[p] = 1;
  transform(a.begin(), a.end(), fl.begin(), ap.begin(), [](ll a, int b) {return make_pair(a, b);});
  debug(ap);
  while (ap.size() > 1) {
    int ok = 0;
    ok |= find_101(ap, ret);
    debug(ap, ok);
    ok |= find_000(ap, ret);
    debug(ap, ok);
    debug("hi", ok, !ok);
    if (!ok) break;
  }
  while (ap.size() > 1 && ap.back().second != 1) {
    ret.push_back((int)ap.size() - 1);
    ap.pop_back();
    debug(ap);
  }
  while (ap.size() > 1 && ap[0].second != 1) {
    ret.push_back((int)0);
    ap.erase(ap.begin());
    debug(ap);
  }

  return ret;
}

void run() {
  cin >> n;
  f.resize(n, -inf);
  a.resize(n, 0);
  pre.resize(n, -2);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  
  for (int i = 0; i < n; ++i) {
    if (f[i] < a[i]) {
      f[i] = a[i];
      pre[i] = -1;
    }
    for (int j = i & 1; j < i; j += 2) {
      if (f[i] < f[j] + a[i]) {
        f[i] = f[j] + a[i];
        pre[i] = j;
      }
    }
  }

  auto t = max_element(f.begin(), f.end()) - f.begin();

  go(t);

  cout << f[t] << endl;

  auto ans = get_from_ps(ps);

  cout << ans.size() << endl;

  for (int i : ans) {
    cout << i + 1 << endl;
  }

}

int main() {
  run();
  return 0;
}


Measured memory_bytes: 256