#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int ST = 100010 * 4;
const int ST1 = 1000010;
const long long MOD = 1000000007;
long long ABS(long long a) {
  if (a < 0)
    return a * (-1);
  else
    return a;
}
int mas[ST];
long long sum[ST];
map<int, int> leff;
int main() {
  int n;
  cin >> n;
  long long cur = 0;
  long long best = -INF;
  long long lf = 0, rg = 0;
  for (int i = 0; i < n; i++) {
    cin >> mas[i];
    if (leff.find(mas[i]) == leff.end()) {
      leff[mas[i]] = i;
    }
    sum[i] = cur;
    if (mas[i] > 0) {
      cur += mas[i];
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    int t = mas[i];
    int j = leff[t];
    if (j < i) {
      long long ss = sum[i] - sum[j] + mas[i];
      if (t < 0) {
        ss += mas[i];
      }
      if (ss > best) {
        best = ss;
        lf = j;
        rg = i;
      }
    }
  }
  vector<int> ans;
  cout << best << " ";
  for (int i = 0; i < n; i++) {
    if (i < lf || i > rg) {
      ans.push_back(i + 1);
    } else {
      if (i != lf && i != rg && mas[i] < 0) {
        ans.push_back(i + 1);
      }
    }
  }
  cout << (int)((ans).size()) << endl;
  for (int i = 0; i < (int)((ans).size()); i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
