#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)3e5 + 20;
long long dp[MAX_N];
long long S[MAX_N];
int mark[MAX_N];
int a[MAX_N];
map<int, int> D;
pair<int, int> Q[MAX_N];
long long ans = (long long)-1e15;
vector<int> del;
int n, head = 1, num;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i(1); i < int(n + 1); i++) {
    int x;
    cin >> x;
    a[i] = x;
    if (D[x] == 0) {
      D[x] = head++;
      Q[D[x]].first = i;
    } else {
      Q[D[x]].second = i;
      mark[D[x]] = 1;
    }
  }
  for (int i(1); i < int(n + 1); i++) {
    S[i] = max(S[i - 1], S[i - 1] + a[i]);
    dp[i] = S[i - 1];
  }
  for (int i(1); i < int(n + 1); i++) {
    if (mark[D[a[i]]]) {
      int cor1 = Q[D[a[i]]].first, cor2 = Q[D[a[i]]].second;
      long long ret = (a[i] > 0 ? a[i] : 2 * a[i]) + (dp[cor2] - dp[cor1]);
      if (ans < ret) {
        ans = ret;
        num = i;
      }
    }
  }
  int cor1 = Q[D[a[num]]].first, cor2 = Q[D[a[num]]].second;
  for (int i(1); i < int(cor1); i++) del.push_back(i);
  for (int i(cor1 + 1); i < int(cor2); i++)
    if (a[i] < 0) del.push_back(i);
  for (int i(cor2 + 1); i < int(n + 1); i++) del.push_back(i);
  cout << ans << ' ' << del.size() << endl;
  for (int i(0); i < int(del.size()); i++) cout << del[i] << ' ';
  cout << endl;
  return 0;
}
