#include <bits/stdc++.h>
using namespace std;
int d4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
template <typename T>
void lmax(T& a, const T& b) {
  if (a < b) a = b;
}
template <typename T>
void lmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <typename T>
void usort(vector<T>& a) {
  sort((a).begin(), (a).end());
  a.erase(unique((a).begin(), (a).end()), a.end());
}
template <typename T>
void operator+=(vector<T>& v, const T& x) {
  v.push_back(x);
}
string str(int i) {
  char s[16];
  sprintf(s, "%d", i);
  return s;
}
const int INF = 2000000000;
int a[300000];
map<int, int> counter;
map<int, int> lmost, rmost;
long long sum[300000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) {
    scanf("%d", a + i);
    if (++counter[a[i]] >= 2) {
      rmost[a[i]] = i;
    } else {
      lmost[a[i]] = i;
      rmost[a[i]] = i;
    }
  }
  sum[0] = max(a[0], 0);
  for (int i = 1; i < n; ++i) {
    sum[i] = sum[i - 1] + max(0, a[i]);
  }
  long long max_ans = -INF - 1;
  int ans_pos = -1;
  for (auto& p : counter) {
    if (p.second >= 2) {
      int l = lmost[p.first];
      int r = rmost[p.first];
      ;
      ;
      long long s = sum[r - 1] - sum[l] + p.first * 2;
      ;
      if (s > max_ans) {
        max_ans = s;
        ans_pos = p.first;
      }
    }
  }
  int l = lmost[ans_pos];
  int r = rmost[ans_pos];
  vector<int> ans;
  long long s = ans_pos * 2;
  for (int i = 0; i < n; ++i) {
    if (i == l or i == r) continue;
    if (i > l and i < r and a[i] >= 0) {
      s += a[i];
    } else {
      ans += i + 1;
    }
  }
  cout << s << ' ' << ans.size() << '\n';
  for (int x : ans) {
    cout << x << ' ';
  }
  return 0;
}
