#include <bits/stdc++.h>
using namespace std;
long long int input[1000000];
long long int sums[1000000];
int main() {
  long long int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> input[i];
  }
  if (input[0] > 0) sums[0] = input[0];
  for (int i = 1; i < n; i++) {
    if (input[i] > 0)
      sums[i] = sums[i - 1] + input[i];
    else
      sums[i] = sums[i - 1];
  }
  map<int, int> m;
  int begin = 0, end = 0;
  std::map<int, int>::iterator it;
  long long int sum = -2000000009;
  for (int i = 0; i < n; i++) {
    if (m.find(input[i]) != m.end()) {
      it = m.find(input[i]);
      if (it->first + input[i] + (sums[i - 1] - sums[it->second]) > sum) {
        sum = it->first + input[i] + (sums[i - 1] - sums[it->second]);
        begin = it->second;
        end = i;
      }
    } else
      m.insert(make_pair(input[i], i));
  }
  cout << sum << " ";
  long long int result = 0;
  for (int i = 0; i < n; i++) {
    if (i < begin || i > end || (input[i] < 0 && i != begin && i != end))
      result++;
  }
  cout << result << endl;
  for (int i = 0; i < n; i++) {
    if (i < begin || i > end || (input[i] < 0 && i != begin && i != end))
      cout << i + 1 << " ";
  }
  return 0;
}
