#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& o, pair<A, B>& p) {
  return o << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "{";
  for (typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
    o << *it << ", ";
  return o << "}";
}
struct debugger {
  ostream& out;
  bool first;
  void start() { first = true; }
  debugger(ostream& out) : out(out) { start(); }
  void nl() {
    out << endl;
    start();
  }
  template <class T>
  debugger& operator,(T& v) {
    if (first)
      first = false;
    else
      out << ", ";
    out << v;
    return *this;
  }
  template <class T>
  debugger& operator,(pair<T*, int> arr) {
    out << "{";
    for (typeof((arr.second) - 1) i = (0); i <= ((arr.second) - 1); i++) {
      out << arr.first[i] << ", ";
    }
    out << "}";
    return *this;
  }
} dbg(cerr);
long long a[3000100], sum[3001000];
int main() {
  int n;
  cin >> n;
  sum[0] = 0;
  map<long long, long long> mp1;
  map<long long, long long> mp2;
  for (typeof(n) i = (1); i <= (n); i++) {
    cin >> a[i];
    mp1[a[i]] = i;
    if (mp2[a[i]] == 0) {
      mp2[a[i]] = i;
    }
    if (a[i] > 0) {
      sum[i] = a[i] + sum[i - 1];
    } else {
      sum[i] = sum[i - 1];
    }
  }
  long long mx = -100000000000000000LL;
  int s, e;
  for (typeof((mp1).begin()) it = (mp1).begin(); it != (mp1).end(); it++) {
    if ((*it).second != 0 && mp2[(*it).first] != (*it).second) {
      if ((*it).first * 2 + sum[mp1[(*it).first] - 1] - sum[mp2[(*it).first]] >
          mx) {
        mx =
            (*it).first * 2 + sum[mp1[(*it).first] - 1] - sum[mp2[(*it).first]];
        s = mp2[(*it).first];
        e = mp1[(*it).first];
      }
    }
  }
  cout << mx << endl;
  vector<int> v;
  for (typeof(n) i = (1); i <= (n); i++) {
    if (((s + 1) <= (i) && (i) <= (e - 1))) {
      if (a[i] < 0) {
        v.push_back(i);
      }
    } else if (i < s) {
      v.push_back(i);
    } else if (i > e) {
      v.push_back(i);
    }
  }
  cout << (int)v.size() << endl;
  for (typeof(((int)v.size()) - 1) i = (0); i <= (((int)v.size()) - 1); i++) {
    cout << v[i] << endl;
  }
  return 0;
}
