#include <bits/stdc++.h>
using namespace std;
const long long maxN = 3e5 + 12;
const long long INF = 2e9 + 12;
long long n, a[maxN], dp[maxN];
map<long long, long long> f, s, mrk;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long x = 0, mx = -INF;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i] = dp[i - 1] + max((long long)0, a[i]);
    mrk[a[i]]++;
    if (mrk[a[i]] == 1)
      f[a[i]] = i;
    else {
      s[a[i]] = i;
      if (mx <= dp[i - 1] - dp[f[a[i]]] + 2 * a[i]) {
        mx = dp[i - 1] - dp[f[a[i]]] + 2 * a[i];
        x = a[i];
      }
    }
  }
  cout << mx << ' ';
  vector<long long> v;
  for (long long i = 1; i <= n; i++) {
    long long y = f[x];
    long long z = s[x];
    if ((a[i] < 0 && i != y && i != z) || i < y || i > z) v.push_back(i);
  }
  cout << v.size() << '\n';
  for (long long i = 0; i < v.size(); i++) cout << v[i] << ' ';
}
