#include <bits/stdc++.h>
using namespace std;
const int N = 300500;
int a[N], b[N], c[N];
long long s[N];
long long s1[N];
int n, sz;
int l[N], r[N];
long long sum(int l, int r) {
  if (!l)
    return s[r];
  else
    return s[r] - s[l - 1];
}
long long sum1(int l, int r) { return sum(l + 1, r - 1) + a[l] + a[r]; }
int nx[N];
int last[N];
long long slow() {
  long long res = -(1LL << 32);
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      if (a[i] == a[j]) {
        long long sum = a[i] + a[j];
        for (int k = i + 1; k < j; k++)
          if (a[k] > 0) sum += a[k];
        res = max(res, sum);
      }
  return res;
}
int main() {
  int ans = -1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int t = a[i];
    if (a[i] < 0) t = 0;
    if (i == 0)
      s[i] = t, s1[i] = a[i];
    else
      s[i] = s[i - 1] + t, s1[i] = s1[i - 1] + a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  sz = unique(b, b + n) - b;
  for (int i = 0; i < n; i++)
    c[i] = lower_bound(b, b + n, a[i]) - b, l[c[i]] = r[c[i]] = -1,
    nx[i] = last[i] = -1;
  for (int i = 0; i < n; i++)
    if (l[c[i]] == -1) l[c[i]] = i;
  for (int i = n - 1; i >= 0; i--)
    if (r[c[i]] == -1) r[c[i]] = i;
  long long res = -1;
  for (int i = 0; i < n; i++) {
    if (l[c[i]] != r[c[i]] && l[c[i]] != -1 && r[c[i]] != -1) {
      if (a[i] >= 0 && res < sum(l[c[i]], r[c[i]]))
        res = sum(l[c[i]], r[c[i]]), ans = i;
      else if (a[i] < 0 && res < sum1(l[c[i]], r[c[i]]))
        res = sum1(l[c[i]], r[c[i]]), ans = i;
    }
  }
  if (ans == -1) {
    for (int i = 0; i < n; i++) {
      if (last[c[i]] != -1) nx[last[c[i]]] = i;
      last[c[i]] = i;
    }
    res = -(1LL << 32LL);
    for (int i = 0; i < sz; i++)
      if (nx[i] != -1 && res < sum1(i, nx[i]))
        res = sum1(i, nx[i]), ans = i, l[i] = i, r[i] = nx[i];
  }
  int k = 0;
  k += l[c[ans]];
  for (int i = l[c[ans]] + 1; i < r[c[ans]]; i++)
    if (a[i] < 0) k++;
  k += (n - 1 - r[c[ans]]);
  cout << res << " " << k << endl;
  for (int i = 0; i < l[c[ans]]; i++) cout << i + 1 << " ";
  for (int i = l[c[ans]] + 1; i < r[c[ans]]; i++)
    if (a[i] < 0) cout << i + 1 << " ";
  for (int i = r[c[ans]] + 1; i < n; i++) cout << i + 1 << " ";
  return 0;
}
