#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
const long double EPSILON = 0.00001;
const long long int mod = 1e9 + 7;
const long long int AM = 2e5 + 5;
const long double pi = 3.14159265358979323846;
long long int max(long long int a, long long int b) {
  if (a > b)
    return a;
  else
    return b;
}
using namespace std;
long long int factorial(long long int n) {
  long long int ans = 1;
  for (long long int i = 1; i <= n; i++) ans *= i;
  return ans;
}
long long int powm(long long int a, long long int b, long long int n) {
  long long int x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y) % n;
    }
    y = (y * y) % n;
    b /= 2;
  }
  return x % n;
}
long long int pow(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = ((res) * (x));
    y = y >> 1;
    x = ((x) * (x));
  }
  return res;
}
long long int min(long long int a, long long int b) {
  if (a > b)
    return b;
  else
    return a;
}
bool cmp(long double x, long double y) {
  if (abs(x - y) <= EPSILON) return 1;
  return 0;
}
bool checkprime(long long int n) {
  for (long long int i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
long long int modInverse(long long int a, long long int m) {
  long long int g = gcd(a, m);
  return powm(a, m - 2, m);
}
int main() {
  int n;
  cin >> n;
  vector<long long int> vec(n);
  map<long long int, int> maap;
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    maap[vec[i]] = i;
  }
  vector<long long int> pre(n);
  pre[0] = max(0, vec[0]);
  for (int i = 1; i < n; i++) {
    pre[i] = max(0, vec[i]) + pre[i - 1];
  }
  long long int ans = LLONG_MIN;
  int l1, r1, l2, r2, l3, r3;
  for (int i = 0; i < n; i++) {
    if (maap[vec[i]] != i) {
      long long int tmp = 2 * vec[i] + pre[maap[vec[i]] - 1] - pre[i];
      if (tmp > ans) {
        ans = tmp;
        l1 = 0;
        r1 = i - 1;
        l2 = i + 1;
        r2 = maap[vec[i]] - 1;
        ;
        l3 = maap[vec[i]] + 1;
        r3 = n - 1;
      }
    }
  }
  vector<int> cut;
  for (int i = l1; i <= r1; i++) cut.push_back(i);
  for (int i = l2; i <= r2; i++)
    if (vec[i] < 0) cut.push_back(i);
  for (int i = l3; i <= r3; i++) cut.push_back(i);
  cout << ans << " " << cut.size() << "\n";
  for (auto it : cut) cout << it + 1 << " ";
  cout << "\n";
  return 0;
}
