#include <bits/stdc++.h>
using namespace std;
long long n, c[1000000], p[1000000], rem[1000000], ans = -1e10, a, b, ansa,
                                                   ansb, now, cnt, add;
map<long long, int> mp;
map<long long, int>::iterator it;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    add = 0;
    if (c[i] > 0)
      p[i + 1] = p[i] + c[i];
    else
      p[i + 1] = p[i];
    it = mp.find(c[i]);
    if (it == mp.end())
      mp[c[i]] = now, rem[now] = i, now++;
    else {
      a = rem[(*it).second];
      b = i;
      if (c[i] < 0) add = 2 * c[i];
      if (p[b + 1] - p[a] + add > ans) {
        ans = p[b + 1] - p[a] + add;
        ansa = a;
        ansb = b;
      }
    }
  }
  for (int i = 0; i < n; i++)
    if (i < ansa || i > ansb || (c[i] < 0 && i != ansa && i != ansb)) cnt++;
  cout << ans << ' ' << cnt << endl;
  for (int i = 0; i < n; i++)
    if (i < ansa || i > ansb || (c[i] < 0 && i != ansa && i != ansb))
      cout << i + 1 << ' ';
  return 0;
}
