#include <bits/stdc++.h>
using namespace std;
int const MAXN = 400000;
int a[MAXN];
long long pref[MAXN];
long long suff[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  int n = 0;
  vector<int> ans;
  cin >> n;
  long long sum = 0;
  pref[0] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += max(a[i], 0);
    pref[i] = sum;
  }
  sum = 0LL;
  suff[n + 1] = 0LL;
  for (int i = n; i > 0; --i) {
    sum += max(a[i], 0);
    suff[i] = sum;
  }
  map<int, int> m;
  for (int i = 1; i <= n; ++i) {
    if (m.find(a[i]) == m.end()) {
      m.insert(make_pair(a[i], i));
    }
  }
  long long best = -1000000000000000000LL;
  int best_start = 0;
  int best_finish = 0;
  for (int i = n; i > 0; --i) {
    int f = m.find(a[i])->second;
    if (f < i) {
      if (best < sum - pref[f - 1] - suff[i + 1] + 2LL * min(0, a[i])) {
        best = sum - pref[f - 1] - suff[i + 1] + 2LL * min(0, a[i]);
        best_start = f;
        best_finish = i;
      }
    }
  }
  for (int i = 1; i < best_start; ++i) ans.push_back(i);
  for (int i = best_start + 1; i < best_finish; ++i)
    if (a[i] < 0) ans.push_back(i);
  for (int i = best_finish + 1; i <= n; ++i) ans.push_back(i);
  cout << best << " " << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
