Problem:
Score : 500 points

Problem Statement

We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i.

Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action:

Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn.

The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand.

X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?

Constraints

All input values are integers.

1 \leq N \leq 2000

1 \leq Z, W, a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N Z W
a_1 a_2 ... a_N

Output

Print the score.

Sample Input 1

3 100 100
10 1000 100

Sample Output 1

900

If X draws two cards first, Y will draw the last card, and the score will be |1000 - 100| = 900.

Sample Input 2

3 100 1000
10 100 100

Sample Output 2

900

If X draws all the cards first, the score will be |1000 - 100| = 900.

Sample Input 3

5 1 1
1 1 1 1 1

Sample Output 3

0

Sample Input 4

1 1 1
1000000000

Sample Output 4

999999999

Solution in Go (1.6) (judge verdict: Wrong Answer)

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func score(scoreX, scoreY int) int {
	return abs(scoreX - scoreY)
}

const INF = -1000001000

// プレイヤーxがy枚目を引いた時のスコア
var memo [][]int

func dfs(scoreX, scoreY, n int, player int) int {

	if n == N {
		return score(scoreX, scoreY)
	}

	if memo[player][n] != -1 {
		return memo[player][n]
	}

	res := INF
	for i := n; i < N; i++ {
		if player == 1 {
			res = max(res, dfs(a[i], scoreY, i+1, 0))
		} else {
			res = max(res, dfs(scoreX, a[i], i+1, 1))
		}
		memo[player][i] = res

	}

	return memo[player][N-1]
}

var N, Z, W int
var a []int

func main() {
	sc.Split(bufio.ScanWords)
	N, Z, W = nextInt(), nextInt(), nextInt()

	memo = make([][]int, 2)
	for i := 0; i < 2; i++ {
		memo[i] = make([]int, 2020)
		for j := 0; j < 2020; j++ {
			memo[i][j] = -1
		}
	}

	a = make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = nextInt()
	}

	fmt.Println(dfs(Z, W, 0, 1))

}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}