#include <bits/stdc++.h>
struct A {
  int num, srt, ind;
} a[1000001];
bool cmp1(A x, A y) { return x.num < y.num; }
bool cmp2(A x, A y) { return x.ind < y.ind; }
long long sum[1000001];
int f1[1000001], f2[1000001];
int cut[1000001], len;
int main() {
  int n, st, ed;
  long long max;
  while (scanf("%d", &n) == 1) {
    sum[0] = 0LL;
    for (int i = 1; i <= n; i++) {
      a[i].ind = i;
      scanf("%d", &a[i].num);
      if (a[i].num > 0)
        sum[i] = sum[i - 1] + a[i].num;
      else
        sum[i] = sum[i - 1];
    }
    std::sort(a + 1, a + n + 1, cmp1);
    a[1].srt = 1;
    for (int i = 2; i <= n; i++) {
      if (a[i].num == a[i - 1].num)
        a[i].srt = a[i - 1].srt;
      else
        a[i].srt = a[i - 1].srt + 1;
    }
    std::sort(a + 1, a + n + 1, cmp2);
    for (int i = 1; i <= n; i++) f1[i] = f2[i] = -1;
    for (int i = 1; i <= n; i++) {
      if (f1[a[i].srt] == -1) f1[a[i].srt] = i;
    }
    for (int i = n; i >= 1; i--) {
      if (f2[a[i].srt] == -1) f2[a[i].srt] = i;
    }
    max = -(1LL << 60);
    for (int i = 1; i <= n; i++) {
      if (f1[a[i].srt] != f2[a[i].srt] &&
          sum[f2[a[i].srt] - 1] - sum[f1[a[i].srt]] + 2 * a[i].num > max) {
        max = sum[f2[a[i].srt] - 1] - sum[f1[a[i].srt]] + 2 * a[i].num;
        st = f1[a[i].srt];
        ed = f2[a[i].srt];
      }
    }
    len = 0;
    for (int i = 1; i < st; i++) cut[len++] = i;
    for (int i = st + 1; i <= ed - 1; i++) {
      if (a[i].num < 0) cut[len++] = i;
    }
    for (int i = ed + 1; i <= n; i++) cut[len++] = i;
    printf("%I64d %d\n", max, len);
    for (int i = 0; i < len; i++)
      printf("%d%c", cut[i], i == len - 1 ? '\n' : ' ');
  }
}
