#include <bits/stdc++.h>
using namespace std;
int n;
int a[312345];
map<int, int> last;
long long cumSum[312345];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  vector<int> toRemove;
  long long totalSum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    last[a[i]] = i;
    totalSum += (a[i] >= 0) * a[i];
  }
  for (int i = n; i >= 1; i--) {
    cumSum[i] = (a[i] >= 0 ? a[i] + cumSum[i + 1] : cumSum[i + 1]);
  }
  long long sum = 0;
  long long best = -1e15;
  int best_l = n + 1;
  int best_r = -1;
  for (int i = 1; i <= n; i++) {
    if (i < last[a[i]]) {
      long long curSum;
      if (a[i] >= 0) {
        curSum = totalSum - sum - cumSum[last[a[i]] + 1];
      } else {
        curSum = totalSum - sum - cumSum[last[a[i]] + 1] + 2 * a[i];
      }
      if (curSum > best) {
        best = curSum;
        best_l = i;
        best_r = last[a[i]];
      }
    }
    sum += (a[i] >= 0) * a[i];
  }
  for (int i = 1; i < best_l; i++) toRemove.push_back(i);
  for (int i = best_r + 1; i <= n; i++) toRemove.push_back(i);
  for (int i = best_l + 1; i <= best_r - 1; i++) {
    if (a[i] < 0) toRemove.push_back(i);
  }
  sort(toRemove.begin(), toRemove.end());
  int sz = toRemove.size();
  cout << best << " " << sz << "\n";
  for (int i : toRemove) cout << i << " ";
}
