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 (Python):
N, Z, W = map(int, input().split())
A = [W]+list(map(int, input().split()))
X = [0]*N
Y = [1<<30]*N
X[0] = Y[0] = abs(A[-2]-A[-1])
for i in range(1,N):
    X[i] = max(abs(A[-2-i]-A[-1]), max(Y[j] for j in range(i)))
    Y[i] = min(abs(A[-2-i]-A[-1]), min(X[j] for j in range(i)))
print(X[-1])

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

Solution (Python):



def main():
    import sys

    input = sys.stdin.readline

    N, Z, W = map(int, input().split())
    a = [int(x) for x in input().split()]

    if N == 1:
        print(abs(a[-1] - W))
    else:
        print(max(abs(a[-1] - W), abs(a[-2] - a[-1])))


if __name__ == '__main__':
    main()

Solution (Python):


import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,z,w = map(int, readline().split())
a = [w]+[*map(int, readline().split())]
n += 1

INF = 1<<30
dp0 = [-INF]*n
dp1 = [INF]*n

dp0[-1] = dp1[-1] = abs(a[-1]-a[-2])
for i in range(n-2,0,-1):
    dp0[i] = max(abs(a[-1]-a[i-1]),max(dp1[i+1:]))
    dp1[i] = min(abs(a[-1]-a[i-1]),min(dp0[i+1:]))

print(dp0[1])

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF=10**18

def main():
    N,Z,W=map(int,input().split())
    a=list(map(int,input().split()))
    dic={}
    def rec(z,w,now,t):
        if dic.get((now,t),None)!=None:
            return dic[(now,t)]
        if now>=N-1:
            return abs(z-w)
        if not t:
            res=-INF
            for i in range(now+1,N):
                r=rec(a[i],w,i,1)
                res=max(res,r)
        else:
            res=INF
            for i in range(now+1,N):
                r=rec(z,a[i],i,0)
                res=min(res,r)
        dic[(now,t)]=res
        return res

    return rec(Z,W,-1,0)
    
print(main())

Solution (Python):
n, z, 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[-1] - a[-2])))

Solution (Python):
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def S(): return sys.stdin.readline().rstrip()

N,Z,W = map(int,S().split())
a = LI()

if N == 1:
    print(abs(a[0]-W))
else:
    print(max(abs(a[-1]-W),abs(a[-1]-a[-2])))

Solution (Python):
import sys
from collections import *
import heapq
import math
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,z,w=map(int,input().split())
a=list(map(int,input().split()))

dp=[[-1]*n for i in range(2)]
dp[0][-1]=abs(a[-1]-w)


for i in range(n-1):
    for j in range(2):
        if j==0:
            tmp=dp[1-j][-1-i:-1][:]
            tmp.append(abs(a[-2-i]-a[-1]))
            dp[j][-2-i]=min(tmp)
        else:
            tmp=dp[1-j][-1-i:-1][:]
            tmp.append(abs(a[-2-i]-a[-1]))
            dp[j][-2-i]=max(tmp)
        
print(max(dp[0]))

Solution (Python):
n, z, w = map(int, input().split())
t = tuple(map(int, input().split()))

if n == 1:
    print(abs(t[0] - w))
    exit()




dp = [[0] * 2 for _ in range(n)]


for j in range(2):
    dp[n-1][j] = abs(t[n-2] - t[n-1])


for i in range(n-2, -1, -1):
    for j in range(2):
        
        if j == 0:
            
            
            
            l = [dp[i+k][1] for k in range(1, n-i)]
            
            q = abs(t[n-1] - w) if i == 0 else abs(t[n-1] - t[i-1])
            l.append(q)
            dp[i][j] = max(l)

        else:
            l = [dp[i+k][0] for k in range(1, n-i)]
            if i != 0:
                q = abs(t[n-1] - t[i-1])
                l.append(q)
            dp[i][j] = min(l)

print(dp[0][0])

Solution (Python):
import sys

def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))

    if len(A) == 1:
        ans = abs(A[0] - W)
    else:
        ans = max(abs(A[-1]-W), abs(A[-2]-A[-1]))

    print(ans)
    return


if __name__ == "__main__":
    main()
    sys.exit(0)

Solution (Python):
n, z, w = map(int, input().split())
a = list(map(int, input().split()))

dp = [[0]*2 for _ in range(n)]

for i in range(n-1, -1, -1):
    dp[i][0] = abs((a[i-1] if i > 0 else w) - a[n-1])
    dp[i][1] = abs((a[i-1] if i > 0 else z) - a[n-1])

    for j in range(i+1, n):
        dp[i][0] = max(dp[i][0], dp[j][1])
        dp[i][1] = min(dp[i][1], dp[j][0])

print(dp[0][0])

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF=10**18

def main():
    N,Z,W=map(int,input().split())
    a=list(map(int,input().split()))
    dic={}
    def rec(z,w,now,t):
        if dic.get((now,t),None)!=None:
            return dic[(now,t)]
        if now>=N-1:
            return abs(z-w)
        if not t:
            res=-INF
            for i in range(now+1,N):
                r=rec(a[i],w,i,1)
                res=max(res,r)
        else:
            res=INF
            for i in range(now+1,N):
                r=rec(z,a[i],i,0)
                res=min(res,r)
        dic[(now,t)]=res
        return res

    return rec(Z,W,-1,0)
    
print(main())

Solution (Python):
N, Z, W = map(int, input().split())
A = list(map(int, input().split()))
dp = [[-1] * (N + 1) for _ in range(N + 1)]

for x in range(N, -1, -1):
    for y in range(N, -1, -1):
        if x == y:
            continue
        X = Z if x == 0 else A[x - 1]
        Y = W if y == 0 else A[y - 1]
        if x == N or y == N:
            rst = abs(X - Y)
        elif x - y == 1:
            rst = 10 ** 10
            for j in range(N, x, -1):
                rst = min(rst, dp[x][j])
        elif x - y > 1:
            rst = dp[x][y + 1]
        elif y - x == 1:
            rst = 0
            for i in range(N, y, -1):
                rst = max(rst, dp[i][y])
        elif y - x > 1:
            rst = dp[x + 1][y]
        else:
            raise Exception
        dp[x][y] = rst

ans = 0
for i in range(N):
    ans = max(ans, dp[i + 1][0])
print(ans)

Solution (Python):



N, Z, W = list(map(int, input().split()))
A = list(map(int, input().split()))


def main():
    ans = abs(A[-1] - W)
    ans = max(ans, abs(A[-1] - A[-2])) if N > 1 else ans
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n,z,w=[int(x) for x in input().split()]
 
a=[int(x) for x in input().split()]
 
if(n==1):
  print(abs(a[0]-w))
else:
  print(max(abs(a[-1]-w),abs(a[-1]-a[-2])))

Solution (Python):
n,z,w = map(int,input().split())
a = list(map(int,input().split()))



if abs(a[n-1]-w) > abs(a[n-2]-a[n-1]) :
    print(abs(a[n-1]-w))
else :
    print(abs(a[n-2]-a[n-1]))

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

Solution (Python):
import sys
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
if n==1: print(abs(a[0]-w));sys.exit()

x,y=[-1]*n,[-1]*n
x[n-1]=abs(a[n-1]-w)
y[n-2]=abs(a[n-1]-a[n-2])

for i in range(n-2,-1,-1):
    x[i]=abs(a[i]-a[n-1])
    for j in range(i+1,n-1):
        x[i]=min(x[i],y[j])
    y[i]=abs(a[n-1]-a[i])
    for j in range(i+1,n-1):
        y[i]=max(y[i],x[j])

print(max(x))

Solution (Python):
n,z,w = map(int, input().split( ))
*a, = map(int, input().split( ))

a.reverse()
ans1 = 0
if len(a)>1:
    ans1 = abs(a[1]-a[0])
ans2 = abs(a[0]-w)
print(max(ans1,ans2))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
N, Z, W = [int(x) for x in input().strip().split()]
a = [int(x) for x in input().strip().split()]
d = {}
def minmax(x, y, c, f):
    
    if (c, f) in d:
        return d[(c, f)]
    if c == N:
        return abs(x - y)
    if f == 0:
        ret = -float('inf')
        for i in range(1, N - c + 1):
            ret = max(ret, minmax(a[c+i-1], y, c+i, f^1))
    else:
        ret = float('inf')
        for i in range(1, N - c + 1):
            ret = min(ret, minmax(x, a[c+i-1], c+i, f^1))
    d[(c, f)] = ret
    return ret

print(minmax(Z, W, 0, 0))

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

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

Solution (Python):
N, Y, Z = map(int, input().split())
As = list(map(int, input().split()))
dpx, dpy = [0]*(N-1), [0]*(N-1)


for i in range(N-2, -1, -1):
    mny, mxx = 10**10, 0
    for j in range(i+1, N-1):
        mny = min(mny, dpy[j])
        mxx = max(mxx, dpx[j])
    dpx[i] = min(mny, abs(As[N-1]-As[i]))
    dpy[i] = min(mxx, abs(As[N-1]-As[i]))
dpx.append(abs(As[N-1]-Z))
print(max(dpx))

Solution (Python):
N, Y, Z = map(int, input().split())
As = list(map(int, input().split()))
dpx, dpy = [0]*(N-1), [0]*(N-1)


for i in range(N-2, -1, -1):
    mny, mxx = 10**10, 0
    for j in range(i+1, N-1):
        mny = min(mny, dpy[j])
        mxx = max(mxx, dpx[j])
    dpx[i] = min(mny, abs(As[N-1]-As[i]))
    dpy[i] = max(mxx, abs(As[N-1]-As[i]))
dpx.append(abs(As[N-1]-Z))
print(max(dpx))

Solution (Python):
N, Z, W = map(int, input().split())
A = [int(x) for x in input().split()]
if N == 1:
    print(abs(A[0] - W))
else:
    print(max(abs(A[-2] - A[-1]), abs(A[-1] - W)))

Solution (Python):
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))

if N == 1:
    print(abs(a[0] - W))
    exit()

ans1 = abs(a[-1] - a[-2])
if abs(a[-1] - W) > ans1:
    print(abs(a[-1] - W))
else:
    print(ans1)

Solution (Python):
import sys

N, Z, W = map(int, input().split())
A = list(map(int, input().split()))

ans = abs(A[-1] - W)
if N != 1:
    ans = max(ans, abs(A[-1] - A[-2]))
print(ans)

Solution (Python):
data = input().split(" ")
n = int(data[0])
z = int(data[1])
w = int(data[2])
a = input().split(" ")
if n != 1:
	b = int(a[n-2])
	c = int(a[n-1])
	ans = abs(w-c)
	if ans <= abs(b-c):
		ans = abs(b-c)
	print(ans)
else:
	print(abs(w-int(a[0])))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・そもそもとして、ゲームが長引くことはありえない
"""

N,Z,W,*A = map(int,read().split())

A = A[::-1]

if N == 1:
    answer = abs(A[0] - W)
    print(answer)
    exit()

x = abs(A[0] - W)
y = abs(A[1] - A[0])
answer = max(x,y)
print(answer)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

"""
山札がなくなると終了かつ必ず1枚は引かなくてはいけない
⇒最後の1枚は必ずどちらかの手になる(山札が1枚の場合、必ず自分の手になる)
先攻はそれを自分の手にするか、相手の手にするかを選べる
自分の手にする場合、1ターン目で全部の手札を取る
相手の手にする場合、1ターン目で最後から2番目まで全部取る
この2通りのみを考える
"""
n,z,w = LI()
a = LI()
if n == 1:
    ans = abs(a[0] - w)
else:
    ans = max(abs(a[-2]-a[-1]),abs(a[-1]-w))
print(ans)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,z,w = LI()
a = LI()
if n == 1:
    ans = abs(a[0]-w)
else:
    ans = max(abs(a[-2] - a[-1]),abs(a[-1] - w))
print(ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    n, z, w = LI()
    a = LI()
    if n == 1:
        print(abs(a[0] - w))
    else:
        print(max(abs(a[-1] - w), abs(a[-2] - a[-1])))
    return



if __name__ == '__main__':
    solve()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,x,y = LI()
    a = LI()
    ans = abs(a[-1]-y)
    if n > 1:
        ans = max(ans,abs(a[-2]-a[-1]))
    print(ans)
    return


if __name__ == "__main__":
    solve()

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def MI(): return map(int, sys.stdin.readline().split())

def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    n, z, w = MI()
    aa = LI()
    if n - 2 >= 0:
        print(max(abs(aa[n - 1] - aa[n - 2]), abs(aa[n - 1] - w)))
    else:
        print(abs(aa[n - 1] - w))

main()

Solution (Python):
N,X,Y = map(int,input().split())
A = list(map(int,input().split()))

if N == 1 :
    a = -1
    b = abs(A[0] - Y)
else :
    a = abs(A[N-1] - Y)
    b = abs(A[N-2] - A[N-1])

print(max(a, b))

Solution (Python):

def main():
    N, Z, W, *A = map(int, open(0).read().split())
    if N == 1:
        ans = abs(A[0] - W)
    else:
        ans = max(abs(A[-1] - W), abs(A[-2] - A[-1]))
    print(ans)


if __name__ == "__main__":
    main()

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

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

Solution (Python):

import sys
def input():
	return sys.stdin.readline().strip()

N, Z, W = list(map(int, input().split()))
a = list(map(int, input().split()))

dp = [[0]*(N + 1) for i in range(N + 1)]
dp[0][N] = abs(a[N-1] - Z)
dp[N][0] = abs(a[N-1] - W)
for i in range(1, N):
	dp[i][N] = abs(a[N - 1] - a[i - 1])
	dp[N][i] = dp[i][N]

for i in range(N - 1, 0, -1):
	min_score = min(dp[i][i + 1: N + 1])
	for j in range(i - 1):
		dp[i][j] = min_score
	max_score = 0
	for j in range(i + 1, N + 1):
		max_score = max(max_score, dp[j][i])
	for j in range(i - 1):
		dp[j][i] = max_score

score = 0
for i in range(1, N + 1):
	score = max(score, dp[i][0])

print(score)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
from collections import deque

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n, ia, ib = getList()
nums = getList()

if n == 1:
    print(abs(ib - nums[0]))
    sys.exit()

ans = abs(nums[-1] - nums[-2])
if abs(nums[-1] - ib) > ans:
    ans = abs(nums[-1] - ib)

print(ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n,k = LI()
    a = LI()
    d = defaultdict(lambda:0)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    ans = 0
    for i in range(len(d)-k):
        ans += d[i]
    print(ans)
    return


def B():
    n,z,w = LI()
    a = LI()
    if n == 1:
        print(abs(a[0]-w))
        return
    ans = max(abs(a[-1]-w),abs(a[-2]-a[-1]))
    print(ans)
    return


def C():

    return


def D():

    return


def E():

    return


if __name__ == "__main__":
    B()

Solution (Python):
n,z,w = 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])))

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

Solution (Python):
n, x0, y0 = list(map(int, input().split()))

cards = [y0] + list(map(int, input().split()))


xs = [[-1] * (n+1) for i in range(n+1)]
ys = [[-1] * (n+1) for i in range(n+1)] 



for i in range(n+1):
	xs[i][-1] = abs(cards[-1] - cards[i])
	ys[i][-1] = abs(cards[-1] - cards[i])

for j in range(n-1, -1, -1):

	
	xs_temp = max(ys[j][j+1:n+1])
	ys_temp = min(xs[j][j+1:n+1])
	for i in range(0, j):
		xs[i][j] = xs_temp
		ys[i][j] = ys_temp



print(max(ys[0][1:]))

Solution (Python):
N,Z,W=map(int,input().split())
A=list(map(int,input().split()))
an=A[-1]
A=[abs(a-an) for a in A]
W=abs(W-an)
if N==1:
    print(W)
else:print(max(W,A[-2]))

Solution (Python):
n,z,w=map(int,input().split())
A=[int(i) for i in input().split()]
print(abs(w-A[-1]) if n==1 else max(abs(A[-2]-A[-1]),abs(w-A[-1])))

Solution (Python):
n,z,w = map(int,input().split())
a = [int(i) for i in input().split()]

if n == 1:
  print(abs(a[-1]-w))
else:
  print(max(abs(a[-1]-w),abs(a[-2]-a[-1])))

Solution (Python):

N,Z,W=list(map(int,input().split()))
a=list(map(int,input().split()))

print(max(abs(W-a[N-1]),abs(a[N-2]-a[N-1])))

Solution (Python):
n, z, w = map(int,input().split())
a = list(map(int,input().split()))

if n == 1:
    print(abs(a[0]-w))
else:
    print(max(abs(a[n-2]-a[n-1]),abs(a[n-1]-w)))

Solution (Python):
n, z, w = map(int, input().split())
alist = list(map(int, input().split()))

if n == 1:
  print(abs(alist[0] - w))
else:
  print(max(abs(alist[-1] - w), abs(alist[-1] - alist[-2])))

Solution (Python):
from functools import lru_cache
import sys
sys.setrecursionlimit(2*10**5)


N, Z, W = map(int, input().split())
a = list(map(int, input().split()))



@lru_cache(maxsize=None)
def f(i, m):
    return (
        max(
            abs(W - a[-1]) if m == N else abs(a[-(m + 1)] - a[-1]),
            max(f(-i, k) for k in range(1, m))
        ) if i == 1 and m >= 2 else
        min(
            abs(a[-(m + 1)] - a[-1]),
            min(f(-i, k) for k in range(1, m))
        ) if i == -1 and m >= 2 else
        abs(a[-2] - a[-1]) if N >= 2 else
        abs(W - a[-1])
    )



ans = f(1, N)
print(ans)

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

Solution (Python):
n,z,w=map(int,input().split())
A=[int(x) for x in input().split()]
print(max(abs(A[n-2]-A[n-1]),abs(A[n-1]-w))) if n!=1 else print(abs(A[0]-w))

Solution (Python):
n,z,w = map(int,input().split())
a = tuple(map(int,input().split()))

res = abs(a[-1]-w)
for i in range(n-1):
    cand = abs(a[-1]-a[i])
    for j in range(i+1,n-1):
        cand = min(a[j]-a[-1],cand)
    res = max(res,cand)
print(res)

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

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

Solution (Python):


def main():
    n, z, w = input().split()
    n = int(n)
    w = int(w)
    a = list(map(int, input().split()))
    a = [w] + a

    sx = s_min = s_max = abs(a[n] - a[n - 1])
    for i in range(n - 1, 0, -1):
        sx = max(s_max, abs(a[n] - a[i - 1]))
        sy = min(s_min, abs(a[n] - a[i - 1]))
        s_max = max(s_max, sy)
        s_min = min(s_min, sx)

    print(sx)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N, Z, W = map(int, input().split())
    a = list(map(int, input().split()))
    retval = abs(a[-1] - W)
    if N >= 2:
        retval = max(retval, abs(a[-1] - a[-2]))
    print(retval)


if __name__ == "__main__":
    main()

Solution (Python):
N, Z, W = map(int, input().split())
A = [int(a) for a in input().split()]

if N == 1: print(abs(A[0]-W))
else: print(max(abs(A[-2]-A[-1]), abs(A[-1]-W)))

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

Solution (Python):
import sys
fin = sys.stdin.readline

N, Z, W = [int(elem) for elem in fin().split()]
a_list = [int(elem) for elem in fin().split()]
assert len(a_list) == N

if N == 1:
    print(abs(a_list[-1] - W))
else:
    print(max(abs(a_list[-1] - W), abs(a_list[-2] - a_list[-1])))

Solution (Python):
n,z,w = map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
ans = max(ans,abs(lis[n-1]-w),abs(lis[n-1]-lis[n-2]))
print(ans)

Solution (Python):
N, Z, W = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
if N == 1:
    print(abs(a[-1]-W))
else:
    ans = max(abs(a[-1]-W),abs(a[-2]-a[-1]))
    print(ans)

Solution (Python):
'''input
4
4 3 2 1
'''
n,z,w = map(int,raw_input().split())
arr = map(int,raw_input().split())
if n > 1:
	print max(abs(arr[-1]-w),abs(arr[-1]-arr[-2]))
else:
	print abs(arr[-1]-w)

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

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

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

Solution (Python):
import sys
N,Z,W=map(int,input().split())
A=[int(i) for i in input().split()]
if N==1:
    print(abs(A[0]-W))
    sys.exit()
print(max(abs(A[-2]-A[-1]),abs(A[-1]-W)))

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, Z, W = reads()
A = reads()

ans = abs(A[-1]-W)
if N >= 2:
  ans = max(ans, abs(A[-1]-A[-2]))
print(ans)

Solution (Python):
N,Z,W=map(int,input().split())
a=list(map(int,input().split()))



score=abs(a[N-1]-W)




print(max(score,abs(a[N-2]-a[N-1])))

'''
drawcount=0 
score=[0]*N 
score[N-1]=abs(a[N-1]-W) 

for i in range(N-1):
  Xscore=a[i]
  print(Xscore)
  score[i]=10**9
  for j in range(i+1,N):
  	score[i]=min(abs(a[i]-a[j]),score[i])
  	print(score)
print(max(score))
'''

Solution (Python):
N, Z, W = map(int, input().split())
As = list(map(int, input().split()))

num = abs(As[-1] - W)
if N == 1:
    print(num)
else:
    print(max(num, abs(As[-2] - As[-1])))

Solution (Python):
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))

if N == 1:
    print(abs(a[0] - W))
else:
    x = abs(a[-2] - a[-1])
    y = abs(a[-1] - W)
    
    ans = max(x, y)
    print(ans)

Solution (Python):

import sys
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)

N, Z, W = map(int, input().split())
a = list(map(int, input().split()))

if N == 1:
    print(abs(a[-1]-W))
    exit()

print(max(abs(a[-2] - a[-1]),
          abs(a[-1] - W)))

Solution (Python):
n, z, w = map(int, input().split())
a = list(map(int, input().split()))

if n == 1:
	print(abs(w - a[0]))
else:
	print(max(abs(w - a[-1]), abs(a[-1] - a[-2])))

Solution (Python):
N,Z,W = map(int,input().split())
src = list(map(int,input().split()))

s1 = abs(src[-1] - W)
s2 = 0 if N==1 else abs(src[-2] - src[-1])

print(max(s1,s2))

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

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

Solution (Python):
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))

if N == 1:
    print(abs(a[0] - W))
else:
    x = abs(a[-2] - a[-1])
    y = abs(a[-1] - W)
    
    ans = max(x, y)
    print(ans)

Solution (Python):
n, z, w = map(int, input().split())
a = list(map(int, input().split()))

if n == 1:
    print(abs(a[-1] - w))
    exit()


ans = abs(a[-1] - w)


ans = max(ans, abs(a[-1] - a[-2]))

print(ans)

Solution (Python):

import math
a = []
N,Z,W = map(int,input().split())
a = list(map(int,input().split()))

if N==1:
	print(abs(a[0]-W))
else :
	print(max(abs(a[N-1]-W),abs(a[N-2]-a[N-1])))

Solution (Python):

import math
a = []
N,Z,W = map(int,input().split())
a = list(map(int,input().split()))

if N==1:
	print(abs(a[0]-W))
elif abs(a[N-2]-a[N-1]) > abs(a[N-1]-W):
	print(abs(a[N-2]-a[N-1]))
else :
	print(abs(a[N-1]-W))

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
INF = float("inf")
import sys
sys.setrecursionlimit(10000)

a = []
memo = []


def dfs(no, i):
    global memo, a
    if memo[no][i] != -1:
        return memo[no][i]

    ans = abs(a[-1] - a[i])
    for j in range(i + 1, len(a) - 1):
        nex = dfs(1 - no, j + 1)
        
        if no == 0:
            ans = max(ans, nex)
        
        else:
            ans = min(ans, nex)

    memo[no][i] = ans
    return ans


def solve2(N, Z, W):
    global a, memo
    a = [Z, W] + a
    memo = [[-1] * len(a) for _ in range(2)]
    return dfs(0, 1)


def solve(N, Z, W):
    global a
    ans = abs(a[-1] - W)
    if len(a) > 1:
        ans = max(ans, abs(a[-2] - a[-1]))
    return ans


def main():
    global a
    N, Z, W = map(int, input().split())
    a = list(map(int, input().split()))
    print(solve2(N, Z, W))


if __name__ == '__main__':
    main()

Solution (Python):
N, Z, W = map(int, input().split())
a = [int(n) for n in input().split()]

if N == 1:
    print(abs(a[0]-W))
else:
    print(max(abs(a[N-1]-W), abs(a[N-1]-a[N-2])))

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

Solution (Python):


N, Z, W = map(int, input().split())

As = list(map(int, input().split()))

if len(As)==1:
    print(abs(W-As[-1]))
    exit()

print(max(abs(W-As[-1]), abs(As[-1]-As[-2])))

Solution (Python):

def inpl(): return tuple(map(int, input().split()))

N, Z, W = inpl()

A = inpl()


p1 = abs(A[-1] - W)


if N > 1:
    p2 = abs(A[-1] - A[-2])
else:
    p2 = p1

print(max(p1, p2))

Solution (Python):
N,Z,W=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]

if N>1:
        print(max(abs(a[-1]-W),abs(a[-2]-a[-1])))
else:
        print(abs(a[0]-W))

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

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

Solution (Python):

def main():
    N,Z,W = map(int,input().split())
    a = list(map(int,input().split()))

    print(max(abs(a[N-1]-W),abs(a[N-1]-a[N-2])))

if __name__ == '__main__':
    main()

Solution (Python):
import math
N,Z,W=list(map(int,input().split()))
a=list(map(int,input().split()))
b=math.fabs(a[N-1]-W)
c=math.fabs(a[N-2]-a[N-1])
print(int(max(b,c)))

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

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

Solution (Python):
c=input()
b=c.split()
N=int(b[0])
Z=int(b[1])
W=int(b[2])
A=input().split()
ans1=abs(int(A[N-1])-W)
ans2=abs(int(A[N-1])-int(A[N-2]))
print(max(ans1,ans2))