#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 0, 1, -1, 1, 1, -1};
template <class T>
inline bool get(T& n) {
  char c, mul = 1;
  n = 0;
  while (!isdigit(c = getchar_unlocked()) && (c != EOF) && (c != '-'))
    ;
  if (c == EOF) return false;
  if (c == '-') {
    c = getchar_unlocked();
    mul = -1;
  }
  for (; isdigit(c); c = getchar_unlocked()) n = n * 10 + c - '0';
  n *= mul;
  return true;
}
inline void get(char& c) {
  while (isspace(c = getchar_unlocked()))
    ;
}
int main() {
  int n;
  get(n);
  vector<int> v(n + 1);
  vector<long long> sum(n + 1);
  map<int, int> b, e;
  for (int(i) = (1), _ = (n); (i) <= _; ++(i)) {
    get(v[i]);
    sum[i] = sum[i - 1];
    if (!b.count(v[i])) b[v[i]] = i;
    e[v[i]] = i;
    if (v[i] > 0) sum[i] += v[i];
  }
  long long maxapp = -0x3f3f3f3f3f3f3f3fLL;
  int l = 1, r = n;
  for (typeof((b).begin()) i = (b).begin(); i != (b).end(); ++i) {
    if (e.count(i->first)) {
      int left = (*i).second, right = e[(*i).first];
      if (left == right) continue;
      if (sum[right - 1] - sum[left] + ((*i).first << 1) > maxapp) {
        maxapp = sum[right - 1] - sum[left] + ((*i).first << 1);
        l = left;
        r = right;
      }
    }
  }
  printf("%I64d", maxapp);
  vector<int> cut;
  for (int(i) = (1), _ = (l - 1); (i) <= _; ++(i)) cut.push_back(i);
  for (int(i) = (l + 1), _ = (r - 1); (i) <= _; ++(i))
    if (v[i] < 0) cut.push_back(i);
  for (int(i) = (r + 1), _ = (n); (i) <= _; ++(i)) cut.push_back(i);
  printf(" %d\n", (int)cut.size());
  for (int(i) = 0, _ = ((int)cut.size()); (i) < _; ++i) printf("%d ", cut[i]);
  return 0;
}
