#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long n;
  cin >> n;
  vector<long long> v;
  for (unsigned long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    v.push_back(x);
  }
  vector<long long> sum(n + 1);
  long long s = 0;
  sum[0] = 0;
  for (unsigned long long i = 1; i < n + 1; i++) {
    if (v[i - 1] > 0) {
      s += v[i - 1];
    }
    sum[i] = s;
  }
  map<long long, unsigned long long> ml;
  for (unsigned long long i = 0; i < n; i++) {
    if (ml.count(v[i]) == 0) {
      ml[v[i]] = i;
    }
  }
  map<long long, unsigned long long> mr;
  long long maxx;
  bool first = true;
  unsigned long long maxl, maxr;
  for (unsigned long long i = n - 1; i != -1; i--) {
    if (mr.count(v[i]) == 0) {
      if (ml[v[i]] < i) {
        auto lidx = ml[v[i]];
        auto x = 2 * v[i] + (sum[i] - sum[lidx + 1]);
        if (first or x > maxx) {
          first = false;
          maxx = x;
          maxl = lidx;
          maxr = i;
        }
      }
      mr[v[i]] = i;
    }
  }
  unsigned long long k = 0;
  for (unsigned long long i = 0; i < n; i++) {
    if (i < maxl or i > maxr or (i > maxl and i < maxr and v[i] < 0)) {
      k++;
    }
  }
  cout << maxx << " " << k << "\n";
  for (unsigned long long i = 0; i < n; i++) {
    if (i < maxl or i > maxr or (i > maxl and i < maxr and v[i] < 0)) {
      cout << (i + 1) << " ";
    }
  }
  cout << "\n";
}
