#include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) using namespace std; typedef long long int lli; lli MOD = 1000000007; lli dp[1005] = {}; int n; lli v[1005] = {}; vector ans; int search(int x, int V) //x以下からvを探す. { if (V == 0 || x < 0) return 0; if (dp[x] == V) { ans.push_back(x); if (dp[x] - v[x] != 0) { return search(x - 2, dp[x] - v[x]); } } else { return search(x - 1, V); } } int main() { cin >> n; rep(i, n) cin >> v[i]; lli a = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < i - 1; j++) { dp[i] = max(dp[j] + v[i], dp[i]); } dp[i] = max(v[i], dp[i]); a = max(dp[i], a); } rrep(i, n) { if (a == dp[i]) { ans.push_back(i); search(i - 2, dp[i] - v[i]); break; } } cout << a << endl; sort(ans.begin(), ans.end()); rep(i, ans.size()) cout << ans[i] + 1 << ' '; cout << endl; }