#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 10;
map<long long, long long> S;
long long n, f[maxn], g[maxn], x, y, ans, m, h[maxn];
int main() {
  x = y = -1;
  S.clear();
  g[0] = 0;
  ans = -2e18;
  scanf("%I64d", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%I64d", &f[i]);
    if (f[i] > 0)
      g[i] = g[i - 1] + f[i];
    else
      g[i] = g[i - 1];
    if (S[f[i]] == 0)
      S[f[i]] = i;
    else {
      if (g[i - 1] - g[S[f[i]]] + f[i] * 2 > ans) {
        ans = g[i - 1] - g[S[f[i]]] + f[i] * 2;
        x = S[f[i]];
        y = i;
      }
    }
  }
  m = 0;
  for (long long i = 1; i < x; i++) h[m++] = i;
  for (long long i = x + 1; i < y; i++)
    if (f[i] < 0) h[m++] = i;
  for (long long i = y + 1; i <= n; i++) h[m++] = i;
  printf("%I64d %I64d\n", ans, m);
  for (long long i = 0; i < m; i++) printf("%I64d ", h[i]);
  puts("");
  return 0;
}
