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"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	z := getNextInt(scanner)
	w := getNextInt(scanner)

	aa := make([]int, n+1)
	aa[0] = w
	for i := 0; i < n; i++ {
		aa[i+1] = getNextInt(scanner)
	}

	ans := solve(n, z, w, aa)
	fmt.Fprintln(writer, ans)

	writer.Flush()
}

func solve(n, z, w int, aa []int) int {
	dp := make([][2]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i][0] = -1
		dp[i][1] = -1
	}
	prev := 0
	p := play(1, n, aa, dp, true)
	i := 0
	for p < n {
		prev, p = p, dp[p+1][1-i]
		i = 1 - i
	}
	return absint(aa[p] - aa[prev])
}

func play(i, n int, aa []int, dp [][2]int, high bool) int {
	di := 0
	if high == false {
		di = 1
	}
	if dp[i][di] >= 0 {
		return dp[i][di]
	}

	if i == n {
		dp[i][di] = i
		return i
	}

	ans := 0
	if high == false {
		ans = int(1e9 + 1)
	}
	var dpi int
	for ii := i; ii <= n; ii++ {
		iii := i - 1
		if ii < n {
			iii = play(ii+1, n, aa, dp, !high)
		}
		score := absint(aa[ii] - aa[iii])
		if high && ans < score {
			ans = score
			dpi = ii
			continue
		}
		if high == false && ans > score {
			ans = score
			dpi = ii
		}
	}
	dp[i][di] = dpi

	return dpi
}

func absint(a int) int {
	if a < 0 {
		return -a
	}
	return a
}