#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 50;
const long long INF = 0x3f3f3f3f3f3f3f3f;
long long f[maxn], a[maxn], b[maxn];
map<int, int> l, r;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i <= n; i++) f[i] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (l[a[i]] == 0) l[a[i]] = i;
    r[a[i]] = i;
    f[i] = f[i - 1];
    if (a[i] > 0) f[i] += a[i];
  }
  long long ans = -INF;
  int x, y;
  for (int i = 1; i <= n; i++) {
    if (l[a[i]] == r[a[i]]) continue;
    long long sum = f[r[a[i]]] - f[l[a[i]] - 1];
    if (a[i] < 0) sum += a[i] * 2;
    if (sum > ans) {
      ans = sum;
      x = l[a[i]];
      y = r[a[i]];
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (i < x || i > y)
      b[++cnt] = i;
    else if (a[i] < 0 && i != x && i != y)
      b[++cnt] = i;
  }
  printf("%lld %d\n", ans, cnt);
  for (int i = 1; i <= cnt; i++) printf("%d ", b[i]);
}
