#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3 * 100000 + 10;
long long n, a[maxn], MIN = -1000000000LL * maxn, MAX = -1000000000LL * maxn,
                      sum[maxn], ted[maxn], t, MAX1 = -1000000000LL * maxn, t1;
pair<long long, long long> ind, ind1;
bool sw = false;
map<long long, long long> mp;
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (mp[a[i]] == 0)
      mp[a[i]] = i;
    else if (a[i] >= 0)
      sw = true;
    sum[i] = sum[i - 1];
    ted[i] = ted[i - 1];
    if (a[i] >= 0) {
      ted[i]++;
      sum[i] += a[i];
    }
  }
  if (sw) {
    for (long long i = 1; i <= n; i++) {
      if (a[i] < 0) continue;
      long long j = mp[a[i]];
      if (j == i) continue;
      long long d = sum[i] - sum[j] + a[j];
      if (d > MAX) {
        t = ted[i] - ted[j] + 1;
        MAX = d;
        ind = pair<long long, long long>(j, i);
      }
    }
    MAX1 = MAX;
  }
  for (long long i = 1; i <= n; i++) {
    if (a[i] >= 0) continue;
    int d = mp[a[i]];
    if (d != i && sum[i] - sum[d] + a[i] + a[d] > MIN) {
      MIN = sum[i] - sum[d] + a[i] + a[d];
      t1 = ted[i] - ted[d] + 2;
      ind1 = pair<long long, long long>(d, i);
    }
  }
  if (MIN > MAX1) {
    cout << MIN << ' ' << n - t1 << endl;
    for (long long i = 1; i < ind1.first; i++) cout << i << ' ';
    for (long long i = ind1.first + 1; i < ind1.second; i++)
      if (a[i] < 0) cout << i << ' ';
    for (long long i = ind1.second + 1; i <= n; i++) cout << i << ' ';
    cout << endl;
    return 0;
  } else {
    cout << MAX1 << ' ' << n - t << endl;
    for (long long i = 1; i < ind.first; i++) cout << i << ' ';
    for (long long i = ind.first + 1; i < ind.second; i++)
      if (a[i] < 0) cout << i << ' ';
    for (long long i = ind.second + 1; i <= n; i++) cout << i << ' ';
    cout << endl;
    return 0;
  }
}
