#include <bits/stdc++.h>
using namespace std;
const long long mod7 = 1000000007;
const long long mod9 = 1000000009;
int main() {
  int n;
  cin >> n;
  vector<long long> A(n + 1);
  vector<long long> S(n + 1);
  map<long long, vector<int> > B;
  for (int i = 1; i <= n; ++i) {
    cin >> A[i];
    S[i] = S[i - 1];
    if (A[i] >= 0) S[i] += A[i];
    B[A[i]].push_back(i);
  }
  long long ans = -100000000000000ll;
  int ga, gb;
  for (auto it = B.begin(); it != B.end(); ++it) {
    if (it->second.size() < 2) continue;
    long long temp = it->first * 2;
    int a = it->second[0];
    int b = it->second.back();
    temp += S[b - 1] - S[a];
    if (temp > ans) {
      ans = temp;
      ga = a;
      gb = b;
    }
  }
  cout << ans;
  vector<int> erased;
  for (int i = 1; i <= n; ++i) {
    if (i < ga || i > gb || (i > ga && i < gb && A[i] < 0)) erased.push_back(i);
  }
  cout << ' ' << erased.size() << endl;
  for (int i = 0; i < erased.size(); ++i) cout << erased[i] << ' ';
  return 0;
}
