#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int T, n, m, l, r;
long long ans = -1e10;
int arr[N];
long long com[N];
map<int, int> cnt;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", arr + i);
  }
  long long sum = 0;
  if (arr[1] > 0) {
    com[1] = arr[1];
    sum = arr[1];
  }
  for (int i = 2; i <= n; ++i) {
    if (arr[i] > 0) sum += arr[i];
    com[i] = sum;
  }
  for (int i = 1; i <= n; ++i) {
    if (cnt[arr[i]]) {
      long long nans =
          (long long)arr[i] + arr[cnt[arr[i]]] + com[i - 1] - com[cnt[arr[i]]];
      if (nans > ans) {
        l = cnt[arr[i]];
        r = i;
        ans = nans;
      }
    } else {
      cnt[arr[i]] = i;
    }
  }
  printf("%lld ", ans);
  vector<int> cut;
  for (int i = 1; i <= n; ++i) {
    if (i == l || i == r || (i > l && i < r && arr[i] > 0)) continue;
    cut.push_back(i);
  }
  printf("%d\n", cut.size());
  for (int i = 0; i < cut.size(); ++i) {
    printf("%d ", cut[i]);
  }
  printf("\n");
}
