#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300010;
const long long INF = 1e15;
int n, a[MAXN];
long long pre[MAXN];
map<int, int> fst, lst;
int best1, best2;
long long best = -INF;
int arr[MAXN], cnt;
int main() {
  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    if (a[i] > 0)
      pre[i + 1] = pre[i] + a[i];
    else
      pre[i + 1] = pre[i];
    if (!fst.count(a[i])) fst[a[i]] = i;
    lst[a[i]] = i;
  }
  for (typeof(fst.begin()) it = fst.begin(), _it = (fst.end()); it != _it;
       it++) {
    if (lst[it->first] == it->second) continue;
    long long res = a[it->second] + a[lst[it->first]] + pre[lst[it->first]] -
                    pre[it->second + 1];
    if (res > best) {
      best = res;
      best1 = it->second;
      best2 = lst[it->first];
    }
  }
  for (int i = 0; i < best1; i++) arr[cnt++] = i;
  for (int i = best2 + 1; i < n; i++) arr[cnt++] = i;
  for (int i = best1 + 1; i < best2; i++) {
    if (a[i] < 0) arr[cnt++] = i;
  }
  printf("%I64d %d\n", best, cnt);
  for (int i = 0; i < cnt; i++) printf("%d ", arr[i] + 1);
}
