#include <bits/stdc++.h>
const long double eps = 1e-9;
using namespace std;
template <class T>
inline T MAX(const T &_a, const T &_b) {
  return ((_a > _b) ? _a : _b);
}
template <class T>
inline T MIN(const T &_a, const T &_b) {
  return ((_a < _b) ? _a : _b);
}
template <class T>
inline T MAX3(const T &_a, const T &_b, const T &_c) {
  return MAX(MAX(_a, _b), _c);
}
template <class T>
inline T MIN3(const T &_a, const T &_b, const T &_c) {
  return MIN(MIN(_a, _b), _c);
}
template <class T>
inline T MAX4(const T &_a, const T &_b, const T &_c, const T &_d) {
  return MAX(MAX3(_a, _b, _c), _d);
}
template <class T>
inline T MIN4(const T &_a, const T &_b, const T &_c, const T &_d) {
  return MIN(MIN3(_a, _b, _c), _d);
}
template <class T>
inline T ABS(const T &_a) {
  return ((_a < 0) ? -_a : _a);
}
template <class T>
inline T gcd(T _a, T _b) {
  for (T _r; (_r = _a % _b); _b = _r) _a = _b;
  return _b;
}
template <class T>
inline T lcm(const T &_a, const T &_b) {
  return (_a / gcd(_a, _b)) * _b;
}
template <class T>
inline bool BETW(const T &_a, const T &_b, const T &_c) {
  return (_a >= MIN(_b, _c) && _a <= MAX(_b, _c));
}
template <class T>
inline bool EXT(const T &_a, const T &_b, const T &_c) {
  return !BETW(_a, _b, _c);
}
const int MAXN = 300010;
int n, a[MAXN], ktmp, k, k1;
long long sum[MAXN], vtmp = LLONG_MIN, v;
map<int, pair<int, int> > m;
map<int, pair<int, int> >::iterator it;
vector<int> ans;
inline long long s(int i, int j) {
  return ((i) ? sum[j] - sum[i - 1] : sum[j]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (m.find(a[i]) == m.end())
      m[a[i]] = make_pair(i, i);
    else
      m[a[i]].second = i;
  }
  if (a[0] > 0) sum[0] = a[0];
  for (int i = 1; i < n; ++i) sum[i] = sum[i - 1] + ((a[i] > 0) ? a[i] : 0);
  for (it = m.begin(); it != m.end(); ++it) {
    if (it->second.first == it->second.second) continue;
    v = s(it->second.first, it->second.second) +
        ((it->first < 0) ? (it->first * 2) : 0);
    if (v > vtmp) {
      vtmp = v;
      ktmp = it->first;
    }
  }
  k = m[ktmp].first;
  k1 = m[ktmp].second;
  for (int i = 0; i < k; ++i) ans.push_back(i + 1);
  for (int i = k + 1; i < k1; ++i)
    if (a[i] < 0) ans.push_back(i + 1);
  for (int i = k1 + 1; i < n; ++i) ans.push_back(i + 1);
  cout << vtmp << " " << ((int)ans.size()) << endl;
  for (int i = 0; i < ((int)ans.size()) - 1; ++i) cout << ans[i] << " ";
  if (((int)ans.size())) cout << ans.back();
  return 0;
}
