#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}
int min(int a, int b) { return a + b - max(a, b); }
int main() {
  int n;
  cin >> n;
  int a[n];
  long long s[n];
  map<int, int> last;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    last[a[i]] = i;
    if (i == 0) {
      s[i] = a[i];
      if (s[i] < 0) s[i] = 0;
    } else {
      s[i] = s[i - 1];
      if (a[i] > 0) s[i] += a[i];
    }
    if (a[i] >= 0) ++ans;
  }
  if (ans == 0) {
    int res = -2147483647, l, r;
    for (int i = 0; i < n; ++i) {
      if (last.count(a[i]) == 0) continue;
      if (last[a[i]] == i) continue;
      int q = a[i] * 2;
      if (res < q) {
        res = q;
        l = i;
        r = last[a[i]];
      }
    }
    int k = 0;
    for (int i = 0; i < n; ++i) {
      if (i != l && i != r) ++k;
    }
    cout << res << " " << k << endl;
    for (int i = 0; i < n; ++i) {
      if (i != l && i != r) cout << i + 1 << " ";
    }
  } else {
    long long res = -100000000000000000ll;
    int l, r;
    for (int i = 0; i < n; ++i) {
      if (last.count(a[i]) == 0) continue;
      if (last[a[i]] == i) continue;
      long long q = s[last[a[i]]] + 2 * a[i] * (a[i] < 0 ? 1 : 0);
      if (i > 0) q -= s[i - 1];
      if (res < q) {
        res = q;
        l = i;
        r = last[a[i]];
      }
    }
    int k = 0;
    for (int i = 0; i < n; ++i) {
      if (i < l || i > r || (a[i] < 0 && i != l && i != r)) ++k;
    }
    cout << res << " " << k << endl;
    for (int i = 0; i < n; ++i) {
      if (i < l || i > r || (a[i] < 0 && i != l && i != r))
        cout << i + 1 << " ";
    }
  }
}
