#include <bits/stdc++.h>
using namespace std;
int const maxn = (int)3e5 + 111;
long long const inf = (long long)1e18;
int n;
long long a[maxn];
long long sum[maxn];
map<int, int> ML;
map<int, int> MR;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1];
    if (a[i] > 0) {
      sum[i] += a[i];
    }
  }
  for (int i = 1; i <= n; i++) {
    MR[a[i]] = i;
  }
  for (int i = n; i >= 1; i--) {
    ML[a[i]] = i;
  }
  long long maxi = -inf;
  int indl = -1, indr = -1;
  for (int i = 1; i <= n; i++) {
    int t = a[i];
    int l = ML[t];
    int r = MR[t];
    if (l > 0 && r > 0 && l != r) {
      long long ss = sum[r - 1] + a[r] - sum[l] + a[l];
      if (ss > maxi) {
        maxi = ss;
        indl = l;
        indr = r;
      }
    }
  }
  cout << maxi << " ";
  vector<int> ans;
  for (int i = 1; i < indl; i++) ans.push_back(i);
  for (int i = indr + 1; i <= n; i++) ans.push_back(i);
  for (int i = indl + 1; i <= indr - 1; i++) {
    if (a[i] <= 0) ans.push_back(i);
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
