#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  unordered_map<long long, set<long long>> idx;
  long long total_pos = 0;
  vector<long long> s(n + 1, 0);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > 0) total_pos += a[i];
    idx[a[i]].insert(i);
  }
  for (long long i = 1; i <= n; i++) {
    s[i] = s[i - 1];
    if (a[i - 1] > 0) s[i] = s[i - 1] + a[i - 1];
  }
  long long ans = INT_MIN;
  long long pref_sum = 0;
  long long f_idx = 0;
  long long s_idx = 0;
  for (long long i = 0; i < n; i++) {
    long long last = *idx[a[i]].rbegin();
    if (last != i) {
      long long cur_sum = total_pos - pref_sum - (s[n] - s[last + 1]);
      if (a[i] < 0) {
        cur_sum += 2 * a[i];
      }
      if (cur_sum > ans) {
        ans = max(ans, cur_sum);
        f_idx = i;
        s_idx = last;
      }
    }
    if (a[i] > 0) {
      pref_sum += a[i];
    }
  }
  vector<long long> rem;
  for (long long i = 0; i < n; i++) {
    if (i < f_idx || i > s_idx) {
      rem.push_back(i + 1);
    } else if (i != f_idx && i != s_idx && a[i] < 0) {
      rem.push_back(i + 1);
    }
  }
  cout << ans << " " << rem.size() << endl;
  for (long long i = 0; i < rem.size(); i++) {
    cout << rem[i] << " ";
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
