#include <bits/stdc++.h>
using namespace std;
const int max_n = 3 * 1000100;
map<int, vector<int> > a;
int tmp[max_n];
long long sup[max_n];
long long get_sum(int p1, int p2) {
  long long sum = sup[p2];
  if (p1 != 0) sum -= sup[p1 - 1];
  if (tmp[p1] < 0) sum += tmp[p1];
  if (tmp[p2] < 0) sum += tmp[p2];
  return sum;
}
long long get_sum2(int p1, int p2) {
  long long sum = sup[p2];
  if (p1 != 0) sum -= sup[p1 - 1];
  return sum;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t = 0;
    cin >> t;
    a[t].push_back(i);
    tmp[i] = t;
  }
  if (tmp[0] > 0)
    sup[0] = tmp[0];
  else
    sup[0] = 0;
  for (int i = 1; i < n; i++)
    if (tmp[i] > 0)
      sup[i] = sup[i - 1] + tmp[i];
    else
      sup[i] = sup[i - 1];
  long long max_sum = -100000000000000;
  int best_i = 0;
  int best_j = 0;
  for (map<int, vector<int> >::iterator it = a.begin(); it != a.end(); ++it) {
    int t = it->first;
    vector<int> &v = it->second;
    if (v.size() < 2) continue;
    int p1 = 0;
    int p2 = 1;
    while (p2 < v.size()) {
      long long sum = 0;
      if (p2 < v.size()) {
        sum = get_sum(v[p1], v[p2]);
        if (sum > max_sum) {
          max_sum = sum;
          best_i = v[p1];
          best_j = v[p2];
        }
      }
      p2++;
      while (p2 < v.size() &&
             get_sum(v[p1], v[p2]) > get_sum(v[p1], v[p2 - 1])) {
        sum = get_sum(v[p1], v[p2]);
        if (sum > max_sum) {
          max_sum = sum;
          best_i = v[p1];
          best_j = v[p2];
        }
        p2++;
      }
      if (p2 == v.size()) {
        break;
      }
      p1 = p2;
      p2++;
    }
  }
  int rem = 0;
  for (int i = 0; i < n; i++)
    if (i < best_i || i > best_j ||
        (tmp[i] < 0 && i != best_i && i != best_j)) {
      rem++;
    }
  cout << max_sum << " " << rem << endl;
  for (int i = 0; i < n; i++) {
    if (i < best_i || i > best_j || (tmp[i] < 0 && i != best_i && i != best_j))
      cout << i + 1 << " ";
  }
  cout << endl;
  return 0;
}
