# !/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% N, *V = map(int, read().split()) # %% dp = [0] * (N + 10) prev = [-1] * (N + 10) for i, x in enumerate(V): dp[i] = x for j in [i - 2, i - 3]: if j < 0: continue if dp[i] < dp[j] + x: dp[i] = dp[j] + x prev[i] = j # %% v = N - 1 if dp[N - 1] > dp[N - 2] else N - 2 path = [] while v != -1: path.append(v) v = prev[v] # %% answers = (x + 1 for x in reversed(path)) print(max(dp[N - 1], dp[N - 2])) print(' '.join(map(str, answers)))