#include <bits/stdc++.h>
using namespace std;
map<int, int> f;
map<int, int> l;
int a[300007];
long long int rs[300007];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    rs[i] = rs[i - 1] + (a[i] > 0 ? a[i] : 0);
  }
  for (int i = 1; i <= n; i++) {
    l[a[i]] = i;
  }
  long long int mx = -99999999999999999;
  long long int tmp;
  int j;
  int mi, mj;
  for (int i = 1; i <= n; i++) {
    j = l[a[i]];
    if (j > i) {
      tmp = rs[j - 1] - rs[i] + a[i] + a[j];
      if (tmp > mx) {
        mx = tmp;
        mi = i;
        mj = j;
      }
    }
  }
  cout << mx << " ";
  vector<int> aaa;
  int cc = 0;
  for (int i = 1; i < mi; i++) {
    cc++;
    aaa.push_back(i);
  }
  for (int i = mi + 1; i < mj; i++) {
    if (a[i] < 0) {
      cc++;
      aaa.push_back(i);
    }
  }
  for (int i = mj + 1; i <= n; i++) {
    cc++;
    aaa.push_back(i);
  }
  cout << cc << "\n";
  for (int i = 0; i < cc; i++) {
    cout << aaa[i] << " ";
  }
  return 0;
}
