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_slow4 {
	int n;
	int[] a;

	void solve() {
		n = nextInt();
		a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = nextInt();
		}
		u = 0;
		pos = new int[2][2];
		int res = init(0, 0);
		System.out.println(res);
		System.err.println("counter = " + counter);
	}

	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;

	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[] a : pos) {
			for (int b : a) {
				if (canMove(b)) {
					return true;
				}
			}
		}
		return false;
	}

	static class State {
		int u;
		int[][] pos;

		public State(int u2, int[][] pos) {
			this.u = u2;
			this.pos = new int[2][2];
			for (int i = 0; i < pos.length; i++) {
				for (int j = 0; j < pos.length; j++) {
					this.pos[i][j] = pos[i][j];
				}
			}
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + Arrays.deepHashCode(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 (!Arrays.deepEquals(pos, other.pos))
				return false;
			if (u != other.u)
				return false;
			return true;
		}

	}

	Map<State, Integer> tm = new HashMap<State, Integer>();
	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 = pos[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);
					pos[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);
					pos[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);
				pos[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) {
		new fish_sm_slow4().run();
	}
}
