#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int a[N], la[N], b[N];
long long s[N];
map<int, int> last;
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (last.count(a[i]))
      la[i] = last[a[i]];
    else {
      la[i] = 0;
      last[a[i]] = i;
    }
    s[i] = max(a[i], 0) + s[i - 1];
  }
  int u = 0, l = 0, r = 0;
  long long best = 0;
  for (int i = 1; i <= n; i++)
    if (la[i]) {
      if (!u || best < s[i - 1] - s[la[i]] + a[i] * 2) {
        u = 1;
        best = s[i - 1] - s[la[i]] + a[i] * 2;
        l = la[i], r = i;
      }
    }
  int bn = 0;
  for (int i = 1; i <= n; i++)
    if (i < l || i > r) {
      ++bn;
      b[i] = 1;
    } else if (i == l || i == r)
      b[i] = 0;
    else if (a[i] < 0) {
      ++bn;
      b[i] = 1;
    } else
      b[i] = 0;
  printf("%I64d %d\n", best, bn);
  for (int i = 1; i <= n; i++)
    if (b[i]) printf("%d ", i);
  return 0;
}
