#include <bits/stdc++.h>
using namespace std;
struct ent {
  int val, pos;
  inline bool operator<(const ent &cpr) const { return val < cpr.val; }
};
set<ent> pq;
int n;
int val[300005];
long long sum[300005];
long long ret;
int a, b;
int del[300005];
int dcnt;
int main() {
  ret = -1000000000000ll;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + max(val[i], 0);
    ent nw;
    nw.pos = i;
    nw.val = val[i];
    set<ent>::iterator it;
    it = pq.find(nw);
    if (it == pq.end())
      pq.insert(nw);
    else {
      if (ret < 2 * val[i] + sum[i - 1] - sum[(*it).pos]) {
        ret = 2 * val[i] + sum[i - 1] - sum[(*it).pos];
        a = (*it).pos;
        b = i;
      }
    }
  }
  cout << ret;
  for (int i = 1; i < a; i++) del[++dcnt] = i;
  for (int i = a + 1; i < b; i++)
    if (val[i] < 0) del[++dcnt] = i;
  for (int i = b + 1; i <= n; i++) del[++dcnt] = i;
  printf(" %d\n", dcnt);
  for (int i = 1; i <= dcnt; i++) printf("%d ", del[i]);
}
