Problem:
Score : 700 points

Problem Statement

You have an integer sequence of length N: a_1, a_2, ..., a_N.

You repeatedly perform the following operation until the length of the sequence becomes 1:

First, choose an element of the sequence.

If that element is at either end of the sequence, delete the element.

If that element is not at either end of the sequence, replace the element with the sum of the two elements that are adjacent to it. Then, delete those two elements.

You would like to maximize the final element that remains in the sequence.

Find the maximum possible value of the final element, and the way to achieve it.

Constraints

All input values are integers.

2 \leq N \leq 1000

|a_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

In the first line, print the maximum possible value of the final element in the sequence.

In the second line, print the number of operations that you perform.

In the (2+i)-th line, if the element chosen in the i-th operation is the x-th element from the left in the sequence at that moment, print x.

If there are multiple ways to achieve the maximum value of the final element, any of them may be printed.

Sample Input 1

5
1 4 3 7 5

Sample Output 1

11
3
1
4
2

The sequence would change as follows:

After the first operation: 4, 3, 7, 5

After the second operation: 4, 3, 7

After the third operation: 11(4+7)

Sample Input 2

4
100 100 -1 100

Sample Output 2

200
2
3
1

After the first operation: 100, 200(100+100)

After the second operation: 200

Sample Input 3

6
-1 -2 -3 1 2 3

Sample Output 3

4
3
2
1
2

After the first operation: -4, 1, 2, 3

After the second operation: 1, 2, 3

After the third operation: 4

Sample Input 4

9
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 4

5000000000
4
2
2
2
2

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 * 
 * @author daltao
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "daltao", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            BothSidesMerger solver = new BothSidesMerger();
            solver.solve(1, in, out);
            out.close();
        }
    }
    static class BothSidesMerger {
        int n;
        int[] a;
        long[][][] dp;
        long lInf = (long) 1e18;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            n = in.readInt();
            a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.readInt();
            }
            dp = new long[n][n][3];
            SequenceUtils.deepFill(dp, -1L);

            long ans = -lInf;
            int maxI = -1;
            int maxK = -1;
            for (int i = 0; i < n; i++) {
                for (int k = 0; k < 3; k++) {
                    if (dp(i, n - 1, k) > ans) {
                        ans = dp(i, n - 1, k);
                        maxI = i;
                        maxK = k;
                    }
                }
            }

            out.println(ans);
            int[] vals = new int[n];

            trace(vals, maxI, n - 1, maxK);

            IntList valDeque = new IntList();
            valDeque.addAll(vals, 0, n);
            IntList op = new IntList(n);

            while (valDeque.tail() == 0) {
                op.add(valDeque.size());
                valDeque.pop();
            }

            valDeque.pop();
            while (true) {
                while (valDeque.size() >= 2 && valDeque.get(valDeque.size() - 2) == 0) {
                    op.add(valDeque.size() - 1);
                    valDeque.pop();
                    valDeque.pop();
                }
                if (valDeque.size() >= 2 && valDeque.get(valDeque.size() - 2) == 1) {
                    op.add(valDeque.size());
                    valDeque.pop();
                    valDeque.pop();
                } else {
                    while (!valDeque.isEmpty()) {
                        valDeque.pop();
                        op.add(1);
                    }
                    break;
                }
            }

            out.println(op.size());
            for (int i = 0; i < op.size(); i++) {
                out.println(op.get(i));
            }
        }

        public void trace(int[] vals, int i, int j, int k) {
            if (j == i) {
                vals[j] = 1;
                return;
            }
            if (k == 2) {
                vals[j] = 1;
                trace(vals, i, j - 1, 1);
                return;
            }
            if (k == 1) {
                if (dp(i, j - 1, 0) == dp(i, j, k)) {
                    trace(vals, i, j - 1, 0);
                } else {
                    trace(vals, i, j - 1, 2);
                }
                return;
            }
            trace(vals, i, j - 1, 1);
        }

        public long dp(int i, int j, int k) {
            if (dp[i][j][k] == -1) {
                if (i == j) {
                    dp[i][j][k] = k == 2 ? a[i] : -lInf;
                    return dp[i][j][k];
                }
                if (k == 2) {
                    dp[i][j][k] = a[j] + dp(i, j - 1, 1);
                } else if (k == 1) {
                    dp[i][j][k] = Math.max(dp(i, j - 1, 0), dp(i, j - 1, 2));
                } else {
                    dp[i][j][k] = dp(i, j - 1, 1);
                }
            }
            return dp[i][j][k];
        }

    }
    static class SequenceUtils {
        public static void deepFill(Object array, long val) {
            if (!array.getClass().isArray()) {
                throw new IllegalArgumentException();
            }
            if (array instanceof long[]) {
                long[] longArray = (long[]) array;
                Arrays.fill(longArray, val);
            } else {
                Object[] objArray = (Object[]) array;
                for (Object obj : objArray) {
                    deepFill(obj, val);
                }
            }
        }

    }
    static class IntList {
        private int size;
        private int cap;
        private int[] data;
        private static final int[] EMPTY = new int[0];

        public IntList(int cap) {
            this.cap = cap;
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new int[cap];
            }
        }

        public IntList(IntList list) {
            this.size = list.size;
            this.cap = list.cap;
            this.data = Arrays.copyOf(list.data, size);
        }

        public IntList() {
            this(0);
        }

        private void ensureSpace(int need) {
            int req = size + need;
            if (req > cap) {
                while (cap < req) {
                    cap = Math.max(cap + 10, 2 * cap);
                }
                data = Arrays.copyOf(data, cap);
            }
        }

        private void checkRange(int i) {
            if (i < 0 || i >= size) {
                throw new ArrayIndexOutOfBoundsException();
            }
        }

        public int get(int i) {
            checkRange(i);
            return data[i];
        }

        public void add(int x) {
            ensureSpace(1);
            data[size++] = x;
        }

        public void addAll(int[] x, int offset, int len) {
            ensureSpace(len);
            System.arraycopy(x, offset, data, size, len);
            size += len;
        }

        public int tail() {
            checkRange(0);
            return data[size - 1];
        }

        public int pop() {
            return data[--size];
        }

        public int size() {
            return size;
        }

        public int[] toArray() {
            return Arrays.copyOf(data, size);
        }

        public boolean isEmpty() {
            return size == 0;
        }

        public String toString() {
            return Arrays.toString(toArray());
        }

    }
    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }
    static class FastOutput implements AutoCloseable, Closeable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput println(int c) {
            cache.append(c).append('\n');
            return this;
        }

        public FastOutput println(long c) {
            cache.append(c).append('\n');
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

    }
}