#include <bits/stdc++.h>
using namespace std;
int n, a[300500], l, r;
long long sa[300500], res = -1e18, cr;
vector<int> v;
map<int, int> s;
int main() {
  while (~scanf("%d", &n)) {
    s.clear();
    res = -1e61;
    memset(sa, 0, sizeof(sa));
    sa[0] = 0;
    v.clear();
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a[i]);
      sa[i] = (i ? sa[i - 1] : 0) + (a[i] > 0 ? a[i] : 0);
      if (s.find(a[i]) != s.end()) {
        cr = 2 * a[i] + sa[i - 1] - sa[s[a[i]]];
        if (cr >= res) {
          res = cr;
          l = s[a[i]];
          r = i;
        }
      } else
        s[a[i]] = i;
    }
    for (int i = 1; i <= n; i++)
      if ((i < l) || (i > r) || ((i > l) && (i < r) && (a[i] < 0)))
        v.push_back(i);
    printf("%I64d %d\n", res, v.size());
    for (int i = 0; i < v.size(); i++) printf("%d ", v[i]);
    puts("");
  }
}
