#include <bits/stdc++.h>
using namespace std;
int n, a[300005], lv, rv;
map<int, int> mpl, mpr;
long long s[300005], an = -21000000000000ll;
int vt[300005];
void setIO(string a) {
  string in = a + ".in", out = a + ".out";
  freopen(in.c_str(), "r", stdin);
  freopen(out.c_str(), "w", stdout);
}
long long get(int L, int R) {
  if (L > R) return 0;
  return s[R] - s[L - 1];
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++) scanf("%d", &a[i]);
  for (int i = (1); i <= (n); i++) s[i] = s[i - 1] + max(0, a[i]);
  for (int i = (1); i <= (n); i++) mpr[a[i]] = i;
  for (int i = (n); i >= (1); i--) mpl[a[i]] = i;
  for (map<int, int>::iterator i = mpl.begin(); i != mpl.end(); i++) {
    int l = i->second, r = mpr[i->first];
    if (r - l + 1 <= 1) continue;
    long long tmp = i->first;
    if (l < r) tmp += i->first;
    tmp += get(l + 1, r - 1);
    if (tmp > an) {
      an = tmp;
      lv = l;
      rv = r;
    }
  }
  for (int i = (lv + 1); i <= (rv - 1); i++)
    if (a[i] < 0) vt[++*vt] = i;
  for (int i = (1); i <= (lv - 1); i++) vt[++*vt] = i;
  for (int i = (rv + 1); i <= (n); i++) vt[++*vt] = i;
  sort(vt + 1, vt + *vt + 1);
  printf("%I64d %d\n", an, *vt);
  for (int i = (1); i <= (*vt); i++) printf("%d ", vt[i]);
  return 0;
}
