#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5;
const long long oo = 1000000000000010LL;
struct node {
  int num, h;
} b[maxn];
int a[maxn], c[maxn], pans[maxn], l[maxn], r[maxn], u[maxn];
long long s[maxn];
bool cmp(node a, node b) { return a.num < b.num; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i), b[i].num = a[i], b[i].h = i;
    s[i] = (i ? s[i - 1] : 0LL) + 1LL * a[i] * (a[i] > 0);
  }
  sort(b, b + n, cmp);
  int cnt = 0;
  c[b[0].h] = 0;
  for (int i = 1; i < n; i++) {
    if (b[i].num > b[i - 1].num) cnt++;
    c[b[i].h] = cnt;
  }
  memset(u, 0, sizeof(u));
  memset(r, 0, sizeof(r));
  for (int i = 0; i < n; i++) {
    if (!u[c[i]]) l[c[i]] = i, u[c[i]] = 1;
    r[c[i]] = max(r[c[i]], i);
  }
  long long ans = -oo;
  int lans, rans;
  for (int i = 0; i < cnt + 1; i++) {
    if (r[c[i]] == l[c[i]]) continue;
    long long tmp = s[r[c[i]] - 1] - s[l[c[i]]] + a[r[c[i]]] + a[l[c[i]]];
    if (tmp > ans) ans = tmp, lans = l[c[i]], rans = r[c[i]];
  }
  cnt = 0;
  for (int i = 0; i < lans; i++) pans[++cnt] = i;
  for (int i = lans + 1; i < rans; i++)
    if (a[i] <= 0) pans[++cnt] = i;
  for (int i = rans + 1; i < n; i++) pans[++cnt] = i;
  printf("%I64d %d\n", ans, cnt);
  for (int i = 1; i < cnt; i++) printf("%d ", pans[i] + 1);
  if (cnt) printf("%d\n", pans[cnt] + 1);
  return 0;
}
