#include <bits/stdc++.h>
using namespace std;
map<long long, int> occ;
long long s[300010];
long long a[300010];
vector<long long> out;
int main() {
  int i, n, l, r;
  long long maxx = -1000000000000ll;
  scanf("%d", &n);
  s[0] = 0;
  for (i = 0; i < n; ++i) {
    if (i) s[i] = s[i - 1];
    scanf("%lld", &a[i]);
    if (a[i] > 0) s[i] += a[i];
    if (occ[a[i]]) {
      int pos1 = occ[a[i]] - 1;
      long long s1 = s[i - 1];
      s1 -= s[pos1];
      if (s1 + 2 * a[i] > maxx) {
        maxx = s1 + 2 * a[i];
        l = pos1;
        r = i;
      }
    } else
      occ[a[i]] = i + 1;
  }
  for (i = 0; i < l; ++i) out.push_back(i + 1);
  for (i = l + 1; i < r; ++i)
    if (a[i] < 0) out.push_back(i + 1);
  for (i = r + 1; i < n; ++i) out.push_back(i + 1);
  printf("%lld %d\n", maxx, (int)out.size());
  for (i = 0; i < out.size(); ++i) printf("%lld ", out[i]);
}
