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):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,z,w=map(int,input().split()) 
    A=[w]+list(map(int,input().split()))
    dp=[[None]*2 for _ in range(n+1)] 

    def dfs(i,turn)->NoneType:
        if(dp[i][turn] is not None): return

        
        for j in range(i+1,n):
            dfs(j,1-turn)

        res=-INF if(turn==0) else INF
        if(turn==0):
            for j in range(i+1,n):
                res=max(res,dp[j][1])
            res=max(res,abs(A[-1]-A[i]))
        else:
            for j in range(i+1,n):
                res=min(res,dp[j][0])
            res=min(res,abs(A[-1]-A[i]))
        dp[i][turn]=res

    dfs(0,0)
    print(dp[0][0])
resolve()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,z,w=map(int,input().split())
    A=list(map(int,input().split()))
    dp=[[None]*2 for _ in range(n+1)] 

    def dfs(i,turn)->NoneType:
        if(dp[i][turn] is not None): return

        
        for j in range(i+1,n):
            dfs(j,1-turn)

        res=-INF if(turn==0) else INF
        if(turn==0):
            for j in range(i+1,n):
                res=max(res,dp[j][1])
            y=A[i-1] if(i!=0) else w
            res=max(res,abs(A[-1]-y))
        else:
            for j in range(i+1,n):
                res=min(res,dp[j][0])
            x=A[i-1]
            res=min(res,abs(A[-1]-x))
        dp[i][turn]=res

    dfs(0,0)
    print(dp[0][0])
resolve()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,z,w=map(int,input().split())
    A=list(map(int,input().split()))
    dp=[[None]*2 for _ in range(n+1)] 

    def dfs(i,turn):
        if(dp[i][turn] is not None): return

        
        for j in range(i+1,n):
            dfs(j,1-turn)

        res=-INF if(turn==0) else INF
        if(turn==0):
            for j in range(i+1,n):
                res=max(res,dp[j][1])
            y=A[i-1] if(i!=0) else w
            res=max(res,abs(A[-1]-y))
        else:
            for j in range(i+1,n):
                res=min(res,dp[j][0])
            x=A[i-1] if(i!=0) else z 
            res=min(res,abs(A[-1]-x))
        dp[i][turn]=res

    dfs(0,0)
    print(dp[0][0])
resolve()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,z,w=map(int,input().split())
    A=list(map(int,input().split()))
    dp=[[None]*2 for _ in range(n+1)] 

    def dfs(i,turn)->NoneType:
        if(dp[i][turn] is not None): return

        
        for j in range(i+1,n):
            dfs(j,1-turn)

        res=-INF if(turn==0) else INF
        if(turn==0):
            for j in range(i+1,n):
                res=max(res,dp[j][1])
            y=A[i-1] if(i!=0) else w
            res=max(res,abs(A[-1]-y))
        else:
            for j in range(i+1,n):
                res=min(res,dp[j][0])
            x=A[i-1] if(i!=0) else z 
            res=min(res,abs(A[-1]-x))
        dp[i][turn]=res

    dfs(0,0)
    print(dp[0][0])
resolve()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    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[-2]-A[-1])))
resolve()

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
 
N,X,Y=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
 
memo={}
def func(n,last,turn):  
    
    if (n,turn) in memo:    
        return memo[(n,turn)]
    if n==1:
        ret=abs(last-A[N-n])
    elif turn==0:
        ret=max( func(n-1,last,0) , func(n-1,A[N-n],1) ) 
    elif turn==1:
        ret=min( func(n-1,last,1) , func(n-1,A[N-n],0) ) 
    memo[(n,turn)]=ret
    return ret
 
 
print func(N,Y,0)

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

Solution (Python):

import sys
sys.setrecursionlimit(10000000)

N,X,Y=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

memo={}
def func(n,last,turn):  
    
    if (n,turn) in memo:    
        return memo[(n,turn)]
    if n==1:
        ret=abs(last-A[N-n])
    elif turn==0:
        ret=max( func(n-1,last,0) , func(n-1,A[N-n],1) ) 
    elif turn==1:
        ret=min( func(n-1,last,1) , func(n-1,A[N-n],0) ) 
    memo[(n,turn)]=ret
    return ret


print func(N,Y,0)

Solution (Python):

import sys
sys.setrecursionlimit(10000000)

N,X,Y=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

memo={}
def func(n,last,turn):  
    
    if (n,turn) in memo:    
        return memo[(n,turn)]
    if n==1:
        ret=abs(last-A[N-n])
    elif turn==0:
        ret=max( func(n-1,last,0) , func(n-1,A[N-n],1) ) 
    elif turn==1:
        ret=min( func(n-1,last,1) , func(n-1,A[N-n],0) ) 
    memo[(n,turn)]=ret
    return ret


print func(N,Y,0)

Solution (Python):

import sys
sys.setrecursionlimit(10000000)

N,X,Y=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

memo={}
def func(n,last,turn):  
    
    if (n,turn) in memo:
        return memo[(n,turn)]
    if n==1:
        ret=abs(last-A[N-n])
    elif turn==0:
        ret=max( func(n-1,last,0) , func(n-1,A[N-n],1) ) 
    elif turn==1:
        ret=min( func(n-1,last,1) , func(n-1,A[N-n],0) ) 
    memo[(n,turn)]=ret
    return ret


print func(N,Y,0)

Solution (Python):
import sys
read = sys.stdin.read

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

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

Solution (Python):
def examD():
    N, Z, W = LI()
    A = LI()
    if N>=2:
        ans = max(abs(A[-2]-A[-1]),abs(A[-1]-W))
    else:
        ans = abs(A[0]-W)
    print(ans)

import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Solution (Python):

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,Z,W = inpl()
aa = inpl()

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

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

Solution (Python):
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
ans = abs(W-a[-1])
for i in range(N-1):
    hoge = abs(a[i]-a[-1])
    for j in range(i+1,N-1):
        hoge = min(hoge,abs(a[-1]-a[j]))
    ans = max(ans,hoge)
print(ans)

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

if N > 1:
    last = A[-1]
    ans = max(abs(W-last), abs(A[-2]-last))
    i = N-2
    while i > 0:
        if A[i] == last:
            ans = max(ans, A[i-1]-last)
            i -= 1
        else:
            i = 0
else:
    ans = abs(W-A[0])
    
print(ans)

Solution (Python):

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

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

else:
    print (abs(W-a[0]))

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[-2] - a[-1])))

Solution (Python):


n, x, y = map(int, input().split())
a = tuple(map(int, input().split()))

if n == 1:
    print(abs(a[-1] - y))
else:
    print(max(abs(a[-1] - y), abs(a[-2] - a[-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[-1]-w),abs(a[-1]-a[-2])))

Solution (Python):
import sys
n, z, w = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
if n > 1 and abs(a_ls[-1] - w) < abs(a_ls[-2] - a_ls[-1]):
    x = a_ls[-2]
    y = a_ls[-1]
else:
    x = a_ls[-1]
    y = w
print(abs(x - y))

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

Solution (Python):
inpl = lambda: list(map(int,input().split()))
N, Z, W = inpl()
a = inpl()[::-1]
a.append(W)

X = Y = Xmin = Ymax = abs(a[0]-a[1])
for i in range(2,N+1):
    X = max(Ymax,abs(a[i]-a[0]))
    Y = min(Xmin,abs(a[i]-a[0]))
    Ymax = max(Ymax, Y)
    Xmin = min(Xmin, X)
print(X)

Solution (Python):
inpl = lambda: list(map(int,input().split()))
N, Z, W = inpl()
a = inpl()[::-1]
a.append(W)
X = [0]*(N+1)
Y = [10**9]*(N+1)
if N == 1:
    print(abs(W-a[0]))
    exit()

Xmin = Ymax = abs(a[0]-a[1])
for i in range(2,N+1):
    X = max(Ymax,abs(a[i]-a[0]))
    Y = min(Xmin,abs(a[i]-a[0]))
    Ymax = max(Ymax, Y)
    Xmin = min(Xmin, X)
print(X)

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

Solution (Python):
N, Z, W  = map(int, input().split())
a = [int(i) for i 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):

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()))
t = 0
if n>1 :t = abs(a[-1]-a[-2])
print(max(abs(a[-1]-w),t))

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

Solution (Python):
N, _, y = map(int, input().split())
a = list(map(int, input().split()))

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

Solution (Python):

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

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

print(ans)

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

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

    ans = 0
    for i in range(N-1):
        s = INF
        for j in range(i+1, N):
            if j < N-1:
                s = min(s, abs(A[j]-A[N-1]))
            else:
                s = min(s, abs(A[j]-A[i]))
        ans = max(s, ans)

    ans = max(ans, abs(A[N-1]-W))

    print(ans)

if __name__ == "__main__":
    main()

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 = 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])))

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, _, W = MAP()
A = [W] + LIST()


memo = list2d(2, N+1, None)
def rec(turn, cnt):
    if memo[turn][cnt] is not None:
        return memo[turn][cnt]
    
    if turn % 2 == 0:
        res = -INF
        for nxt in range(cnt+1, N):
            res = max(res, rec(1-turn, nxt))
        
        res = max(res, abs(A[N]-A[cnt]))
    
    else:
        res = INF
        for nxt in range(cnt+1, N):
            res = min(res, rec(1-turn, nxt))
        res = min(res, abs(A[cnt]-A[N]))
    memo[turn][cnt] = res
    return res

ans = rec(0, 0)
print(ans)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, _, W = MAP()
A = [W] + LIST()


memo = list2d(2, N+1, None)
def rec(turn, cnt):
    if memo[turn][cnt] is not None:
        return memo[turn][cnt]
    
    if turn % 2 == 0:
        res = -INF
        for nxt in range(cnt+1, N):
            res = max(res, rec(1-turn, nxt))
        
        res = max(res, abs(A[N]-A[cnt]))
    
    else:
        res = INF
        for nxt in range(cnt+1, N):
            res = min(res, rec(1-turn, nxt))
        res = min(res, abs(A[cnt]-A[N]))
    memo[turn][cnt] = res
    return res

ans = rec(0, 0)
print(ans)

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

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

Solution (Python):
import sys
input = sys.stdin.readline
n,x,y=[int(j) for j in input().split()]
a=[int(j) for j in input().split()]
a=[y]+a
print(max(abs(y-a[-1]),abs(a[-2]-a[-1])))

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

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()))
dp1 = [0]*N
dp2 = [0]*N
dp1[N-2] = dp2[N-2] = abs(a[N-2]-a[-1])
for i in range(N-2)[::-1]:
    dp1[i] = max(abs(a[i]-a[-1]), max(dp2[j] for j in range(i+1, N-1)))
    dp2[i] = min(abs(a[i]-a[-1]), min(dp1[j] for j in range(i+1, N-1)))
if N==1:
    ans = abs(W-a[-1])
else:
    ans = max(abs(W-a[-1]), max(dp2[i] for i in range(N-1))) 
print(ans)

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):
N, Z, W = map(int,input().split())
A = list(map(int,input().split()))

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

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

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

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

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

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

memoX = {}
memoY = {}
memo = 0

def X(n,z,w):
    score = 0
    if n == 0:
        if not (0,z,w) in memoX:
            memoX[(0,z,w)] = abs(z-w)
        return abs(z-w)
    else:
        if (n,w) in memoX:
            global memo
            memo += 1
            return memoX[(n,w)]
        else:
            for i in range(n):
                tmp = Y(i,A[N-1-i],w)
                if score < tmp:
                    score = tmp
            memoX[(n,w)] = score
            return score

def Y(n,z,w):
    score = float("inf")
    if n == 0:
        if not (0,z,w) in memoY:
            memoY[(0,z,w)] = abs(z-w)
        return abs(z-w)
    else:
        if (n,z) in memoY:
            global memo
            memo += 1
            return memoY[(n,z)]
        else:
            for i in range(n):
                tmp = X(i,z,A[N-1-i])
                if score > tmp:
                    score = tmp
            memoY[(n,z)] = score
            return score
    
ans = X(N,Z,W)



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))
else:
    print(max(abs(A[-1] - w), abs(A[-2] - A[-1])))

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

dp = [[0]*2 for i in range(n)]
for i in range(n-1, -1, -1):
    
    
    x = a[i-1] if i else w
    
    dp[i][0] = abs(a[-1] - x)
    
    for j in range(i+1, n):
        dp[i][0] = max(dp[i][0], dp[j][1])

    
    
    x = a[i-1] if i else z
    dp[i][1] = abs(a[-1]-x)
    
    for j in range(i+1, n):
        dp[i][1] = min(dp[i][1], dp[j][0])
print(dp[0][0])

Solution (Python):
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):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
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:
    print(abs(a[-1] - w))
else:
    print(max(abs(a[-1]-w),abs(a[-2]-a[-1])))

Solution (Python):
import sys
input = sys.stdin.readline
def solve():
  n,z,w = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  if n == 1:
    ans = abs(w-a[0])
  else:
    ans = 0
    
    tmp = abs(a[n-2]-a[n-1])
    tmp2 = abs(a[n-1]-w)
    ans = max(tmp,tmp2)
  print(ans)
solve()

Solution (Python):
N,Z,W,*A=map(int,open(0).read().split());print(max(abs(A[-2%N]-A[-1]),abs(A[-1]-W)))

Solution (Python):
import sys,bisect as bs,collections as cl,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n,z,w =m()
a = l()
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())

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

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

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**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 II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main_old(): 
    N, _, W = LI()
    a = LI()

    
    res = abs(a[-1] - W)
    if N == 1:
        print(res)
        return
    res2 = abs(a[-1] - a[-2])

    
    max_li = [0, res, res2] + [0 for _ in range(N)]
    min_li = [INF, res, res2] + [INF for _ in range(N)]
    for i in range(3, N+1):
        take_all = abs(a[-i] - a[-1])
        max_li[i] = min([min_li[j] for j in range(2, i)]+[take_all])
        min_li[i] = max([max_li[j] for j in range(2, i)]+[take_all])

    print(max(max_li))

def main():
    N, _, W = LI()
    a = LI()

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

    
    res2 = abs(a[-1] - a[-2])

    
    
    

    print(max(res, res2))

main()

Solution (Python):
import sys
sys.setrecursionlimit(10**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 II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, _, W = LI()
    a = LI()

    
    res = abs(a[-1] - W)
    if N == 1:
        print(res)
        return
    res2 = abs(a[-1] - a[-2])

    
    max_li = [0, res, res2] + [0 for _ in range(N)]
    min_li = [INF, res, res2] + [INF for _ in range(N)]
    for i in range(3, N+1):
        take_all = abs(a[-i] - a[-1])
        max_li[i] = min([min_li[j] for j in range(2, i)]+[take_all])
        min_li[i] = max([max_li[j] for j in range(2, i)]+[take_all])

    print(max(max_li))


main()

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):
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):
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[-1] - W), abs(a[-2] - a[-1])))

if __name__ == "__main__":
    main()

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
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)]
mod = 1000000007


"""
x, y = LS()
if x > y:
    print(">")
elif x == y:
    print("=")
else:
    print("<")
"""


"""
x, y, z = LI()
print((x-z)//(y+z))
"""


"""
n, m = LI()
print((m*1900+(n-m)*100)*2**m)
"""




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

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

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline



n,z,w = [int(i) for i in readline().split()]
a = [w] + [int(i) for i in readline().split()]
n += 1

dps = [0]*(n)+[10**18]
dpg = [0]*(n+1)

for i in range(n-1,0,-1):
    dps[i] = max(max(dpg[j] for j in range(i+1,n+1)),abs(a[-1]-a[i-1]))
    dpg[i] = min(min(dps[j] for j in range(i+1,n+1)),abs(a[-1]-a[i-1]))
    

print(dps[1])

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

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,*l=map(int,open(0).read().split());print(max(abs(l[n]-l[n-1]),abs(l[n]-l[0])))

Solution (Python):
n,z,w,*l=map(int,open(0).read().split())
if len(l)<2:l+=[l[0]]
print(max(abs(l[-1]-l[-2]),abs(w-l[-1])))

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

if N == 1:
    print(abs(A_arr[0]-W))
else:
    print(max(abs(A_arr[-1]-W), abs(A_arr[-2]-A_arr[-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):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math






def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,Z,W = inputMap()
    A = inputList()
    
    if N ==1:
        print(abs(A[-1]-W))
    else:
        print(max(abs(A[-1]-W), abs(A[-2]-A[-1])))
    
    '''
    A_max = max(A)
    A_min = min(A)
    
    ans = 0
    tmp1 = abs(Z - A[-1])
    tmp2 = abs(A[-1] - W)
    tmp3 = abs(A_max - A[-1])
    tmp4 = abs(A[-1] - A_min)
    
    tmp5 = 0
    if A_max == A[-1] or A_min == A[-1]:
        tmp5 = abs(A_max - A_min)
    
    print(max(tmp1, tmp2, tmp3, tmp4, tmp5))
    '''
            	
if __name__ == "__main__":
	main()

Solution (Python):
*a,b=map(int,open(0).read().split());print(max(abs(a[-1]-b),abs(a[2]-b)))

Solution (Python):
*a,b=map(int,open(0).read().split());print(max(abs(a[-1]-b),abs(a[2]-b)))

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):
import sys
sys.setrecursionlimit(10 ** 5)

N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
a.reverse()
a += [W] 
dp_T = [-1] * (N + 1) 
dp_F = [-1] * (N + 1) 

def calc(n, flag): 
    
    if flag == True and dp_T[n] != -1:
        return dp_T[n]
    if flag == False and dp_F[n] != -1:
        return dp_F[n]

    if n == 1: 
        return abs(a[0] - a[n])
    if flag == True: 
        tmp = 0
        for i in range(1, n + 1): 
            if i == n: 
                tmp = max(tmp, abs(a[0]-a[n]))
            else: 
                tmp = max(tmp, calc(n-i, not flag))
        dp_T[n] = tmp
        return tmp
    if flag == False: 
        tmp = 10 ** 10 
        for i in range(1, n + 1): 
            if i == n - 1: 
                tmp = min(tmp, abs(a[0] - a[n]))
            else:
                tmp = min(tmp, calc(n-i, not flag))
        dp_F[n] = tmp
        return tmp

print (calc(N, True))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5)

N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
a.reverse()
a += [W] 
dp_T = [-1] * (N + 1) 
dp_F = [-1] * (N + 1) 

def calc(n, flag): 
    
    if flag == True and dp_T[n] != -1:
        return dp_T[n]
    if flag == False and dp_F[n] != -1:
        return dp_F[n]

    if n == 1: 
        return abs(a[0] - a[n])
    if flag == True: 
        tmp = 0
        for i in range(1, n + 1): 
            if i == n: 
                tmp = max(tmp, abs(a[0]-a[n]))
            else: 
                tmp = max(tmp, calc(n-i, not flag))
        dp_T[n] = tmp
        return tmp
    if flag == False: 
        tmp = 10 ** 10 
        for i in range(1, n + 1): 
            if i == n - 1: 
                tmp = min(tmp, abs(a[0] - a[n]))
            else:
                tmp = min(tmp, calc(n-i, not flag))
        dp_F[n] = tmp
        return tmp

print (calc(N, True))

Solution (Python):
n,x,y=map(int,input().split())
a=list(map(int,input().split()))
if len(a)==1:a=a+a
print(max(abs(y-a[-1]),abs(a[-1]-a[-2])))

Solution (Python):
n,z,w=map(int,input().split())
a_list=list(map(int,input().split()))
dp_m=[0]*n
for i in range(n-2,-1,-1):
    temp=10**10
    for j in range(i+1,n):
        if j==n-1:
            temp=min(temp,abs(a_list[i]-a_list[n-1]))
        else:
            temp2=max(abs(a_list[j]-a_list[n-1]),dp_m[j+1])
            temp=min(temp,temp2)
    dp_m[i]=max(dp_m[i+1],temp)
ans=max(dp_m[0],abs(a_list[n-1]-w))
print(ans)

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


if __name__ == "__main__":
    main()

Solution (Python):

import sys

def method_1(N, Z, W, a):
    return abs(a[-1]-W)


def method_2(N, Z, W, a):
    return abs(a[-2]-a[-1])




def solve(N: int, Z: int, W: int, a: "List[int]"):
    res = 0
    
    res = max(res,method_1(N,Z,W,a))
    if N >= 2:
        res = max(res,method_2(N,Z,W,a))

    print(res)



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)

if __name__ == '__main__':
    main()

Solution (Python):


def main():
    n, jibun, aite = map(int, input().split())
    data = list(map(int, input().split()))
    if n == 1:
        print(abs(aite - data[-1]))
    else:
        print(max(abs(aite - data[-1]), abs(data[-1] - data[-2])))



if __name__ == '__main__':
    main()