#include <bits/stdc++.h>
using namespace std;
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++) {
    scanf("%I64d", &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;
  long long ansin1, ansin2;
  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]]]) {
      p = 2 * in[i];
      if (p < ans) {
        continue;
      } else {
        ans = p;
        ansin1 = b[in[i]];
        ansin2 = e[in[i]];
        continue;
      }
    }
    if (b[in[i]] == 0) {
      p = v[e[in[i]]];
      if (in[i] < 0) {
        p += 2 * in[i];
      }
    } else {
      p = v[e[in[i]]] - v[b[in[i]] - 1];
      if (in[i] < 0) {
        p += 2 * in[i];
      }
    }
    if (ans <= p) {
      ansin1 = b[in[i]];
      ansin2 = e[in[i]];
      ans = p;
    }
  }
  vector<long long> tt;
  for (int j = 0; j < ansin1; j++) {
    tt.push_back(j);
  }
  for (int j = ansin2 + 1; j < n; j++) {
    tt.push_back(j);
  }
  for (int j = ansin1 + 1; j < ansin2; j++) {
    if (in[j] < 0) {
      tt.push_back(j);
    }
  }
  cout << ans << " " << tt.size() << "\n";
  for (long long i = 0; i < tt.size(); i++) {
    printf("%I64d ", tt[i] + 1);
  }
}
