#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const long long INF = 1e18;   const long double EPS = 1e-12;   int a[300005];   map<int, int> mi;   int l_, r_;   long long pre[300005];   int b[300005];   int main() {     int n;     scanf( %d , &n);     for (int i = (int)1; i < (int)n + 1; i++) {       scanf( %d , &a[i]);     }     for (int i = (int)1; i < (int)n + 1; i++) {       if (mi[a[i]] == 0) mi[a[i]] = i;     }     for (int i = (int)1; i < (int)n + 1; i++) {       pre[i] = pre[i - 1];       if (a[i] >= 0) pre[i] += (long long)(a[i]);     }     long long ans = -(long long)(1e12);     l_ = 0;     r_ = 0;     for (int i = n; i >= 1; i--) {       int x = a[i];       int l = mi[x];       if (i == mi[x]) continue;       long long net = pre[i - 1] - pre[l];       net += 2LL * (long long)(x);       if (net > ans) {         ans = net;         l_ = l;         r_ = i;       }     }     int cnt = 0;     for (int i = 0; i < (int)n + 1; i++) b[i] = 0;     for (int i = (int)1; i < (int)n + 1; i++) {       if (i == l_ || i == r_) {         b[i] = 1;         continue;       }       if (l_ < i && i < r_ && a[i] > 0) {         b[i] = 1;       } else {         b[i] = 0;         cnt++;       }     }     cout << ans <<     << cnt << endl;     for (int i = (int)1; i < (int)n + 1; i++) {       if (b[i] == 0) {         printf( %d  , i);       }     }     cout << endl;     return 0;   }   