#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 10;
long long a[N];
long long sum[N];
int last[N];
map<long long, int> Map;
map<long long, int> L;
map<long long, int> B;
int main() {
  srand(time(0));
  int n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%I64d", &a[i]);
    L[a[i]] = i;
    Map[a[i]]++;
    if (Map[a[i]] == 1) B[a[i]] = i;
  }
  sum[0] = 0;
  for (i = 1; i <= n; ++i) sum[i] = sum[i - 1] + (a[i] >= 0 ? a[i] : 0);
  long long ans = -0x1f1f1f1f1f1f1f1fLL;
  pair<int, int> mark;
  for (map<long long, int>::iterator e = Map.begin(); e != Map.end(); ++e)
    if (e->second >= 2) {
      long long tmp =
          sum[L[e->first] - 1] - sum[B[e->first]] + 2 * a[L[e->first]];
      if (tmp > ans) {
        ans = tmp;
        mark = make_pair(B[e->first], L[e->first]);
      }
    }
  int cnt = 2;
  for (i = mark.first + 1; i < mark.second; ++i)
    if (a[i] >= 0) cnt++;
  printf("%I64d %d\n", ans, n - cnt);
  for (i = 1; i < mark.first; ++i) printf("%d ", i);
  for (i = mark.first + 1; i < mark.second; ++i)
    if (a[i] < 0) printf("%d ", i);
  for (i = mark.second + 1; i <= n; ++i) printf("%d ", i);
  puts("");
  return 0;
}
