#include <bits/stdc++.h>
using namespace std;
const int Maxn = 300005, Maxm = 100005, Mo = 1000000007,
          sp[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const long long oo = LONG_LONG_MAX >> 2;
struct Tree {
  int x, y;
};
struct edge {
  int v, c, w, Ft;
};
typedef int IArr[Maxn];
typedef long long LArr[Maxn];
typedef double DArr[Maxn];
int i, j, n, ansl, ansr;
long long ans;
LArr a, s;
map<long long, int> Max, Min;
void up(long long s, int al, int ar) {
  ans = s;
  ansl = al;
  ansr = ar;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) s[i] = s[i - 1] + (a[i] > 0 ? a[i] : 0);
  for (i = 1; i <= n; i++) Max[a[i]] = i;
  for (i = n; i >= 1; i--) Min[a[i]] = i;
  ans = -oo;
  for (i = 1; i <= n; i++) {
    int l = Min[a[i]], r = Max[a[i]];
    if (!l || !r) continue;
    if (l + 1 == r && ans < a[i] * 2)
      up(a[i] * 2, l, r);
    else if (l < r && s[r - 1] - s[l] + a[i] * 2 > ans)
      up(s[r - 1] - s[l] + a[i] * 2, l, r);
  }
  int num = 0;
  int l = ansl, r = ansr;
  for (i = l + 1; i < r; i++)
    if (a[i] < 0) num++;
  cout << ans << ' ' << l - 1 + (n - r) + num << endl;
  for (i = 1; i < l; i++) cout << i << ' ';
  for (i = l + 1; i < r; i++)
    if (a[i] < 0) cout << i << " ";
  for (i = r + 1; i <= n; i++) cout << i << ' ';
}
