import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class fish_sm {
	int n;
	int[] a;

	void solve() {
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = nextInt();
		}

		out.println(solve(a));
		// System.err.println("counter = " + counter);
	}

	int solve(int[] a) {
		this.n = a.length;
		this.a = a;
		u = 0;
		pos = 0;
		tm = new HashMap<State, Integer>();
		ppos = new int[2][2];
		int res = init(0, 0);
		// System.out.println(res);
		return res;
	}

	int u;

	boolean getU(int x) {
		return (u & (1 << x)) > 0;
	}

	void setU(int x, boolean state) {
		if (state) {
			u |= 1 << x;
		} else {
			u &= ~(1 << x);
		}
	}

	int pos;
	int[][] ppos;

	int getPos(int i, int j) {
		int x = 2 * i + j;
		int res = (pos >> (8 * x)) & 0xFF;
		// if (res != ppos[i][j]) {
		// throw new AssertionError();
		// }
		return res;
	}

	void setPos(int i, int j, int value) {
		// System.err.println("set " + i + " " + j + " = " + value );
		int x = 2 * i + j;
		pos &= ~(0xFF << (x * 8));
		pos |= value << (x * 8);
		// ppos[i][j] = value;
	}

	boolean free(int x) {
		return x >= 0 && x < n && !getU(x);
	}

	boolean canMove(int from) {
		return free(from - 1) || free(from + 1);
	}

	boolean anybodyCanMove() {
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				if (canMove(getPos(i, j))) {
					return true;
				}
			}
		}

		return false;
	}

	static class State {
		int u;
		int pos;

		public State(int u, int pos) {
			super();
			this.u = u;
			this.pos = pos;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + pos;
			result = prime * result + u;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			State other = (State) obj;
			if (pos != other.pos)
				return false;
			if (u != other.u)
				return false;
			return true;
		}

	}

	Map<State, Integer> tm;
	int counter = 0;

	int play(int player) {
		counter++;
		State state = new State(u, pos);
		if (tm.containsKey(state)) {
			return tm.get(state);
		}
		if (!anybodyCanMove()) {
			// System.err.println(Arrays.toString(u));
			return 0;
		}
		int best = player == 0 ? Integer.MIN_VALUE / 10 : Integer.MAX_VALUE / 10;
		for (int i = 0; i < 2; i++) {
			int x = getPos(player, i);
			for (int dir = -1; dir <= 1; dir += 2) {
				for (int j = x + dir; j >= 0 && j < n; j += dir) {
					if (getU(j))
						break;
					setU(j, true);
					setPos(player, i, j);
					int res = play(1 - player) + (player == 0 ? a[j] : -a[j]);
					if (player == 0) {
						best = Math.max(best, res);
					} else {
						best = Math.min(best, res);
					}
					setU(j, false);
					setPos(player, i, x);
				}
			}
		}
		if (best == (player == 0 ? Integer.MIN_VALUE / 10 : Integer.MAX_VALUE / 10)) {
			best = play(1 - player);
		}
		tm.put(state, best);
		return best;
	}

	int init(int player, int step) {
		if (step == 4) {
			return play(0);
		}
		int best = player == 0 ? Integer.MIN_VALUE / 10 : Integer.MAX_VALUE / 10;
		for (int i = 0; i < n; i++) {
			if (!getU(i)) {
				setU(i, true);
				setPos(player, step / 2, i);
				int x = init(1 - player, step + 1) + (player == 0 ? a[i] : -a[i]);
				if (player == 0) {
					best = Math.max(best, x);
				} else {
					best = Math.min(best, x);
				}
				setU(i, false);
			}
		}
		return best;
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	public void run() {
		try {
			String filename = "fish";
			br = new BufferedReader(new FileReader(filename + ".in"));
			out = new PrintWriter(filename + ".out");
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	String nextToken() {
		try {
			while (st == null || !st.hasMoreTokens()) {
				String s = br.readLine();
				if (s == null) {
					return null;
				}
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		} catch (IOException e) {
			throw new RuntimeException();
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Integer.parseInt(nextToken());
	}

	public static void main(String[] args) {
		// long time = System.currentTimeMillis();
		new fish_sm().run();
		// System.err.println(System.currentTimeMillis() - time);
	}
}
