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())
 
x = z
y = w

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

print(ans)

Solution (Python):


def main():
    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])))

if __name__ == '__main__':
    main()

Solution (Python):
def ABS(N, Z, W, ai):
    if len(ai) == 1:
        return abs(ai[0]-W)
    else:
        return max(abs(ai[-1]-W), abs(ai[-1]-ai[-2]))


if __name__ == '__main__':
    n, z, w = [int(i) for i in input().split()]
    ai = list(map(int, input().split()))
    print(ABS(n, z, w, ai))

Solution (Python):


def f(N, Z, W, A):
    A.insert(0, W)

    lastA = A[-1]
    sc = abs(lastA - A[-2])
    minOfX = sc
    maxOfY = sc
    scX = sc

    for i in range(N-1, 0, -1):
        sc = abs(lastA - A[i-1])

        scX = max(sc, maxOfY)
        scY = min(sc, minOfX)

        minOfX = min(minOfX, scX)
        maxOfY = max(maxOfY, scY)

    return scX
            

def test():
    assert f(3, 100, 100, [10, 1000, 100]) == 900
    assert f(3, 100, 1000, [10, 100, 100]) == 900
    assert f(5, 1, 1, [1, 1, 1, 1, 1]) == 0
    assert f(1, 1, 1, [1000000000]) == 999999999


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

    print(f(N,Z,W,A))


if __name__ == '__main__':
    main()

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

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


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


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

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


if __name__ == '__main__':
    main()

Solution (Python):



from sys import stdin

def solve(a):
  n = len(a)
  xmemo = [0 for i in range(n)]  
  ymemo = [0 for i in range(n)]  

  
  for i in range(n - 2, -1, -1):
    
    f = abs(a[i] - a[n - 1])
    
    xmemo[i] = max([f] + [ymemo[jj] for jj in range(i + 1, n - 1)])
    ymemo[i] = min([f] + [xmemo[jj] for jj in range(i + 1, n - 1)])

  return xmemo[1]

N, Z, W = map(int, stdin.readline().split())
a       = map(int, stdin.readline().split())
if len(a) != N: raise


a = [Z, W] + a

print(solve(a))

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,z,w = LI()
    a = LI()
    m = {}
    def f(z,w,i,t):
        if i >= n:
            return abs(z-w)
        if t:
            k = (-1,w,i)
            if k in m:
                return m[k]
            r = -1
            for j in range(i,n):
                jr = f(a[j],w,j+1,False)
                if r < jr:
                    r = jr
            m[k] = r
        else:
            k = (z,-1,i)
            if k in m:
                return m[k]
            r = inf
            for j in range(i,n):
                jr = f(z,a[j],j+1,True)
                if r > jr:
                    r = jr
            m[k] = r
        return m[k]

    return f(z,w,-1,True)



print(main())

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

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

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

Solution (Python):
n, x, y = map(int, input().split())
a = list(map(int, input().split()))

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

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):
l=input().split()
n=int(l[0])
w=int(l[2])
l=input().split()
a=[]
for i in range(n):
  a.append(int(l[n-1-i]))
s=[]
m=[]
if n>=3:
  s.append(abs(a[1]-a[0]))
  s.append(max(abs(a[2]-a[0]),abs(a[1]-a[0])))
  m=[s[0],min(s[0],s[1])]
  x=min(abs(a[2]-a[0]),m[0])
  for i in range(2,n-2):
    if(max(abs(a[i]-a[0]),m[i-2])>x):
      x=max(abs(a[i]-a[0]),m[i-2])
    s.append(max(abs(a[i+1]-a[0]),x,abs(a[1]-a[0])))
    m.append(min(s[-1],m[-1]))
  s.reverse()
  if n==3:
    del(s[0])
  res=[abs(w-a[0]),abs(a[1]-a[0])]
  a.reverse()
  for i in range(n-2):
    res.append(min(abs(a[-2]-a[-1]),abs(a[i]-a[-1]),min(s[i:])))
  print(max(res))
if n==2:
  print(max(abs(w-a[0]),abs(a[1]-a[0])))
if n==1:
  print(abs(w-a[0]))
s.append

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

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

    D = [0]*N
    E = [0]*N
    D[0] = abs(Z-W)
    D[1] = abs(A[N-1]-A[N-2])
    E[0] = abs(Z-W)
    E[1] = abs(A[N-2] - A[N-1])

    for n in range(2, N):
        D[n] = min(E[n-1], D[n-1])
        E[n] = max(D[n-1], E[n-1])

    
    
    

    res = max(E[N-1], abs(W - A[N-1]))
    print(res)

if __name__ == "__main__":
    main()

Solution (Python):


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

BOTTOM = A[0]

M = float('inf')
m = 0

for a in A[1:]:
  x = abs(BOTTOM-a)
  t = max(x,m)
  s = min(x,M)
  M = min(M,t)
  m = max(m,s)

print(t)

Solution (Python):
[N,Z,W]=map(int,raw_input().split())
A=map(int,raw_input().split())

if len(A)==1:
    print abs(A[-1]-W)
else:
    if abs(A[-1]-W)>abs(A[-1]-A[-2]):
        print abs(A[-1]-W)
    else:
        print abs(A[-1]-A[-2])

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

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

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

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

Solution (Python):
n, Z, W = map(int, raw_input().split())
a = map(int, raw_input().split())
z = abs(W - a[-1])
if n > 1:
	z = max(z, abs(a[-1] - a[-2]))
print z

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

Solution (Python):



from math import *
import random

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

n,z,w = readln()
a = readln()
f = [0 for i in range(n)]
min_f = [0 for i in range(n)]
max_min_f = [0 for i in range(n)]

s = [a[n - i - 1] for i in range(n)]
s.append(w)

f[0] = abs(s[0] - s[1])
min_f[0] = f[0]
max_min_f[0] = f[0]
for i in range(1,n):
    f[i] = max(abs(s[0] - s[i + 1]), max_min_f[i-1])
    min_f[i] = min(f[i],min_f[i-1])
    max_min_f[i] = max(min_f[i], max_min_f[i-1])


print(f[n-1])

Solution (Python):
import sys
sys.setrecursionlimit(10**4)
n, _, y = map(int, input().split())
a = list(map(int, input().split()))
a = [y] + a

memo = [[-1 for i in range(n + 1)] for j in range(2)]
def sol(i, turn):
    
    if memo[turn][i] != -1:
        return memo[turn][i]
    best = abs(a[i] - a[n])
    for j in range(i + 1, n):
        pot = sol(j, 1 - turn)
        if turn == 0:
            best = max(best, pot)
        else:
            best = min(best, pot)
    memo[turn][i] = best
    return best

print(sol(0, 0))

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

Solution (Python):
N, Z, W = map(int, input().split())
*A, = map(int, input().split())

import sys
sys.setrecursionlimit(10**6)

memo = {}
def dfs(i, turn):
    if (i, turn) in memo:
        return memo[i, turn]
    if turn == 0:
        
        if i == 0:
            res = abs(W - A[-1])
        else:
            res = abs(A[i-1] - A[-1])
        for j in range(i+1, N):
            res = max(res, dfs(j, 1))
    else:
        
        if i == 0:
            res = abs(Z - A[-1])
        else:
            res = abs(A[i-1] - A[-1])
        for j in range(i+1, N):
            res = min(res, dfs(j, 0))
    memo[i, turn] = res
    return res
print(dfs(0, 0))

Solution (Python):
N, Z, W = map(int, raw_input().split())
A = map(int, raw_input().split())

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