#include using namespace std; int dp[1001]; int history[1001]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, t;; vector v; cin >> n; for (int i = 0; i < n; i++) { cin >> t; v.push_back(t); } memset(history, -1, sizeof(history)); dp[0] = v[0]; dp[1] = v[1]; for (int i = 2; i < n; i++) { dp[i] = v[i]; for (int j = i - 2; j >= 0; j--) { if (dp[i] < dp[j] + v[i]) { dp[i] = dp[j] + v[i]; history[i] = j; } } } int MAX = 0; int now = n; for (int i = n - 1; i >= 0; i--) { if (MAX < dp[i]) { MAX = dp[i]; now = i; } } cout << MAX << '\n'; stack stk; while (1) { if (now == -1) { break; } stk.push(now); now = history[now]; } while (!stk.empty()) { cout << stk.top() + 1 << ' '; stk.pop(); } cout << '\n'; return 0; }