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-----
3 100 100
10 1000 100

-----Sample Output-----
900

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

Difficulty: MEDIUM_HARD

Solutions:
(n, z, w) = map(int, input().split())
a = list(map(int, input().split()))
if len(a) == 1:
	print(abs(a[-1] - w))
else:
	print(max(abs(a[-1] - w), abs(a[-1] - a[-2])))


(N, Z, W) = list(map(int, input().split()))
A = list(map(int, input().split()))
idea = abs(A[-1] - W)
try:
	idea2 = abs(A[-2] - A[-1])
except:
	print(idea)
	return
print(max(idea, idea2))


import sys

def solve():
	input = sys.stdin.readline
	(N, Z, W) = map(int, input().split())
	A = [int(a) for a in input().split()]
	if N == 1:
		print(abs(W - A[0]))
	else:
		print(max(abs(W - A[N - 1]), abs(A[N - 2] - A[N - 1])))
	return 0

def __starting_point():
	solve()
__starting_point()


(N, Z, W) = map(int, input().split())
a = list(map(int, input().split()))
print(max(abs(W - a[-1]), abs(a[N - 1] - a[N - 2])))


import sys
from itertools import product
input = sys.stdin.readline

def main():
	(n, z, w) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	ans = abs(w - a[-1])
	if n != 1:
		ans = max(ans, abs(a[-2] - a[-1]))
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, z, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
INF = 10 ** 10
dp = [[None] * 2 for _ in range(n)]
for i in range(n - 1, -1, -1):
	dp[i][0] = -INF
	y = a[i - 1] if i else w
	dp[i][0] = max(dp[i][0], abs(y - a[-1]))
	for j in range(i + 1, n):
		dp[i][0] = max(dp[i][0], dp[j][1])
	dp[i][1] = INF
	x = a[i - 1] if i else z
	dp[i][1] = min(dp[i][1], abs(x - a[-1]))
	for j in range(i + 1, n):
		dp[i][1] = min(dp[i][1], dp[j][0])
ans = dp[0][0]
print(ans)


(N, Z, W) = map(int, input().split())
A = list(map(int, input().split()))
if N == 1:
	print(abs(W - A[0]))
else:
	ans = max(abs(A[-1] - W), abs(A[-1] - A[-2]))
	print(ans)


(n, z, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
if n == 1:
	print(abs(a[0] - w))
	return
print(max(abs(a[-1] - w), abs(a[-1] - a[-2])))


import sys
readline = sys.stdin.readline
(N, Z, W) = map(int, readline().split())
A = list(map(int, readline().split()))
if N == 1:
	print(abs(A[0] - W))
	return
last_one = abs(A[-1] - W)
last_two = abs(A[-1] - A[-2])
if last_one > last_two:
	print(last_one)
else:
	print(last_two)


def main():
	(N, Z, W) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	if N == 1:
		return abs(A[-1] - W)
	return max(abs(A[-1] - W), abs(A[-1] - A[-2]))
print(main())


(n, z, w) = list(map(int, input().split()))
A = list(map(int, input().split()))
if n == 1:
	print(abs(A[0] - w))
else:
	print(max(abs(A[-1] - w), abs(A[-2] - A[-1])))


import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
MAXN = 2005
dp0 = [[-1] * MAXN for _ in range(MAXN)]
dp1 = [[-1] * MAXN for _ in range(MAXN)]

def dfs(i, j, p, z, w, a, n):
	if p == 0:
		if dp0[i][j] != -1:
			return dp0[i][j]
		if i == n:
			if j == 0:
				return abs(w - a[-1])
			return abs(a[j - 1] - a[-1])
		ans = 0
		for k in range(i, n):
			ans = max(ans, dfs(k + 1, k, 1, z, w, a, n))
		if i == 1:
			ans = max(ans, abs(a[-1] - w))
		else:
			ans = max(ans, abs(a[-1] - a[i - 1]))
		dp0[i][j] = ans
		return ans
	elif p == 1:
		if dp1[i][j] != -1:
			return dp1[i][j]
		if i == n:
			if j == 0:
				return abs(z - a[-1])
			return abs(a[j - 1] - a[-1])
		ans = INF
		for k in range(i, n):
			ans = min(ans, dfs(k + 1, k, 0, z, w, a, n))
		if i == 1:
			ans = min(ans, abs(a[-1] - z))
		else:
			ans = min(ans, abs(a[-1] - a[i - 1]))
		dp1[i][j] = ans
		return ans

def main():
	(n, z, w) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = dfs(1, 0, 0, z, w, a, n)
	print(ans)

def __starting_point():
	main()
__starting_point()


import collections

def main():
	(n, z, w) = list(map(int, input().split()))
	a = [int(i) for i in input().split()]
	if n == 1:
		print(abs(w - a[0]))
	else:
		print(max(abs(a[n - 1] - a[n - 2]), abs(a[n - 1] - w)))

def __starting_point():
	main()
__starting_point()


(N, Z, W) = list(map(int, input().split()))
a = list(map(int, input().split()))
if N == 1:
	print(abs(a[0] - W))
else:
	print(max(abs(a[-1] - W), abs(a[-1] - a[-2])))


(n, z, w, *a) = list(map(int, open(0).read().split()))
if n > 1:
	print(max(abs(a[-2] - a[-1]), abs(a[-1] - w)))
else:
	print(abs(a[0] - w))


import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
(N, Z, W) = list(map(int, input().split()))
A = list(map(int, input().split()))
if N == 1:
	print(abs(A[-1] - W))
else:
	print(max(abs(A[-1] - W), abs(A[-1] - A[-2])))


(n, z, w) = map(int, input().split())
a = [int(i) for i in input().split()]
if n == 1:
	print(abs(w - a[0]))
	return
print(max(abs(w - a[n - 1]), abs(a[n - 1] - a[n - 2])))


(n, z, w) = map(int, input().split())
l = list(map(int, input().split()))
if n == 1:
	print(abs(l[-1] - w))
else:
	print(max(abs(l[-1] - w), abs(l[-1] - l[-2])))


(n, z, w) = map(int, input().split())
a = list(map(int, input().split()))
ma = max(abs(a[n - 2] - a[n - 1]), abs(a[n - 1] - w))
print(ma)


def main():
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 7)
	from collections import Counter, deque
	from itertools import combinations, permutations, accumulate
	from bisect import bisect_left, bisect_right
	import heapq
	from math import floor, ceil
	(N, Z, W) = map(int, input().split())
	a = list(map(int, input().split()))
	if N >= 2:
		print(max(abs(a[-1] - W), abs(a[-1] - a[-2])))
	else:
		print(abs(a[0] - W))

def __starting_point():
	main()
__starting_point()


(n, z, w) = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
	print(abs(a[0] - w))
else:
	p = abs(a[-2] - a[-1])
	q = abs(a[-1] - w)
	print(max(p, q))


import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)
input = sys.stdin.readline

def main():
	(n, z, w) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 1:
		ans = abs(w - a[0])
	else:
		ans = max(abs(w - a[-1]), abs(a[-1] - a[-2]))
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, _, w) = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
	print(abs(a[-1] - w))
else:
	print(max(abs(a[-1] - w), abs(a[-2] - a[-1])))


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
(n, z, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
last = a[-1]
if n == 1:
	print(abs(w - last))
	return
last2 = a[-2]
print(max(abs(last2 - last), abs(last - w)))


(N, Z, W) = map(int, input().split())
As = list(map(int, input().split()))
max_score = abs(As[-1] - W)
if N >= 2 and max_score < abs(As[-2] - As[-1]):
	max_score = abs(As[-2] - As[-1])
print(max_score)


def solve():
	(N, Z, W) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if N == 1:
		print(abs(a[0] - W))
		return
	print(max(abs(a[-1] - W), abs(a[-2] - a[-1])))

def __starting_point():
	solve()
__starting_point()


(n, z, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
INF = 10 ** 10
coef = [-1, 1]
initial = [w, z]
func = [max, min]
turn = [0, 1]
dp = [[None] * 2 for _ in range(n)]
for i in range(n - 1, -1, -1):
	for (c, ini, f, t) in zip(coef, initial, func, turn):
		dp[i][t] = c * INF
		opo_card = a[i - 1] if i else ini
		dp[i][t] = f(dp[i][t], abs(a[-1] - opo_card))
		opo_t = (t + 1) % 2
		for j in range(i + 1, n):
			dp[i][t] = f(dp[i][t], dp[j][opo_t])
ans = dp[0][0]
print(ans)


def main():
	(N, Z, W) = list(map(int, input().split(' ')))
	A = list(map(int, input().split(' ')))
	if N == 1:
		print(abs(A[0] - W))
	else:
		print(max([abs(A[-1] - W), abs(A[-2] - A[-1])]))

def __starting_point():
	main()
__starting_point()


(n, z, w) = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
	print(abs(a[-1] - w))
	return
ans = abs(a[-1] - a[-2])
tmp = abs(a[-1] - w)
print(max(ans, tmp))


(n, z, w) = map(int, input().split())
al = list(map(int, input().split()))
if n == 1:
	print(abs(al[0] - w))
	return
al1 = al[-2]
al2 = al[-1]
d1 = abs(al1 - al2)
d2 = abs(al2 - w)
print(max(d1, d2))


(N, Z, W) = map(int, input().split())
A = list(map(int, input().split()))
if N == 1:
	print(abs(A[0] - W))
	return
dp = [[0, 0] for i in range(N)]
dp[-1][0] = abs(A[-1] - W)
dp[-1][1] = -1
dp[-2][0] = dp[-2][1] = dp1min = abs(A[-2] - A[-1])
dp0max = max(dp1min, dp[-1][0])
for i in range(N - 3, -1, -1):
	ai = A[i]
	diff = abs(ai - A[-1])
	dp[i][0] = min(diff, dp1min)
	dp[i][1] = max(diff, dp0max)
	dp0max = max(dp0max, dp[i][0])
	dp1min = min(dp1min, dp[i][1])
print(dp0max)


import sys
try:
	from typing import List
except ImportError:
	pass

def solve(N: int, Z: int, W: int, a: 'List[int]'):
	dp = [(0, 0)] * N
	if N == 1:
		dp[N - 1] = (abs(a[N - 1] - W), abs(Z - a[N - 1]))
	else:
		dp[N - 1] = (abs(a[N - 1] - a[N - 2]), abs(a[N - 2] - a[N - 1]))
	for i in reversed(list(range(N - 1))):
		v1 = max((dp[j][1] for j in range(i + 1, N)))
		if i == 0:
			v1 = max(v1, abs(a[N - 1] - W))
		else:
			v1 = max(v1, abs(a[N - 1] - a[i - 1]))
		v2 = min((dp[j][0] for j in range(i + 1, N)))
		if i == 0:
			v2 = min(v2, abs(Z - a[N - 1]))
		else:
			v2 = min(v2, abs(a[i - 1] - a[N - 1]))
		dp[i] = (v1, v2)
	print(dp[0][0])

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	Z = int(next(tokens))
	W = int(next(tokens))
	a = [int(next(tokens)) for _ in range(N)]
	solve(N, Z, W, a)

def __starting_point():
	main()
__starting_point()


(n, z, w) = map(int, input().split())
cards = list(map(int, input().split()))
if abs(cards[len(cards) - 1] - w) > abs(cards[len(cards) - 1] - cards[len(cards) - 2]):
	print(abs(cards[len(cards) - 1] - w))
else:
	print(abs(cards[len(cards) - 1] - cards[len(cards) - 2]))


(N, Z, W) = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
ans = max(abs(A[N - 2] - A[N - 1]), abs(A[N - 1] - W))
print(ans)


(N, X, Y) = map(int, input().split())
L = list(map(int, input().split()))
if N > 2:
	print(max(abs(L[-2] - L[-1]), abs(Y - L[-1])))
else:
	print(abs(L[-1] - Y))


(N, Z, W) = list(map(int, input().split()))
A = list(map(int, input().split()))
if N == 1:
	print(abs(A[0] - W))
	return
print(max(abs(A[-1] - W), abs(A[-2] - A[-1])))


(n, z, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.insert(0, a[0])
print(max(abs(w - a[-1]), abs(a[-1] - a[-2])))


(N, Z, W) = map(int, input().split())
A = list(map(int, input().split()))
ans = abs(W - A[-1])
if N > 1:
	a = abs(A[-2] - A[-1])
	ans = max(ans, a)
print(ans)


(N, _, W) = map(int, input().split())
A = [int(i) for i in input().split()]
if N == 1:
	ans = abs(A[0] - W)
else:
	ans = abs(A[-1] - A[-2])
	ans = max(ans, abs(A[-1] - W))
print(ans)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	(n, z, w) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	res = abs(w - A[-1])
	if n > 1:
		res = max(res, abs(A[-2] - A[-1]))
	print(res)

def __starting_point():
	resolve()
__starting_point()


import sys
sys.setrecursionlimit(10 ** 6)
(n, z, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
if n == 1:
	ans = abs(a[0] - w)
	print(ans)
	return
ans1 = abs(a[-2] - a[-1])
ans2 = abs(a[-1] - w)
print(max(ans1, ans2))


(N, Z, W) = map(int, input().split())
alist = list(map(int, input().split()))
if N == 1:
	print(abs(alist[-1] - W))
else:
	ans1 = abs(alist[-2] - alist[-1])
	ans2 = abs(alist[-1] - W)
	print(max(ans1, ans2))


def main():
	(n, z, w) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	if n == 1:
		ans = abs(w - a[0])
	else:
		ans = max(abs(a[-1] - w), abs(a[-2] - a[-1]))
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys
sys.setrecursionlimit(10 ** 8)

def sort(a):
	a.sort()

def rev(a):
	a.reverse()

def sd():
	return int(input())

def _sd():
	return list(map(int, input().split()))

def sa():
	return list(map(int, input().split()))

def ss():
	return input()

def sf():
	return float(input())

def main():
	(N, Z, W) = _sd()
	a = sa()
	if N > 1:
		print(max(abs(a[N - 1] - W), abs(a[N - 2] - a[N - 1])))
	else:
		print(abs(a[0] - W))
main()


import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 6)
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
nn = lambda : list(stdin.readline().split())
ns = lambda : stdin.readline().rstrip()
(n, z, w) = na()
a = na()
if n == 1:
	print(abs(a[-1] - w))
	return
print(max(abs(a[-1] - w), abs(a[-2] - a[-1])))


(N, Z, W) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
t1 = abs(a[N - 1] - W)
if N > 1:
	t2 = abs(a[N - 1 - 1] - a[N - 1])
else:
	t2 = 0
if N > 2:
	t3 = min(abs(a[N - 2 - 1] - a[N - 1]), abs(a[N - 1] - a[N - 1 - 1]))
else:
	t3 = 0
print(max(t1, t2, t3))


(n, z, w) = list(map(int, input().split()))
a = list(map(int, input().split()))
if n >= 2:
	dp_x = [abs(a[-1] - a[i]) for i in range(n)]
	dp_y = [abs(a[-1] - a[i]) for i in range(n)]
	for i in reversed(list(range(n - 1))):
		for j in range(i):
			dp_x[j] = min(dp_x[j], dp_y[i])
			dp_y[j] = max(dp_y[j], dp_x[i])
	print(max(abs(a[-1] - w), max(dp_x)))
else:
	print(abs(a[-1] - w))


import numpy as np

def solve(N, Z, W, A):
	dp_x = np.full(N + 1, 1 << 61, dtype=np.int64)
	dp_y = np.zeros(N + 1, dtype=np.int64)
	for i in range(N - 1, 0, -1):
		dp_x[i] = max(dp_y[i + 1:].max(), abs(A[-1] - A[i - 1]))
		dp_y[i] = min(dp_x[i + 1:].min(), abs(A[-1] - A[i - 1]))
	ans = max(abs(A[-1] - W), dp_y[1:].max())
	return ans
(N, Z, W) = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
ans = solve(N, Z, W, A)
print(ans)


import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values():
	return list(map(int, input().split()))

def read_index():
	return [int(x) - 1 for x in input().split()]

def read_list():
	return list(read_values())

def read_lists(N):
	return [read_list() for n in range(N)]

def init_dp1(init, N):
	return [init for _ in range(N)]

def init_dp2(init, N, M):
	return [[init for _ in range(M)] for _ in range(N)]

class V:

	def __init__(self, f, v=None):
		self.f = f
		self.v = v

	def __str__(self):
		return str(self.v)

	def ud(self, n):
		if n is None:
			return
		if self.v is None:
			self.v = n
			return
		self.v = self.f(self.v, n)

def main():
	(N, Z, W) = read_values()
	A = read_list()
	res = V(max, abs(W - A[-1]))
	if N >= 2:
		res.ud(abs(A[-1] - A[-2]))
	print(res)

def __starting_point():
	main()
__starting_point()


(N, Z, W) = map(int, input().split())
a_ls = list(map(int, input().split()))
iA = [0] * N
iB = [0] * N
iA[N - 1] = abs(a_ls[N - 2] - a_ls[N - 1])
iB[N - 1] = abs(a_ls[N - 2] - a_ls[N - 1])
for i in range(N - 2, -1, -1):
	if i != 0:
		prev = a_ls[i - 1]
	else:
		prev = W
	ans = -float('inf')
	for j in range(i + 1, N):
		ans = max(ans, iB[j])
	ans = max(ans, abs(prev - a_ls[-1]))
	iA[i] = ans
	if i != 0:
		prev = a_ls[i - 1]
	else:
		prev = Z
	ans = float('inf')
	for j in range(i + 1, N):
		ans = min(ans, iA[j])
	ans = min(ans, abs(prev - a_ls[-1]))
	iB[i] = ans
if N != 1:
	print(iA[0])
else:
	print(abs(W - a_ls[0]))