#include <bits/stdc++.h>
using namespace std;
typedef const long long &CI;
long long mas[300300 * 4], arr2[300300], arr3[300300];
pair<long long, long long> arr[300300];
void build(long long v, long long lp, long long rp) {
  if (lp == rp) {
    mas[v] = arr2[lp];
    return;
  }
  long long m = (lp + rp) / 2;
  build(2 * v, lp, m);
  build(2 * v + 1, m + 1, rp);
  mas[v] = mas[2 * v] + mas[2 * v + 1];
}
inline long long getSum(CI v, CI lPos, CI rPos, CI l, CI r) {
  if (r < l) return 0;
  if (l == lPos && r == rPos) return mas[v];
  long long m = (lPos + rPos) / 2;
  return getSum(2 * v, lPos, m, l, min(m, r)) +
         getSum(2 * v + 1, m + 1, rPos, max(l, m + 1), r);
}
int main() {
  ios_base::sync_with_stdio(0);
  long long n;
  long long mval = LLONG_MIN;
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> arr3[i];
    arr[i].first = arr3[i];
    arr[i].second = i;
    arr2[i] = arr3[i] > 0 ? arr3[i] : 0;
  }
  build(1, 0, n - 1);
  stable_sort(arr, arr + n);
  long long j;
  bool k;
  long long FA;
  long long ind1 = 0, ind2 = 0;
  for (long long i = 0; i < n - 1; ++i) {
    k = false;
    j = i;
    while (arr[i].first == arr[i + 1].first) {
      k = true;
      ++i;
      if (i == n - 1) break;
    }
    if (k) {
      FA = getSum(1, 0, n - 1, arr[j].second + 1, arr[i].second - 1) +
           2 * arr[j].first;
      if (FA > mval) {
        mval = FA;
        ind1 = arr[j].second;
        ind2 = arr[i].second;
      }
    }
  }
  cout << mval << " ";
  vector<long long> ans;
  long long a2 = 0;
  for (long long i = 0; i < n; ++i) {
    if (i > ind1 && i < ind2) {
      if (arr2[i] == 0 && arr3[i] != 0) {
        ++a2;
        ans.push_back(i + 1);
      }
    } else if (i == ind1 || i == ind2)
      ;
    else {
      ++a2;
      ans.push_back(i + 1);
    }
  }
  cout << a2 << endl;
  for (const auto &it : ans) cout << it << " ";
}
