#include <bits/stdc++.h>
using namespace std;
int val[300001];
long long csum[300001], psum[300001];
vector<int> del;
vector<pair<int, int> > v;
int BS(int val, bool up) {
  int l = 0, m, h = (signed)v.size() - 1;
  while (l <= h) {
    m = (l + h) >> 1;
    if (val < v[m].first)
      h = m - 1;
    else if (val > v[m].first)
      l = m + 1;
    else {
      if (up)
        l = m + 1;
      else
        h = m - 1;
    }
  }
  if (up) {
    if (h + 1 < v.size() && v[h + 1].first == val) return h + 1;
    if (v[h].first == val) return h;
    return h - 1;
  }
  if (l - 1 >= 0 && v[l - 1].first == val) return l - 1;
  if (v[l].first == val) return l;
  return l + 1;
}
int main() {
  int n;
  cin >> n;
  v.reserve(300001);
  for (int i = 1; i <= n; ++i) {
    cin >> val[i];
    csum[i] = csum[i - 1] + val[i];
    psum[i] = psum[i - 1];
    if (val[i] >= 0) psum[i] += val[i];
    v.push_back(make_pair(val[i], i));
  }
  sort(v.begin(), v.end());
  long long best = -(1ll << 61);
  int A, B;
  for (int i = 1; i < n; ++i) {
    int a = BS(val[i], 0);
    if (v[a].second < i) continue;
    int b = BS(val[i], 1);
    if (a == b) continue;
    a = v[a].second;
    b = v[b].second;
    long long s = val[a] * 2 + psum[b - 1] - psum[a];
    if (s > best) {
      best = s;
      A = a;
      B = b;
    }
  }
  cout << best;
  for (int i = 1; i <= n; ++i)
    if (i < A || i > B || (i != A && i != B && val[i] < 0)) del.push_back(i);
  cout << " " << del.size() << endl;
  if (del.size()) cout << del[0];
  for (int i = 1; i < del.size(); ++i) cout << " " << del[i];
  return 0;
}
