#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int arr[n];
  unordered_map<long long int, pair<long long int, long long int>> um;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    um[arr[i]] = {LLONG_MAX, LLONG_MIN};
  }
  for (long long int i = 0; i < n; i++) {
    um[arr[i]].first = min(um[arr[i]].first, i);
    um[arr[i]].second = max(um[arr[i]].second, i);
  }
  pair<long long int, long long int> ans1, ans2;
  ans1 = make_pair(LLONG_MIN, 0);
  ans2 = make_pair(0, 0);
  unordered_map<long long int, bool> uglymap;
  for (auto x : um) {
    long long int curr = 0, ugly = 0;
    unordered_map<long long int, bool> um;
    for (int i = x.second.first; i <= x.second.second; i++) {
      if (i > x.second.first && i < x.second.second) {
        if (arr[i] < 0)
          ugly++, um[i] = true;
        else if (arr[i] >= 0)
          curr += arr[i];
      } else if (i == x.second.first || i == x.second.second)
        curr += arr[i];
    }
    if (curr > ans1.first) {
      if (x.second.second - x.second.first + 1 >= 2) {
        uglymap = um;
        ans1.first = curr;
        ans1.second = n - (x.second.second - x.second.first + 1 - ugly);
        ans2.first = x.second.first;
        ans2.second = x.second.second;
      }
    }
  }
  cout << ans1.first << " " << ans1.second << endl;
  for (int i = 0; i < n; i++) {
    if ((i >= ans2.first && i <= ans2.second)) {
      if (uglymap[i])
        cout << i + 1 << " ";
      else if (!uglymap[i])
        continue;
    } else
      cout << i + 1 << " ";
  }
  return 0;
}
