#include <bits/stdc++.h>
using namespace std;
const long long negInf = -1000000000000000000;
int main() {
  int n;
  scanf("%d", &n);
  int arr[300005];
  vector<long long> acc(300005, (long long)0);
  map<long long, pair<int, int>> mp;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &arr[i]);
    acc[i] = acc[i - 1] + (arr[i] > 0 ? (long long)arr[i] : 0);
    long long aa = acc[i], bb = arr[i];
    if (mp.find(arr[i]) == mp.end()) {
      mp[arr[i]] = make_pair(i, i);
    } else {
      int q = mp[arr[i]].first;
      mp[arr[i]] = make_pair(q, i);
    }
  }
  long long ans = negInf;
  int p1, p2;
  for (auto e : mp) {
    if (ans < acc[e.second.second - 1] - acc[e.second.first] + 2 * e.first &&
        e.second.second != e.second.first) {
      p1 = e.second.first, p2 = e.second.second;
      ans = acc[p2 - 1] - acc[p1] + 2 * e.first;
    }
  }
  vector<long long> sol;
  for (int i = 1; i <= n; i++) {
    if (i < p1 || i > p2 || (i > p1 && i < p2 && arr[i] < 0)) sol.push_back(i);
  }
  printf("%I64d %d\n", ans, sol.size());
  for (auto e : sol) printf("%I64d ", e);
  return 0;
}
