#include <bits/stdc++.h>
using namespace std;
const double Pi = acos(-1.0);
long long mod = 1000000007;
int n;
long long arr[300005];
long long cum[300005];
map<long long, int> last;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int j = (int)(1); j < (int)(n + 1); j++) cin >> arr[j];
  cum[0] = 0;
  for (int i = (int)(1); i < (int)(n + 1); i++) {
    last[arr[i]] = i;
    if (arr[i] >= 0)
      cum[i] = cum[i - 1] + arr[i];
    else
      cum[i] = cum[i - 1];
  }
  long long ans = -(1LL << 50);
  int a, b;
  for (int i = (int)(1); i < (int)(n + 1); i++) {
    int id = last[arr[i]];
    if (id > i && cum[id - 1] - cum[i] + arr[i] + arr[id] > ans) {
      ans = cum[id - 1] - cum[i] + arr[i] + arr[id];
      a = i, b = id;
    }
  }
  vector<int> v;
  for (int i = (int)(1); i < (int)(a); i++) v.push_back(i);
  for (int i = (int)(a + 1); i < (int)(b); i++)
    if (arr[i] < 0) v.push_back(i);
  for (int i = (int)(b + 1); i < (int)(n + 1); i++) v.push_back(i);
  cout << ans << " " << v.size() << endl;
  for (int j = (int)(0); j < (int)(v.size() + 0); j++) {
    if (j > 0) cout << ' ';
    cout << v[j];
  };
  return 0;
}
