#include <bits/stdc++.h>
using namespace std;
int n, arr[300010], nxt[300010];
long long cum[300010];
int rem[300010];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  map<int, int> was;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    cum[i + 1] = arr[i] >= 0 ? cum[i] + arr[i] : cum[i];
    if (was.count(arr[i])) {
      nxt[was[arr[i]]] = i;
    } else {
      was[arr[i]] = i;
    }
  }
  int l, r;
  long long sum = -999999999999999;
  for (int i = 0; i < n - 1; ++i) {
    if (nxt[i] != 0) {
      int tl = i, tr = nxt[i];
      long long tsum = cum[tr + 1] - cum[tl] + (arr[i] < 0 ? 2 * arr[i] : 0);
      if (tsum > sum) l = tl, r = tr, sum = tsum;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (i < l || i > r || (arr[i] < 0 && i != l && i != r)) rem[ans++] = i;
  }
  cout << sum << ' ' << ans << '\n';
  for (int i = 0; i < ans; ++i) cout << rem[i] + 1 << ' ';
}
