#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
int n;
int arr[maxn];
long long sumPositive[maxn];
map<int, int> larr, rarr;
int main() {
  memset(sumPositive, 0, sizeof sumPositive);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  sumPositive[0] = 0;
  larr.clear();
  rarr.clear();
  for (int i = 1; i <= n; i++) {
    rarr[arr[i]] = i;
  }
  for (int i = n; i >= 1; i--) {
    larr[arr[i]] = i;
  }
  for (int i = 1; i <= n; i++)
    sumPositive[i] = sumPositive[i - 1] + max(0, arr[i]);
  long long ans = 0;
  int ans2 = -1;
  for (map<int, int>::iterator it = larr.begin(); it != larr.end(); it++) {
    if (rarr.count(it->first) == 0) continue;
    if (rarr[it->first] == it->second) continue;
    long long tmp = sumPositive[rarr[it->first] - 1] - sumPositive[it->second] +
                    2ll * it->first;
    if (ans2 == -1 || tmp > ans) {
      ans2 = it->second;
      ans = tmp;
    }
  }
  ans2 = arr[ans2];
  vector<int> ansArr;
  int l = larr[ans2], r = rarr[ans2];
  for (int i = 1; i < l; i++) ansArr.push_back(i);
  for (int i = l + 1; i < r; i++)
    if (arr[i] < 0) ansArr.push_back(i);
  for (int i = r + 1; i <= n; i++) ansArr.push_back(i);
  cout << ans << " " << ansArr.size() << endl;
  for (int i = 0; i < ansArr.size(); i++) cout << ansArr[i] << " ";
  cout << endl;
}
