#include <bits/stdc++.h>
using namespace std;
const long long A = 10000000000000000LL, N = 300228;
vector<long long> k;
map<int, long long> b[3];
long long o[3] = {-A, -1, -1}, ot, l, r, i, j, n, m, d[N], a[N];
long long get(long long l, long long r) { return d[r] - d[l - 1]; }
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (i = 1; i <= n; i++) b[0][a[i]] = A, b[1][a[i]] = -A;
  for (i = 1; i <= n; i++)
    b[0][a[i]] = min(b[0][a[i]], i), b[1][a[i]] = max(b[1][a[i]], i);
  for (i = 1; i <= n; i++)
    if (a[i] < 0)
      d[i] = d[i - 1];
    else
      d[i] = d[i - 1] + a[i];
  for (i = 1; i <= n; i++)
    if (!b[2][a[i]]) {
      b[2][a[i]] = 1, l = b[0][a[i]], r = b[1][a[i]];
      if (l == r) continue;
      ot = a[i] * 2 + get(l + 1, r - 1);
      if (ot > o[0]) o[0] = ot, o[1] = l, o[2] = r;
    }
  for (i = 1; i < o[1]; i++) k.push_back(i);
  for (i = o[2] + 1; i <= n; i++) k.push_back(i);
  for (i = o[1] + 1; i < o[2]; i++)
    if (a[i] < 1) k.push_back(i);
  cout << o[0] << " " << k.size() << "\n";
  for (i = 0; i < k.size(); i++) cout << k[i] << " ";
}
