#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300001;
int MN[MAXN];
int MX[MAXN];
int A[MAXN];
long long SUM[MAXN];
map<int, int> M;
int main() {
  int n;
  scanf("%d", &n);
  int c = 1;
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &A[i]);
    SUM[i] = SUM[i - 1] + (A[i] > 0 ? A[i] : 0);
    if (M.find(A[i]) == M.end()) {
      M[A[i]] = c;
      c++;
      MN[c - 1] = i;
      MX[c - 1] = i;
    } else {
      MX[M[A[i]]] = i;
    }
  }
  long long ans = -1e18;
  int a, b;
  for (int i = 1; i < n + 1; i++) {
    int x = M[A[i]];
    int mn = MN[x];
    int mx = MX[x];
    if (mx > mn) {
      if (2 * A[mn] + SUM[mx - 1] - SUM[mn] > ans) {
        ans = 2 * A[mn] + SUM[mx - 1] - SUM[mn];
        a = mn;
        b = mx;
      }
    }
  }
  cout << ans << " ";
  int cnt = 0;
  vector<int> v;
  for (int i = 1; i < n + 1; i++)
    if (i != a && i != b) {
      if (i < a || i > b || A[i] < 0) v.push_back(i);
    }
  cout << v.size() << endl;
  int x = v.size();
  for (int i = 0; i < x; i++) cout << v[i] << " ";
  return 0;
}
