#include <bits/stdc++.h>
using namespace std;
const int MaxN = 300000 + 5;
const long long oo = 0x3f3f3f3fLL * 0x3f3f3f3fLL;
int N;
int a[MaxN];
long long s[MaxN];
map<int, int> fir;
vector<int> tr;
long long ans;
int lb, rb, cut;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", a + i);
  }
  s[0] = 0;
  for (int i = 1; i <= N; ++i) {
    s[i] = s[i - 1] + max(a[i], 0);
  }
  fir.clear();
  ans = -oo;
  for (int i = 1; i <= N; ++i) {
    if (fir.count(a[i])) {
      int pre = fir[a[i]];
      long long cnt = a[pre] + a[i] + s[i - 1] - s[pre];
      if (cnt > ans) {
        ans = cnt;
        lb = pre;
        rb = i;
      }
    } else
      fir[a[i]] = i;
  }
  tr.clear();
  for (int i = 1; i <= N; ++i) {
    if (i < lb || i > rb || (i > lb && i < rb && a[i] < 0)) tr.push_back(i);
  }
  cout << ans << ' ' << tr.size() << endl;
  for (int i = 0; i < (int)tr.size(); ++i) {
    if (i + 1 == (int)tr.size())
      printf("%d\n", tr[i]);
    else
      printf("%d ", tr[i]);
  }
  return 0;
}
