#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000 + 5;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int a[MAXN];
long long sum[MAXN];
void solve(int n) {
  vector<int> ans;
  map<int, int> chg;
  ans.clear();
  chg.clear();
  sum[0] = 0LL;
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + max(a[i], 0);
  }
  for (int i = 1; i <= n; i++) {
    chg[a[i]] = i;
  }
  long long cur = -INF;
  long long tmp = 0;
  int ans_l = 0, ans_r = 0;
  for (int i = 1; i <= n; i++) {
    int r = chg[a[i]];
    if (r <= i) continue;
    tmp = sum[r - 1] - sum[i] + a[i] + a[r];
    if (tmp > cur) {
      cur = tmp;
      ans_l = i;
      ans_r = r;
    }
  }
  for (int i = 1; i < ans_l; i++) ans.push_back(i);
  for (int i = ans_l + 1; i < ans_r; i++) {
    if (a[i] < 0) ans.push_back(i);
  }
  for (int i = ans_r + 1; i <= n; i++) ans.push_back(i);
  cout << cur << " " << ans.size() << endl;
  if (ans.size() > 0) {
    for (int i = 0; i < ans.size() - 1; i++) printf("%d ", ans[i]);
    printf("%d\n", ans[ans.size() - 1]);
  }
  return;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  solve(n);
  return 0;
}
