#include using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() typedef long long ll; typedef pair P; typedef vector V; typedef vector> VV; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int N; cin >> N; V v(N + 1, 0); rep(i, N) cin >> v[i + 1]; V dp(N + 1, 0); V prev(N + 1, -1); dp[1] = v[1]; prev[1] = 0; rep2(i, 2, N + 1) { if (dp[i - 1] > dp[i]) { dp[i] = dp[i - 1]; prev[i] = i - 1; } if (dp[i - 2] + v[i] > dp[i]) { dp[i] = dp[i - 2] + v[i]; prev[i] = i - 2; } } cout << dp[N] << endl; V ans; for (int i = N; i > 0; i = prev[i]) { if (dp[i] > dp[prev[i]]) { ans.emplace_back(i); } } reverse(all(ans)); rep(i, ans.size()) { cout << ans[i] << (i != ans.size() - 1 ? " " : ""); } cout << endl; }