#include <bits/stdc++.h>
using namespace std;
int a[300010], b[300010], n;
long long sum[300010], t, ans = -2e18, cnt = 0, l, r;
map<int, int> mp;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    mp[a[i]] = i;
    sum[i] = max(sum[i - 1], sum[i - 1] + a[i]);
  }
  for (int i = 1; i <= n; i++)
    if (i < mp[a[i]]) {
      t = sum[mp[a[i]] - 1] - sum[i] + a[i] + a[mp[a[i]]];
      if (t > ans) ans = t, l = i, r = mp[a[i]];
    }
  for (int i = 1; i <= n; i++) {
    if (i < l || i > r) cnt++, b[i] = 1;
    if (i > l && i < r && a[i] < 0) cnt++, b[i] = 1;
  }
  printf("%lld %d\n", ans, cnt);
  for (int i = 1; i <= n; i++)
    if (b[i]) printf("%d ", i);
  return 0;
}
