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: Runtime Error

Solution code:
from pprint import pprint
'''
## O(1)のパターン
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)))
'''
## DPを使って解くとき
N , Z , W = map(int , input().split())
a = list(map(int , input().split()))
a.reverse()
a += [W]
#print(a)
memo = [[-1]* (N + 1) , [-1] * (N + 1)]
def DP(n , turn):

    if n == 1:
        #print(memo[turn][n])
        return abs(a[0] - W)
    if memo[turn][n] != -1:
        return memo[turn][n]
    if turn == 1:
        #print("turn : 1")
        tmp_max = 0
        for i in range(1 , n + 1):
            if i == n:
                tmp_max = max(tmp_max , abs(a[0]-W))
            else:
                tmp_max = max(tmp_max , DP(n - 1,1 - turn))
        #print("tmp_max : ",tmp_max)
        memo[turn][n] = tmp_max
        return tmp_max
    if turn == 0:
        tmp_min = 10 ** 9
        #print("turn : 0")
        for i in range(1 , n + 1):
            if i == n:
                tmp_min = min(tmp_min , abs(a[0]-W))
            else:
                tmp_min = min(tmp_min , DP(n - 1,1 - turn))
        #print("tmp_min : ",tmp_min)
        memo[turn][n] = tmp_min
        return tmp_min



print(DP(N , 1))
#print(memo)

Submission status: Runtime Error

Solution code:
N, Z, W = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
#[abs(a-A[-1]) for a in A[i:-1]]が広義単調増加になるような最小のiを選ぶと、
#Xさんは最初にA[i]までとるのが最善策の候補
#このときYさんは最後までとるのが最善
#ただしabs(A[i]-A[-1])がWより小さいならXさんは最初に全部とってしまうのが最善
ans = 0
b = A[-1]
j = N - 2
for i in range(N - 3, -1, -1):
    if abs(A[i] - b) <= abs(A[i + 1] - b):
        j -= 1
    else:
        break
print(max(abs(A[i] - b), abs(W - b)))

Submission status: Runtime Error

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

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

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()
    
    A_max = max(A)
    A_min = min(A)
    
    tmp2 = abs(A[-1] - W)
    tmp3 = 0
    if A_max != A[-1]:
        tmp3 = abs(A_max - A[-1])
    tmp4 = 0
    if A_min != A[-1] and A_min != A[0]:
        tmp4 = abs(A[-1] - A_min)
    
    '''
    tmp5 = 0
    if A_max != A[-1] and A_min == A[-1]:
        tmp5 = abs(A_max - A_min)
        '''
    
    print(max(tmp2, tmp3, tmp4, tmp5))
            	
if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000)

N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
a.reverse()
a += [W] #最後にYさんの手札を加えておく
dp_T = [-1] * (N + 1) #Xの手番
dp_F = [-1] * (N + 1) #Yの手番

def calc(n, flag): #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: #山の残り枚数が1枚の時 -->引くしかなく得点が決定
        return abs(a[0] - a[n])
    if flag == True: #Xのターン-->大きくしたい
        tmp = 0
        for i in range(1, n + 1): #自分が引く枚数 = 1 ~ n枚
            if i == n: #残り枚数0で相手に渡す = 自分が最後の1枚を引く -->相手の手札が決まっているから得点が決定
                tmp = max(tmp, abs(a[0]-a[n]))
            else: #残り枚数が1枚以上ある時、手番は相手に変える
                tmp = max(tmp, calc(n-i, not flag))
        dp_T[n] = tmp
        return tmp
    if flag == False: #Yのターン-->小さくしたい
        tmp = 10 ** 10 #最大値
        for i in range(1, n + 1): #自分が引く枚数 = 1 ~ n枚
            if i == n - 1: #残り0枚で相手に渡す
                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))

Submission status: Runtime Error

Solution code:
n=int(input())
p=[list(map(int,input().split())) for _ in [0]*(n-1)]
g=[[] for _ in [0]*n]

[g[a-1].append(b-1) for a,b in p]
[g[b-1].append(a-1) for a,b in p]

memo=[False for _ in [0]*n]
q=[0]
memo[0]=True
last=0
while(q):
	qq=[]
	for i in q:
		for j in g[i]:
			if memo[j]==False:
				memo[j]=True
				last=j
				qq.append(j)
	q=qq

memo=[False for _ in [0]*n]
q=[last]
memo[0]=True
cnt=0
while(q):
	cnt+=1
	qq=[]
	for i in q:
		for j in g[i]:
			if memo[j]==False:
				memo[j]=True
				qq.append(j)
	q=qq
	
if cnt%3==2:
	print('Second')
else:
	print('First')

Submission status: Runtime Error

Solution code:
N,Z,W=map(int, input().split())
INL = list(map(int,input().split()))
INVL = {v:i for i, v in enumerate(INL)}

class BitMAX:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s = max(self.tree[i],s)
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = max(x, self.tree[i])
            i += i & -i
    
    def reset(self):
        t = self.tree
        for i in range(len(t)):
            t[i] = 0

class BitMIN:
    def __init__(self, n):
        self.size = n
        self.tree = [10**9+1] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s = min(self.tree[i],s)
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = min(x, self.tree[i])
            i += i & -i
    
    def reset(self):
        t = self.tree
        for i in range(len(t)):
            t[i] = 0

bit_max = BitMAX(3000)
bit_min = BitMIN(3000)

offset = 2500

for i, v in enumerate(INL):
    bit_max.add(offset-i, v)
    bit_min.add(offset-i, v)

pos = 0
while pos < len(INL):
    ma = bit_max.sum(offset-pos)
    mi = bit_min.sum(offset-pos)
    if abs(W-ma) > abs(W-mi):
        Z = ma
        pos = INVL[ma]+1
    else:
        Z = mi
        pos = INVL[mi]+1
    # print("A pos: {}".format(pos))

    if pos < len(INL):
        ma = bit_max.sum(offset-pos)
        mi = bit_min.sum(offset-pos)
        if abs(Z-ma) < abs(Z-mi):
            W = ma
            pos = INVL[ma]+1
        else:
            W = mi
            pos = INVL[mi]+1
        # print("B pos: {}".format(pos))

print(abs(Z-W))

Submission status: Runtime Error

Solution code:
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
fin = open('in_4.txt', 'r')
sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"

    # write code
    # †私は証明のない決め打ちを提出しました†
    if N == 1:
        print(abs(a[-1]-W))
    elif 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:
#
#　　　　　　　　　　　　　　,. -─────────‐- .、
#　　　　　　　　　　　　 ／／￣￣＼　　　　　　／￣￣＼＼
#　　　　　　　　　　　／　　　　　　　　　　　　　　　　　　　　 ＼
#　　　　　　　　　 ／　　　　　　　　::::::::::::::::::::::::::::::::　　　　　　　＼
#　　　　　　　　／ 　　／ ／￣＼＼::::;;;;;;;;;;;;;;;;;:::::／／￣＼＼　　＼
#　　　　　　 ／　　　　|　 |.　┃　.|　| ::::;;;;;;;;;;;;;::::｜ |.　┃　.|　|　　　 ＼　　　　　　　　　　　　　　　　　　　　　
#　　　　　／ 　　　　　＼ ＼＿／／　::::::::::::::::::　＼＼＿／／　　　　　 ＼　　　　
#　　　 ／　　　　　..／￣￣＼　／　　　::｜::　　　＼　／￣￣＼..　　　　　＼
#　　 / 　 　 　 　 :::::　　　　　　|　　　　　 |　　　　　 |　　　　　　 :::::　　　　　 ヽ.　　　
#　　| 　　　　　　　　　　　　　　|　　　　　 |　　　　　 |　　　　　　　　　　　　　　|.
#　　| 　　　　　　　　　　　　　　＼＿＿／＼＿＿／ 　　　　　　　　　　　　　　|　　　　　　　　　　　　　　　　　
#　　| 　　　　　　　　　　　　　　　｜　　　　　　　｜　　　　　　　　　　　　　　　|
#　　| 　　　　　　　　　　　　　　　｜r─‐┬──､|　　　　　　　　　　　　　　　 |
#　　ヽ　　　　　　　　　　　　　　　 |/　　　|　　 　｜　　　　　　　　　　　　　　/
#　　　 ＼　　　　　　　　　　　　　 ＼　　　　　　／　　　　　　　　　　　　　／
#　　　　　＼ 　　　　　　　　　　　　　￣￣￣￣　　　　　　　　　　　　　／
#
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N, _, W = MI()
    A = LI()
    
    #初手で前取りか寸止め侍かするのと同じ(２手目で同じことがされてしまうから)
    print(max(abs(W-A[-1]), abs(A[-1]-A[-2]) ))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
"""
n=1の時、山札とＹの初期手札が答え
n>=2の時、
・Ｘは得点の最大化を狙う
・Ｙは得点の最小化を狙う＝Ｘの邪魔をする
山札内の得点の最大化をできるカードをＸが選んでも、Ｙはそれを邪魔する動きをとるので、真に最大化すること(Xの狙いを達成すること)はできない
→選べるのはＹの初期値＆山札最後（Ｘがすべて取る）か、最後とその一つ手前の比較（Ｘが一枚残してすべて取る）のどちらかにするのがましな選択



"""


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

Submission status: Runtime Error

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

score = []

# only X
score.append(abs(a[-1] - w))

if n > 1:
    # X -> Y
    score.append(abs(a[i] - a[-1]))

print(max(score))

Submission status: Runtime Error

Solution code:
n,z,w=map(int,input().split())
a=[int(i) for i in input().split()]
if n>=2:
    print(max(abs(a[-1]-w),abs(a[-1]-a[-2]) ))
else:
    print(max(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[-1]-a[-2]) ))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A,B,C=map(int,input().split())
N=[ _ for _ in map(int, input().split())]
N.reverse


Max=0
Min=100000000000000000



for i in N:
  if Max<i:
    Max=i
  if Min>i:
    Min=i
G=max(N[-1],B)
H=min(N[-2],C)

if Max< G:
  Max=G
elif Min>H:
  Min=H
print(Max-Min)

Submission status: Runtime Error

Solution code:
a,b,c = int(input().split())
z = [int(input().split())]
if a == 1:
  sco = abs(z-c)
else:
  if abs(z[-1] - c) > abs(z[-2] - z[-1]):
    sco = abs(z[-1] - c)
  else:
    sco = abs(z[-2] - z[-1])
    
print(sco)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#078-C 
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,z,w=IL()
a=IL()
print(max(abs(a[-1]-w),abs(a[-1]-a[-2])))

Submission status: Runtime Error

Solution code:

a,b,c=map(int,input().split())
x = list(map(int,input().split()))
print(max(abs(b-x[-1]),abs(x[-1]-x[-2])))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

Solution code:
n, z, w = map(int, input().split())
aList = list(map(int, input().split()))
INF = 10 ** 20

def check(xScore, yScore, pointer, turn):
    if pointer == n:return abs(xScore - yScore)
    if turn == 0:
        ret = 0
        for nextPointer in range(pointer, n):
            ret = max(ret, check(aList[nextPointer], yScore, nextPointer + 1, 1))
    else:
        ret = INF
        for nextPointer in range(pointer, n):
            ret = min(ret, check(xScore, aList[nextPointer], nextPointer + 1, 0))

    return ret

print(check(z, w, 0, 0))

Submission status: Runtime Error

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

cache = {}

def f(idx, turn, x, y):
    if idx == n:
        return abs(x - y)
    
    key = (idx, turn)
    if key in cache:
        return cache[key]

    if turn == 0:
        ans = -float('inf')
        for i in range(idx, n):
            ans = max(ans, f(i + 1, 1 - turn, a[i], y))
    else:
        ans = float('inf')
        for i in range(idx, n):
            ans = min(ans, f(i + 1, 1 - turn, x, a[i]))

    cache[key] = ans
    return cache[key]



print(f(0, 0, z, w))

Submission status: Runtime Error

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

# 再帰呼び出しの回数制限(デフォルト1000)
sys.setrecursionlimit(10 ** 9)

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

def dfs(turn, rest, x, y):
    if rest == 0:
        return abs(x - y)
    if turn % 2 == 0:
        mx = -1
        for i in range(N-rest, N):
            x = aN[i]
            idx = i+1
            mx = max(dfs(turn+1, N-idx, x, y), mx)
        return mx
    else:
        mn = float('inf')
        for i in range(N-rest, N):
            y = aN[i]
            idx = i+1
            mn = min(dfs(turn+1, N-idx, x, y), mn)
        return mn

print(dfs(0, N, Z, W))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
 
N, Z, W = map(int, input().split())
aN = list(map(int, input().split()))

def dfs(turn, rest, x, y):
    if rest == 0:
        return abs(x - y)
    if turn % 2 == 0:
        mx = -1
        for i in range(N-rest, N):
            x = aN[i]
            idx = i+1
            mx = max(dfs(turn+1, N-idx, x, y), mx)
        return mx
    else:
        mn = float('inf')
        for i in range(N-rest, N):
            y = aN[i]
            idx = i+1
            mn = min(dfs(turn+1, N-idx, x, y), mn)
        return mn

print(dfs(0, N, Z, W))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

memo = {}
def act(xlast, ylast, turn):
    x = z if xlast == -1 else aa[xlast]
    y = w if ylast == -1 else aa[ylast]

    if xlast == n - 1 or ylast == n - 1:
        return abs(x - y)
    
    if (xlast, ylast, turn) in memo:
        return memo[(xlast, ylast, turn)]
    
    if turn == 0:
        # x turn
        ans = 0
        for i in range(ylast + 1, n):
            ans = max(ans, act(i, ylast, 1))
    else:
        # y turn
        ans = 1 << 30
        for i in range(xlast + 1, n):
            ans = min(ans, act(xlast, i, 0))
    
    memo[(xlast, ylast, turn)] = ans
    return ans

print(act(-1, -1, 0))

Submission status: Runtime Error

Solution code:
def d_abs(N, Z, W, A):
    # 山札の枚数が1枚なら、Xがそれを引いて終わる。山札が2枚以上なら、
    # Xは初手でN-1枚目かN枚目かのどちらかスコアが大きくなる方を取るのが最善。
    # そうしなかった場合、Xが最善手を取らなかったことになって前提に反するか、
    # Yが最善手を取ってスコアabs(A[N - 1] - A[N - 2])になるかのどちらかである
    ans = abs(A[0] - W) if N == 1 else max(abs(A[N - 1] - W), abs(A[N - 1] - A[N - 2]))
    return ans

N,Z,W = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(D_abs(N, Z, W, A))

Submission status: Runtime Error

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

x=0
y=0
a.sort()
i=n-1
while (i>0):
  if a[i-1]==a[i]:
    x=y
    y=a[i]
    if x>0:
      break
    i-=2
  else:
    i-=1

print(x*y)

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


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))
    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 = [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))
    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()))
L = []
D = []
def rec(x, y, n, turn):
    xp, yp = x, y
    C = []
    for i in range(n+1, N+1):
        x, y = xp, yp
        if i == N:
            C.append(abs(A[-1]-y if turn else x-A[-1]))
            continue
        if turn:
            x = A[i-1]
        else:
            y = A[i-1]
        if [x, y, i, not turn] in L:
            C.append(D[L.index([x, y, i, not turn])])
        else:
            C.append(rec(x, y, i, not turn))
    ret = max(C) if turn else min(C)
    L.append([xp, yp, n, turn])
    D.append(ret)
    return ret


print(rec(Z, W, 0, True))

Submission status: Runtime Error

Solution code:
N,Z,W = map(int,input().split())
a = list(map(int,input().split()))
amax = max(*a,Z,W)
amin = min(*a,Z,W)
alast = a[N-1]
if N == 1:
    print(abs(W-a[0]))
    exit()
print(max(amax-alast,amin-alast))

Submission status: Runtime Error

Solution code:
N,Z,W = map(int,input().split())
a = list(map(int,input().split()))
owa = len(a)
dai = abs(Z-W)
syou = abs(Z-W)
if abs(Z - W) >= abs(min(a) - max(a)):
    a =  []
while a:
  for i in range(len(a)):
    if dai <= abs(a[i] - W):
      dai = max(abs(a[i] - W),dai)
      iti = i + 0
  Z = a[iti]
  if iti == owa: break
  a = a[iti+1:]
  for i in range(len(a)):
    if dai >= abs(a[i] - Z):
      dai = min(abs(a[i] - Z),dai)
      iti = i + 0
  if a == []: break
  W = a[iti]
  if iti == owa: break
  a = a[iti+1:]

print(abs(Z-W))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
if len(a)==1: print(abs(a[-1]-w))
elif abs(a[-2]-a[-1])>abs(a[-1]-w):
    print(abs(a[-2]-a[-1]))
else: print(abs(a[-1]-w))

Submission status: Runtime Error

Solution code:
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
a[-1], b = w, a[-1]
print(max((x-b) if x > a else b-x for x in a))

Submission status: Runtime Error

Solution code:
import numpy as np


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

f = []

if N > 2:
    for i in range(0, 2**(N-1)): # 1 枚目は必ず X
        string = str(bin(i))[2:]
        f.append(['1'] + ['0'] * (N - 1 - len(string)) + list(string))
else:
    f = ['1']

F = np.array(f)
F = (F == '1')


R = []

for i in range(len(F)):
    X_max = max(Z, np.array(A)[F[i]].max())
    try:
        Y_min = min(W, np.array(A)[F[i]==False].min())
    except:
        Y_min = W
    R.append(abs(X_max-Y_min))

print(max(R))

Submission status: Runtime Error

Solution code:
cm = None
cM = None
def m(a, n, i, w):
    if w in cm[i]: return cm[i][w]
    m = abs(a[n - 1] - w)
    for k in range(i, n - 1):
        m = min(m, abs(M(a, n, k + 1, a[k])))
    cm[i][w] = m
    return m

def M(a, n, i, w):
    if w in cM[i]: return cM[i][w]
    M = abs(a[n - 1] - w)
    for k in range(i, n - 1):
        M = max(M, abs(m(a, n, k, a[k])))
    cM[i][w] = M
    return M

n, z, w = map(int, raw_input().split())
a = map(int, raw_input().split())
cm = [dict() for _ in range(n)]
cM = [dict() for _ in range(n)]
print M(a, n, 0, w)

Submission status: Runtime Error

Solution code:
def max(a,b):
  	if a>=b:
      	return a
    else:
      	return b

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: Runtime Error

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

l0=abs(a[-1]-a[-2])
l1=abs(a[-1]-w)

if l1>l0:
  print(l1)
else:
  print(l0)

Submission status: Runtime Error

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

def ans(Z,W,A):
    length=len(A)
    if length==0:
        return abs(Z-W)
    else:
        i_list=[]
        for i in range(length):
            j_list=[]
            for j in range(length-i-1):
                j_list.append(ans(A[i],A[i+j+1],A[i+j+2:]))
            try:
                i_list.append(min(j_list))
            except:
                i_list.append(abs(A[length-1]-W))
        return(max(i_list))

print(ans(Z,W,a))

Submission status: Runtime Error

Solution code:
def getNum():
    N,Z,W = map(int,input().split())
    cards = input()
    cards = cards.split()
    return N,Z,W,cards

def cal(N,Z,W,cards):
    cand1 = abs(W - int(cards[-1]))
    cand2 = abs(int(cards[-1]) - int(cards[-2]))
    if cand1 >= cand2:
        print(cand1)
    else:
        print(cand2)

def main():
    N,Z,W,cards = getNum()
    cal(N,Z,W,cards)

main()

Submission status: Runtime Error

Solution code:
s1 = input()
s2 = input()

x, y, z = [int(i) for i in s1.split()]
l = [int(i) for i in s2.split()]
 
if x = 1:
  print(abs(z - l[x-1]))
else:
  if abs(z - l[x-1]) > abs(l[x-1] - l[x-2]):
    print(abs(z - l[x-1]))
  else:
    print(abs(l[x-1] - l[x-2]))

Submission status: Runtime Error

Solution code:
x, y, z = [int(i) for i in s.split()]
l = [int(i) for i in s.split()]

if x = 1:
  print(abs(z - l[x-1]))
else:
  if abs(z - l[x-1]) > abs(l[x-1] - l[x-2]):
    print(abs(z - l[x-1]))
  else:
    print(abs(l[x-1] - l[x-2]))

Submission status: Runtime Error

Solution code:
def D_abs(N, Z, W, A):
    if N == 1:
        # Xは山札のたった1枚を引かねばならず、Yは山札から1枚も引けないから
        return abs(A[0] - W)
    else:
        # 山札は一番上しか見れないので、
        # Xがa_{N-1}を持ち、Yがa_{N}を持つか、
        # Xがa_{N}を持ち、YがWまたはa_{N-1}を持つかの
        # どちらかで終了する。
        return max(abs(A[N - 1] - W), abs(A[N - 1] - A[N - 2]))

N,Z,W = [int(_) for _ in input().split()]
A = [int(input()) for _ in range(N)]
print(D_abs(N, Z, W, A))

Submission status: Runtime Error

Solution code:
nzw = input().split()
n = int(nzw[0])
z = int(nzw[1])
w = int(nzw[2])
an = input().split()
turn_x = True
now_idx = 0
for j in range(n):
    tmp_idx = now_idx
    if(turn_x):
        max_dif = -1
        for i in range(now_idx, n):
            if(abs(z - int(an[i])) >= max_dif):
                max_dif = abs(z - int(an[i]))
                tmp_idx = i
        z = int(an[tmp_idx])
    else:
        min_dif = float("inf")
        for i in range(now_idx, n):
            if(abs(w - int(an[i])) <= min_dif):
                min_dif = abs(w - int(an[i]))
                tmp_idx = i
        w = int(an[tmp_idx])
    now_idx = tmp_idx + 1
    if(now_idx == n - 1):
        break
    turn_x = not(turn_x)
print(abs(z - 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(n) for n in input().split()]
b = a.pop()
max = 0
if nota == []:
    for n in a:
        if abs(n - b) > max:
            max = abs(n - b)
if abs(n - Z) > max:
    max = abs(n - Z)
if abs(n - W) > max:
    max = abs(n - W)

print(max)

Submission status: Runtime Error

Solution code:
nzw = input().split()
n = int(nzw[0])
z = int(nzw[1])
w = int(nzw[2])
an = input().split()
turn_x = True
now_idx = 0
for j in range(n):
    tmp_idx = now_idx + 1
    if(tmp_idx == n - 1):
        break
    if(turn_x):
        max_dif = -1
        for i in range(now_idx + 1, n):
            if(abs(w - int(an[i])) >= max_dif):
                max_dif = abs(w - int(an[i]))
                tmp_idx = i
        z = int(an[tmp_idx])
    else:
        min_dif = float("inf")
        for i in range(now_idx + 1, n):
            if(abs(z - int(an[i])) <= min_dif):
                min_dif = abs(z - int(an[i]))
                tmp_idx = i
        w = int(an[tmp_idx])
    now_idx = tmp_idx
    if(now_idx == n - 1):
        break
    turn_x = not(turn_x)
print(abs(z - w))

Submission status: Runtime Error

Solution code:
def fx(p, x, y):
    global a, X
    if p == len(a):
        return abs(x - y)
    if x in X[p] and y in X[p][x]:
        return X[p][x][y]
    ret = 0
    for i in range(p, len(a)):
        ret = max(fy(i+1, a[i], y), ret)
    if x not in X[p]:
        X[p][x] = {y: ret}
    else:
        X[p][x][y] = ret
    return ret


def fy(p, x, y):
    global a, Y
    if p == len(a):
        return abs(x - y)
    if x in Y[p] and y in Y[p][x]:
        return Y[p][x][y]
    ret = float('inf')
    for i in range(p, len(a)):
        ret = min(fy(i+1, x, a[i]), ret)
    if x not in Y[p]:
        Y[p][x] = {y: ret}
    else:
        Y[p][x][y] = ret
    return ret


N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
X = [{} for i in range(len(a))]
Y = [{} for i in range(len(a))]

print(fx(0, Z, W))

Submission status: Runtime Error

Solution code:
import math
from collections import deque

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

def ans(a, b):
    print(a - b)

def main():
    deck = deque([])
    deck.extend(DECK)
    first = deck.popleft()

    x = max(Z, first)
    y = W

    deck_max = max(deck)
    deck_min = min(deck)

    ans(max(x, deck_max), min(y, deck_min))

    """
    print("x:{0} y:{1}".format(x, y))
    print("{0}".format(DECK))
    print("max:{0} min:{1}".format(deck_max, deck_min))
    #"""

main()

Submission status: Runtime Error

Solution code:
def fx(p, x, y):
    global a, X
    if p == len(a):
        return abs(x - y)
    if x in X[p] and y in X[p][x]:
        return X[p][x][y]
    ret = 0
    for i in range(p, len(a)):
        ret = max(fy(i+1, a[i], y), ret)
    if x not in X[p]:
        X[p][x] = {y: ret}
    else:
        X[p][x][y] = ret
    return ret


def fy(p, x, y):
    global a, Y
    if p == len(a):
        return abs(x - y)
    if x in Y[p] and y in Y[p][x]:
        return Y[p][x][y]
    ret = float('inf')
    for i in range(p, len(a)):
        ret = min(fy(i+1, x, a[i]), ret)
    if x not in Y[p]:
        X[p][x] = {y: ret}
    else:
        Y[p][x][y] = ret
    return ret


N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
X = [{} for i in range(len(a))]
Y = [{} for i in range(len(a))]

print(fx(0, Z, W))

Submission status: Runtime Error

Solution code:
nzw = input().split()
n = int(nzw[0])
z = int(nzw[1])
w = int(nzw[2])
an = input().split()
turn_x = True
now_idx = 0
for j in range(n):
    tmp_idx = now_idx + 1
    if(turn_x):
        max_dif = -1
        for i in range(now_idx + 1, n):
            if(abs(w - int(an[i])) >= max_dif):
                max_dif = abs(w - int(an[i]))
                tmp_idx = i
        z = int(an[tmp_idx])
    else:
        min_dif = float("inf")
        for i in range(now_idx + 1, n):
            if(abs(z - int(an[i])) <= min_dif):
                min_dif = abs(z - int(an[i]))
                tmp_idx = i
        w = int(an[tmp_idx])
    now_idx = tmp_idx
    if(now_idx == n - 1):
        break
    turn_x = not(turn_x)
print(abs(z - w))

Submission status: Runtime Error

Solution code:
#http://abc078.contest.atcoder.jp/
# -*- coding: utf-8 -*-
n, z, w = map(int,input().split())
a = list(map(int,input().split()))

ans = []
ans.append( abs( a[-1] - w ) )
ans.append( abs( a[-1] - a[-2] ) )
print(max(ans))

Submission status: Runtime Error

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

std = abs(Z-W)
last = a[0]

absList = [abs(last-i) for i in a]

ans = ans(last-W)
for i in range(N-1):
	testList = absList[i+1:]
	if min(absList) > ans:
		ans = max(absList)
print(ans)

Submission status: Runtime Error

Solution code:
def fx(p, x, y):
    global a
    if p == len(a):
        return abs(x - y)
    ret = 0
    for i in range(p, len(a)):
        ret = max(fy(i+1, a[i], y), ret)
    return ret


def fy(p, x, y):
    global a
    if p == len(a):
        return abs(x - y)
    ret = float('inf')
    for i in range(p, len(a)):
        ret = min(fy(i+1, x, a[i]), ret)
    return ret


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

print(fx(0, Z, W))