#include <bits/stdc++.h>
using namespace std;
const int maxn = 300007;
const long long maxnum = 10000000000000000ll;
int n;
int a[maxn];
long long sum[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1];
    if (a[i] > 0) sum[i] += a[i];
  }
  map<int, int> R;
  for (int i = 1; i <= n; i++) R[a[i]] = i;
  long long res = -maxnum;
  int l, r;
  for (int i = 1; i <= n; i++) {
    if (R[a[i]] == i) continue;
    int j = R[a[i]];
    if (sum[j - 1] - sum[i] + a[i] + a[j] > res) {
      res = sum[j - 1] - sum[i] + a[i] + a[j];
      l = i, r = j;
    }
  }
  vector<int> ans;
  for (int i = 1; i < l; i++) ans.push_back(i);
  for (int i = r + 1; i <= n; i++) ans.push_back(i);
  for (int i = l + 1; i <= r - 1; i++)
    if (a[i] < 0) ans.push_back(i);
  sort(ans.begin(), ans.end());
  cout << res << " " << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    if (i + 1 < ans.size())
      printf("%d ", ans[i]);
    else
      printf("%d\n", ans[i]);
  return 0;
}
