#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
#pragma GCC optimize("O500")
using namespace std;
const bool db = false;
long long t[4 * 300100], a[300100];
void build(int v, int L, int R) {
  if (L == R)
    t[v] = max(0LL, a[L]);
  else {
    int md = (L + R) >> 1;
    build(v << 1, L, md);
    build((v << 1) + 1, md + 1, R);
    t[v] = t[v << 1] + t[(v << 1) + 1];
  }
}
long long get(int v, int L, int R, int l, int r) {
  if (L == l && r == R)
    return t[v];
  else {
    int md = (L + R) >> 1;
    if (r <= md)
      return get(v << 1, L, md, l, r);
    else if (md < l)
      return get((v << 1) + 1, md + 1, R, l, r);
    else
      return (get(v << 1, L, md, l, md) +
              get((v << 1) + 1, md + 1, R, md + 1, r));
  }
}
map<int, int> L, R;
int main() {
  int n;
  scanf("%d\n", &n);
  for (int i = 1; i <= n; i++) scanf("%lld ", &a[i]);
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    if (!L.count(a[i])) L[a[i]] = i;
    R[a[i]] = i;
  }
  long long mx = LLONG_MIN, temp;
  int ans_l, ans_r;
  ans_l = ans_r = 1;
  for (auto i : L) {
    if (R[i.first] != i.second) {
      temp = 2 * i.first;
      if (L[i.first] + 1 < R[i.first])
        temp += get(1, 1, n, L[i.first] + 1, R[i.first] - 1);
      if (mx < temp) mx = temp, ans_l = L[i.first], ans_r = R[i.first];
    }
  }
  vector<int> ans;
  for (int i = 1; i < ans_l; i++) ans.push_back(i);
  for (int i = ans_l + 1; i <= ans_r - 1; i++)
    if (a[i] < 0) ans.push_back(i);
  for (int i = ans_r + 1; i <= n; i++) ans.push_back(i);
  printf("%lld %d\n", mx, ans.size());
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
  return 0;
}
