#include <bits/stdc++.h>
using namespace std;
using namespace rel_ops;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int inf = 0x7FFFFFFF;
template <class T>
inline bool checkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
inline bool checkmax(T &a, T b) {
  return b > a ? a = b, 1 : 0;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const int N = 3e5 + 10;
int a[N];
long long sum[N];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      scanf("%d", a + i + 1);
      sum[i + 1] = sum[i];
      if (a[i + 1] > 0) sum[i + 1] += a[i + 1];
    }
    map<int, int> mp;
    for (int i = 1; i <= n; i++) {
      if (!mp.count(a[i])) mp[a[i]] = i;
    }
    long long ans = -(1ll << 62);
    int l, r;
    for (int i = n; i >= 1; i--) {
      int j = mp[a[i]];
      if (j != i) {
        long long tmp = sum[i - 1] - sum[j] + a[i] * 2;
        if (checkmax(ans, tmp)) {
          l = j, r = i;
        }
      }
    }
    vector<int> del;
    for (int i = 1; i < l; i++) del.push_back(i);
    for (int i = l + 1; i < r; i++)
      if (a[i] < 0) del.push_back(i);
    for (int i = r + 1; i <= n; i++) del.push_back(i);
    cout << ans << ' ' << del.size() << endl;
    for (int i = 0; i < del.size(); i++) printf("%d ", del[i]);
    puts("");
  }
  return 0;
}
