#include <bits/stdc++.h>
using namespace std;
int stringtoint(string s) {
  istringstream buffer(s);
  int value;
  buffer >> value;
}
std::string intToString(int i) {
  std::stringstream ss;
  std::string s;
  ss << i;
  s = ss.str();
  return s;
}
const long long N = 2000000010L;
const long long c = 1000000000L;
int main() {
  long long n;
  cin >> n;
  map<long long, long long> b, e;
  vector<long long> v(n, 0L);
  vector<long long> in;
  long long sum = 0L;
  long long tmp;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    in.push_back(tmp);
    if (b.count(tmp) == 0) b[tmp] = i;
    e[tmp] = i;
    if (tmp >= 0) sum += tmp;
    v[i] = sum;
  }
  long long ans = LONG_MIN;
  vector<long long> ret;
  vector<long long> t;
  long long countans = 0;
  for (long long i = 0; i < n; i++) {
    long te = e[in[i]];
    long long tb = b[in[i]];
    if (e[in[i]] == b[in[i]] || b[in[i]] != i) continue;
    long count = 0;
    long long p = 0L;
    if (v[e[in[i]]] == v[b[in[i]]]) {
      t.clear();
      p = 2 * in[i];
      for (int j = 0; j < b[in[i]]; j++) {
        t.push_back(j);
      }
      for (int j = i + 1; j < e[in[i]]; j++) {
        t.push_back(j);
      }
      for (int j = e[in[i]] + 1; j < n; j++) {
        t.push_back(j);
      }
      if (p < ans) {
        t.clear();
        continue;
      } else {
        ans = p;
        ret = t;
        t.clear();
        continue;
      }
    }
    for (int j = b[in[i]] + 1; j < e[in[i]]; j++) {
      if (in[j] < 0) {
        count++;
        t.push_back(j);
      }
    }
    if (b[in[i]] == 0) {
      p = v[e[in[i]]];
      if (in[i] < 0) {
        p += 2 * in[i];
      }
      for (long long j = e[in[i]] + 1; j < n; j++) {
        t.push_back(j);
      }
      count = 0;
    } else {
      p = v[e[in[i]]] - v[b[in[i]] - 1];
      if (in[i] < 0) {
        p += 2 * in[i];
      }
      for (int j = 0; j < b[in[i]]; j++) {
        t.push_back(j);
      }
      for (int j = e[in[i]] + 1; j < n; j++) {
        t.push_back(j);
      }
      count = n - (e[in[i]] - b[in[i]] + 1);
    }
    if (ans <= p) {
      ret = t;
      ans = p;
    }
    t.clear();
  }
  cout << ans << " " << ret.size() << "\n";
  for (long long i = 0; i < ret.size(); i++) {
    cout << ret[i] + 1 << " ";
  }
}
