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



Sample input:
3 100 100
10 1000 100


Sample output:
900

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
'''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)

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
#!/usr/bin/env 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

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

#最後のカードをどちらかが引くことになる
#Xが最後のカードまで一気に引く場合
score=abs(a[N-1]-W)

#Xが任意の枚数を取ってスコアを大きくする時、YはN-2番目まで取ってabs(a[N-2]-a[N-1])まではスコアを小さくすることができる。
#逆にYが任意の枚数を取ってスコアを小さくする時、Xはこの値までスコアを大きくできる。
#よって、Xが期待できるスコアの最大値はabs(a[N-2]-a[N-1])になる。
print(max(score,abs(a[N-2]-a[N-1])))

'''
drawcount=0 #2人が引いた枚数
score=[0]*N #XがN枚引いた時の最少スコアを格納
score[N-1]=abs(a[N-1]-W) #Xが全部引いた時のスコア

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

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)))

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

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

# Xが最後の1枚をとるとき
ans = abs(a[-1] - w)

# Yが最後の1枚をとるとき
ans = max(ans, abs(a[-1] - a[-2]))

print(ans)

Submission status: Accepted

Solution code:
#-*- coding:utf-8 -*-
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])))

Submission status: Accepted

Solution code:
#-*- coding:utf-8 -*-
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))

Submission status: Accepted

Solution code:
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)
        # X
        if no == 0:
            ans = max(ans, nex)
        # Y
        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()

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

N, Z, W = inpl()

A = inpl()

# X全取り
p1 = abs(A[-1] - W)

# X１残し
if N > 1:
    p2 = abs(A[-1] - A[-2])
else:
    p2 = p1

print(max(p1, p2))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env 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()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
#  --*-coding:utf-8-*--

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

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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)

# 4近傍（右, 下, 左, 上）
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()

Submission status: Accepted

Solution code:
#!/usr/bin/python
# coding: utf-8

from sys import stdin

def solve(a):
  n = len(a)
  xmemo = [0 for i in range(n)]  # player X の手番での最適スコア
  ymemo = [0 for i in range(n)]  # player Y 　　　〃

  # 自分がj (< i) 枚目, 相手がi枚目を持っている
  for i in range(n - 2, -1, -1):
    # 自分が取り切ったときのスコア
    f = abs(a[i] - a[n - 1])
    # j, i の差が何枚でも同じ
    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

# Z, Wを山の先頭に置く
a = [Z, W] + a

print(solve(a))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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])

    # print(D)
    # print(E)
    # print(D[N-1])

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# どちらか必ずa_Nのカードを持つ

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)

Submission status: Accepted

Solution code:
[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])

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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


# F[i] 表示y手里是i，x的最优解

Submission status: Accepted

Solution code:
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):
    # ovaj drugi ima a[i]
    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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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:
        # X
        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:
        # Y
        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))

Submission status: Accepted

Solution code:
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]))

Submission status: Runtime Error

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

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

dp = np.full((N+1,N+1),np.NaN,dtype = np.int64) #dp[i][j]:=xがi,yがjの時からの最善手のスコア
for i in reversed(range(N)):
    for j in reversed(range(N)):
        if i==0 and j ==0:
            ian = np.nanmax(dp)
            dp[0][0] = np.nanmax(np.array([ian,abs(W-Als[N-1])]))
        if  i < j:
            if j == N-1:
                dp[i][j] = abs(Als[N-1]-Als[i])
            else:
                bdp = dp[i:][j:]
                ban = np.nanmax(bdp)
                dp[i][j] = np.nanmax(np.array([abs(Als[N-1]-Als[j]),ban]))

        if  j < i:
            if i == N-1:
                dp[i][j] = abs(Als[N-1]-Als[j])
            else:
                cdp = dp[i:][j:]
                can = np.nanmin(cdp)
                dp[i][j] = np.nanmin(np.array([abs(Als[N-1]-Als[i]),can]))


print(dp[0][0])

Submission status: Runtime Error

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

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

dp = np.full((N+1,N+1),np.NaN,dtype = np.int64) #dp[i][j]:=xがi,yがjの時からの最善手のスコア
for i in reversed(range(N)):
    for j in reversed(range(N)):
        if i==0 and j ==0:
            ian = np.nanmax(dp)
            dp[0][0] = np.nanmax(np.array([ian,abs(W-Als[N-1])]))
        if  i < j:
            bdp = dp[i:][j:]
            ban = np.nanmax(bdp)
            dp[i][j] = np.nanmax(np.array([abs(Als[N-1]-Als[j]),ban]))
        if  j < i:
            cdp = dp[i:][j:]
            can = np.nanmin(cdp)
            dp[i][j] = np.nanmin(np.array([abs(Als[N-1]-Als[i]),can]))

print(dp[0][0])

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
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):
    # print('x={}, y={}, c={}, f={}'.format(x, y, c, f))
    if (x, y, c, f) in d:
        return d[(x, y, 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[(x, y, c, f)] = ret
    return ret

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N, Z, W = [int(x) for x in input().strip().split()]
a = [int(x) for x in input().strip().split()]

def minmax(x, y, c, f):
    # print('x={}, y={}, c={}, f={}'.format(x, y, 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))
    return ret

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

Submission status: Runtime Error

Solution code:
N, Y, Z = map(int, input().split())
As = list(map(int, input().split()))
dpx, dpy = [0]*(N-1), [0]*(N-1)
#dpx[i] = min(dpy[i+1]...dpy[N-2], abs(As[N-1]-As[i]))
#dpy[i] = max(dpx[i+1]...dpx[N-2], abs(As[N-1]-As[i]))
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]))
#print(dpx)
print(max(max(dpx),abs(As[N-1]-Z)))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:
n,z,w = map(int,raw_input().split())
arr = map(int,raw_input().split())
print max(abs(arr[-1]-w),abs(arr[-1]-arr[-2]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

memo = [[None for _ in range(2)] for _ in range(N + 1)]


def f(i, p, x, y):
    """
    i番目にx, yが手持ちのとき、プレイヤーpが引いたときのスコア
    """
    if i == N:
        return abs(x - y)
    if memo[i][p]:
        return memo[i][p]

    if p == 0:
        score = float('-inf')
        for j in range(i, N):
            score = max(score, f(j + 1, 1, A[j], y))
        memo[i][p] = score
        return score
    else:
        score = float('inf')
        for j in range(i, N):
            score = min(score, f(j + 1, 0, x, A[j]))
        memo[i][p] = score
        return score


print(f(0, 0, Z, W))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
    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))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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

Submission status: Runtime Error

Solution code:
N, Z, W = map(int, input().split())
aa = list(map(int, input().split()))
aa = [W] + aa
N += 1

dp = [[-1] * N for i in range(2)]
def dfs(xy, n, prev):
    index = n
    if dp[xy][n] != -1:
        return dp[xy][n]

    if xy == 0:
        m = 0
    else:
        m = 1 << 64

    for i in range(n+1, N):
        if i == N-1:
            r = aa[prev]
        else:
            r = dfs((xy+1)%2, i, n)

        if xy == 0 and m < abs(aa[i] - r):
            m = abs(aa[i] - r)
            index = i
        elif xy == 1 and m > abs(aa[i] - r):
            m = abs(aa[i] - r)
            index = i
    dp[xy][n] = aa[index]
    if xy == 0 and n == 0:
        print(abs(aa[index] - dfs(1, index, n)))
    return aa[index]

dfs(0, 0, 0)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
INF = 1e14

def minim(base,x,y,a):
    score = INF
    n = len(base)-a
    if n == 0:
        return abs(x-y)
    for i in range(n):
        _sc = maxim(base,x,base[i+a],i+a+1)
        if score > _sc:
            score = _sc

    return score


def maxim(base,x,y,a):
    score = 0
    n = len(base)-a
    if n == 0:
        return abs(x-y)
    for i in range(n):
        _sc = minim(base,base[i+a],y,i+a+1)
        if score < _sc:
            score = _sc

    return score

if __name__ == '__main__':
    n,x,y = map(int, input().split(" "))
    a = list(map(int, input().split(" ")))
    ret = [None for _ in range(n)]
    print(maxim(a,x,y,0))

Submission status: Runtime Error

Solution code:
INF = 1e14

def minim(x,y,a):
    score = INF
    n = len(a)
    if n == 0:
        return abs(x-y)
    for i in range(n):
        _sc = maxim(x,a[i],a[i+1:])
        if score > _sc:
            score = _sc

    return score


def maxim(x,y,a):
    score = 0
    n = len(a)
    if n == 0:
        return abs(x-y)
    for i in range(n):
        _sc = minim(a[i],y,a[i+1:])
        if score < _sc:
            score = _sc

    return score

if __name__ == '__main__':
    n,x,y = map(int, input().split(" "))
    a = list(map(int, input().split(" ")))
    ret = [None for _ in range(n)]
    print(maxim(x,y,a))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

@functools.lru_cache()
def solve(x_turn, idx, x, y):
    if idx == n:
        return abs(x-y)
    if x_turn:
        score = [solve(False, i+1, a[i], y) for i in range(idx, n)]
        return max(score)
    else:
        score = [solve(True, i+1, x, a[i]) for i in range(idx, n)]
        return min(score)

print(solve(True, 0, x, y))