#include <bits/stdc++.h>
using namespace std;
long long a[400009];
map<long long, vector<long long> > mp;
long long sum[400009];
int main() {
  long long n;
  cin >> n;
  long long sm = 0;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] > 0) sm += a[i];
    sum[i] = sm;
    mp[a[i]].push_back(i);
  }
  long long MX = -1000000000000009, u, v;
  for (int i = 1; i <= n; i++) {
    long long len = mp[a[i]].size();
    if (len > 1) {
      long long an = sum[mp[a[i]][len - 1]] - sum[mp[a[i]][0] - 1];
      if (a[i] < 0) an += 2 * a[i];
      if (MX < an) {
        MX = an;
        u = mp[a[i]][0];
        v = mp[a[i]][len - 1];
      }
    }
  }
  vector<long long> V;
  for (int i = 1; i <= n; i++) {
    if ((i < u || i > v) || (i != u && i != v && a[i] < 0)) V.push_back(i);
  }
  long long L = V.size();
  cout << MX << " " << L << endl;
  for (int i = 0; i < L; i++) cout << V[i] << " ";
  return 0;
}
