#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> V(n);
  for (int i = 0; i < n; ++i) cin >> V[i];
  vector<long long> PRE(n);
  for (int i = 0; i < n; ++i) {
    PRE[i] = (i > 0 ? PRE[i - 1] : 0) + (V[i] > 0 ? V[i] : 0);
  }
  map<int, int> L, R;
  for (int i = 0; i < n; ++i) R[V[i]] = i;
  for (int i = n - 1; i >= 0; --i) L[V[i]] = i;
  long long ans = -1e15, l, r;
  for (auto v : L) {
    if (v.second == R[v.first]) continue;
    if (ans < 2 * v.first + PRE[R[v.first] - 1] - PRE[L[v.first]]) {
      ans = 2 * v.first + PRE[R[v.first] - 1] - PRE[L[v.first]];
      l = v.second;
      r = R[v.first];
    }
  }
  vector<long long> cut;
  for (int i = 0; i < n; ++i) {
    if (i < l || i > r || (i > l && i < r && V[i] < 0)) cut.push_back(i + 1);
  }
  cout << ans << " " << cut.size() << endl;
  for (int i = 0; i < cut.size(); ++i) cout << cut[i] << " ";
  cout << "\n";
  return 0;
}
