#include <bits/stdc++.h>
using namespace std;
const int nm = 300002;
const long long inf = 1000000000000000ll;
int n;
long long a[nm], sum[nm], sumNeg[nm];
map<long long, int> dau;
vector<int> xoa;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%I64d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    if (a[i] < 0)
      sumNeg[i] = sumNeg[i - 1] + a[i];
    else
      sumNeg[i] = sumNeg[i - 1];
  }
  long long kq = -inf;
  int kqi, kqj;
  for (int i = 1; i <= n; ++i) {
    int j = dau[a[i]];
    if (j) {
      long long s = sum[i] - sum[j - 1];
      if (i > j) s -= (sumNeg[i - 1] - sumNeg[j]);
      if (s > kq) {
        kq = s;
        kqi = i;
        kqj = j;
      }
    } else
      dau[a[i]] = i;
  }
  printf("%I64d ", kq);
  for (int i = 1; i < kqj; ++i) xoa.push_back(i);
  for (int i = kqj + 1; i < kqi; ++i)
    if (a[i] < 0) xoa.push_back(i);
  for (int i = kqi + 1; i <= n; ++i) xoa.push_back(i);
  printf("%d\n", xoa.size());
  for (int i = 0; i < xoa.size(); ++i) printf("%d ", xoa[i]);
}
