#include <bits/stdc++.h>
using namespace std;
map<int, int> first;
map<int, int> last;
long long ans;
int lf, rg;
int a[310000];
long long sum[310000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum[i + 1] = sum[i] + max(a[i], 0);
    last[a[i]] = i;
    if (!first.count(a[i])) first[a[i]] = i;
  }
  ans = -(1LL << 60);
  for (map<int, int>::iterator iter = first.begin(); iter != first.end();
       ++iter) {
    int l = iter->second;
    int r = last[a[l]];
    if (l == r) continue;
    long long cur = a[l] + a[r] + sum[r] - sum[l + 1];
    if (cur > ans) {
      ans = cur;
      lf = l;
      rg = r;
    }
  }
  int cnt = n;
  for (int i = 0; i < n; i++)
    if (i == lf || i == rg || (lf < i && i < rg && a[i] > 0)) cnt--;
  printf(
      "%lld"
      " %d\n",
      ans, cnt);
  for (int i = 0; i < n; i++)
    if (!(i == lf || i == rg || (lf < i && i < rg && a[i] > 0)))
      printf("%d ", i + 1);
  ;
  return 0;
}
