#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
long long n, p, b, L, m, q = 0, per = 0, k = 0, res = -10000000000000, sum = 0,
                         ras = 0, atc = 0, def = 0;
long long a[300009], t[10009], d[10009], l[100009], r[100009];
int main() {
  map<int, int> M;
  cin >> n;
  cin >> a[0];
  t[0] = max((long long)0, a[0]);
  M[a[0]] = 1;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    t[i] = t[i - 1] + max((long long)0, a[i]);
    if (M[a[i]] == 0) M[a[i]] = i + 1;
  }
  for (int i = n - 1; i > 0; i--) {
    if (M[a[i]] != 0 && M[a[i]] != i + 1) {
      ras = t[i - 1] - t[M[a[i]] - 1];
      ras += 2 * a[i];
      if (ras > res) {
        res = ras;
        L = i;
      }
    }
  }
  for (int i = 0; i < M[a[L]] - 1; i++) {
    d[k] = i + 1;
    k++;
  }
  for (int i = M[a[L]]; i < L; i++) {
    if (a[i] < 0) {
      d[k] = i + 1;
      k++;
    }
  }
  for (int i = L + 1; i < n; i++) {
    d[k] = i + 1;
    k++;
  }
  cout << res << " " << k << "\n";
  for (int i = 0; i < k; i++) {
    cout << d[i] << " ";
  }
  int kol234;
  cin >> kol234;
}
