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:
import numpy as np
n, z, w = map(int, input().split())
tmp = list(map(int, input().split()))
a = np.array(tmp)

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

print(score)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, C =  map(int, input().split())
M = list(map(int, input().split()))

if abs(M[A-1] - M[A-2]) >= abs(M[A-1] - C):
    print(abs(M[A-1] - M[A-2]))
else:
    print(abs(M[A-1] -C))

Submission status: Accepted

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

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

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

Submission status: Accepted

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 ) )
if len(a) > 1: ans.append( abs( a[-1] - a[-2] ) )

print(max(ans))

Submission status: Accepted

Solution code:
import sys
line = sys.stdin.readline().strip()
n, z, w = map(int, line.split()[:3])
line = sys.stdin.readline().strip()
a = list(map(int, line.split()[:n]))
#print(n, z, w)
#print(a)

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

print(result)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N,Z,W = map(int, raw_input().split(" "))
cards = map(int, raw_input().split(" "))

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
try:
    print(max(abs(a[2] - b[-1]), abs(b[-1] - b[-2])))
except:
    print(abs(a[2] - b[0]))

Submission status: Accepted

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

def main():
    n, z, w = list(map(int, input().split()))
    As = list(map(int, input().split()))
    if len(As) > 1:
        answer = max(abs(w - As[-1]), abs(As[-1] - As[-2]))
    else:
        answer = abs(w-As[-1])
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import math

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

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

X=S[1]
Y=S[2]

if S[0]==1:
	print(int(math.fabs(A[-1]-Y)))
else:
	r1=math.fabs(A[-1]-Y)
	r2=math.fabs(A[-2]-A[-1])

	if r1<r2:
		print(int(r2))
	else:
		print(int(r1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
import numpy as np
import bisect

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

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

Submission status: Accepted

Solution code:
from sys import stdin, stdout
def IL():return list(map(int, stdin.readline().split()))

def main():
    N,Z,W = IL()
    a = IL()
    if len(a)>1:
        p=abs(a[-2] - a[-1])
        q=abs(a[-1] - W)
        print(max(p,q))
    else:
        print(abs(a[0]-W))
        
if __name__ == "__main__": main()

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:
n,z,w = map(int, raw_input().split() ) #3 100 1000
ais = = map(int, raw_input().split()) #10 100 100
m = abs(z - w)
for u,v in zip(ais, ais[1:]):
	m = max(m, (u - v))
m = max(m, abs(ais[-1] - w))
print m

Submission status: Runtime Error

Solution code:
N,Z,W=map(int,input().split())
a=list(map(int,input().split()))
print(abs(W-a[0])if n==1 else 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(abs(w-a[0])if n==1 else max(abs(w-a[-1]),abs(a[-1]-a[-2])))

Submission status: Runtime Error

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

def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    """
    O(N^2)dpでも行けるそうです。以下写経：
    https://atcoder.jp/contests/abc078/submissions/14886969
    dp[turn][top]の２引数だけでいいのか、[x][y]の２引数も必要ではないかと思うが、
    考えてみれば
        dfs(0, top, x, y) = dfs(1, top', A[top], y)
                          = dfs(0, top", A[top], A[top'])
    となるので、実はdfs(0, top, x, y)はtop = Nでない限りx, yに依らない。
    """
    dp = [[-1] * N for _ in range(2)]
    def dfs(turn, top, x, y): # turn: 0 => x, 1 => y
        if top == N: return abs(x - y)
        if dp[turn][top] != -1: return dp[turn][top]
        if turn == 1:
            """
            yのターンは、top以降を取ってなるべくスコアが低くなるようなiを選ぶ
            """
            ret = 10**9
            for i in range(top, N): ret = min(ret, dfs(0, i + 1, x, A[i]))
            dp[turn][top] = ret
            return ret
        else:
            """
            xのターンは、top以降を取ってなるべくスコアが高くなるようなiを選ぶ
            """
            ret = 0
            for i in range(top, N): ret = max(ret, dfs(1, i + 1, A[i], y))
            dp[turn][top] = ret
            return ret
    
    print(dfs(0, 0, Z, W))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache
def input(): return sys.stdin.readline().strip()


def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    """
    O(N^2)dpでも行けるそうです。以下写経：
    https://atcoder.jp/contests/abc078/submissions/14886969
    dpテーブルが訳分からなくなったら@lru_cache使うのが楽。
    """
    #@lru_cache(maxsize=None)
    def dfs(turn, top, x, y): # turn: 0 => x, 1 => y
        if top == N: return abs(x - y)
        if turn == 1:
            """
            yのターンは、top以降を取ってなるべくスコアが低くなるようなiを選ぶ
            """
            ret = 10**9
            for i in range(top, N): ret = min(ret, dfs(0, i + 1, x, A[i]))
            return ret
        else:
            """
            xのターンは、top以降を取ってなるべくスコアが高くなるようなiを選ぶ
            """
            ret = 0
            for i in range(top, N): ret = max(ret, dfs(1, i + 1, A[i], y))
            return ret
    
    print(dfs(0, 0, Z, W))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache
def input(): return sys.stdin.readline().strip()


def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    """
    O(N^2)dpでも行けるそうです。以下写経：
    https://atcoder.jp/contests/abc078/submissions/14886969
    dpテーブルが訳分からなくなったら@lru_cache使うのが楽。
    """
    @lru_cache(maxsize=None)
    def dfs(turn, top, x, y): # turn: 0 => x, 1 => y
        if top == N: return abs(x - y)
        if turn == 1:
            """
            yのターンは、top以降を取ってなるべくスコアが低くなるようなiを選ぶ
            """
            ret = 10**9
            for i in range(top, N): ret = min(ret, dfs(0, i + 1, x, A[i]))
            return ret
        else:
            """
            xのターンは、top以降を取ってなるべくスコアが高くなるようなiを選ぶ
            """
            ret = 0
            for i in range(top, N): ret = max(ret, dfs(1, i + 1, A[i], y))
            return ret
    
    print(dfs(0, 0, Z, W))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache
def input(): return sys.stdin.readline().strip()


def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    """
    O(N^2)dpでも行けるそうです。以下写経：
    https://atcoder.jp/contests/abc078/submissions/14886969
    dpテーブルが訳分からなくなったら@lru_cache使うのが楽。
    """
    @lru_cache(maxsize=None)
    def dfs(turn, top, x, y): # turn: 0 => x, 1 => y
        if top == N: return abs(x - y)
        if turn == 1:
            """
            yのターンは、top以降を取ってなるべくスコアが低くなるようなiを選ぶ
            """
            ret = 10**18
            for i in range(top, N): ret = min(ret, dfs(0, i + 1, x, A[i]))
            return ret
        else:
            """
            xのターンは、top以降を取ってなるべくスコアが高くなるようなiを選ぶ
            """
            ret = 0
            for i in range(top, N): ret = max(ret, dfs(1, i + 1, A[i], y))
            return ret
    
    print(dfs(0, 0, Z, W))

if __name__ == "__main__":
    main()

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:
n,z,w=map(int,input().split())
card=list(map(int,input.split()))

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

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

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

Submission status: Runtime Error

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n), n)+[X%n]
  return [X%n]


#############
# Main Code #
#############

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

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

Submission status: Runtime Error

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n), n)+[X%n]
  return [X%n]


#############
# Main Code #
#############

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

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 = list(map(int,input().split()))
idea = abs(A[-1] - W)
idea2 = abs(A[-2] - A[-1])
print(max(idea,idea2))

Submission status: Runtime Error

Solution code:
N, Z, W = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
dp = [{} for _ in range(N)]


def search(i, X, Y, turn):
    if i == N:
        return abs(X - Y)
    if (X, Y, turn) in dp[i]:
        return dp[i][(X, Y, turn)]
    if turn == 1:
        ans = 0
        for j in range(i, N):
            ans = max(ans, search(j + 1, a[j], Y, -turn))
        dp[i][(X, Y, turn)] = ans
        return ans
    else:
        ans = 10 ** 18
        for j in range(i, N):
            ans = min(ans, search(j + 1, X, a[j], -turn))
        dp[i][(X, Y, turn)] = ans
        return ans


print(search(0, Z, W, 1))

Submission status: Runtime Error

Solution code:
dic = {}

def getX(x, y, cards, idx):
    if len(cards)==1:
        return abs(cards[0]-y)
    lgst = 0
    tmpcards = cards.copy()
    for ex, i in enumerate(cards):
        if(ex==len(cards)-1):
            return max(abs(i-y),lgst)
        tmpcards.remove(i)
        idx += 1
        #if (i,y,idx) in dic:
            #tmp = dic[(i,y,idx)]
        #else:
        tmp = getY(i, y, tmpcards, idx)
            #dic[(i,y,idx)]= tmp
        if tmp > lgst:
            lgst = tmp
    return lgst

def getY(x, y, cards, idx):
    if len(cards)==1:
        return abs(cards[0]-x)
    smlst = 0
    tmpcards = cards.copy()
    for ex, i in enumerate(cards):
        if (ex==len(cards)-1):
            return min(abs(i - x), smlst)
        tmpcards.remove(i)
        idx += 1
        #if (x,i,idx) in dic:
            #tmp = dic[(x,i,idx)]
        #else:
        tmp = getX(x, i, tmpcards, idx)
            #dic[(x,i,idx)]= tmp
        if tmp < smlst:
            smlst = tmp
    return smlst

n, z, w = map(int, input().split())
cards = list(map(int, input().split()))
print(getX(z, w, cards, 0))

Submission status: Runtime Error

Solution code:
dic = {}

def getX(x, y, cards, idx):
    if len(cards)==1:
        return abs(cards[0]-y)
    lgst = 0
    tmpcards = cards.copy()
    for ex, i in enumerate(cards):
        if(ex==len(cards)-1):
            return max(abs(i-y),lgst)
        tmpcards.remove(i)
        idx += 1
        if (i,y,idx) in dic:
            tmp = dic[(i,y,idx)]
        else:
            tmp = getY(i, y, tmpcards, idx)
            dic[(i,y,idx)]= tmp
        if tmp > lgst:
            lgst = tmp
    return lgst

def getY(x, y, cards, idx):
    if len(cards)==1:
        return abs(cards[0]-x)
    smlst = 0
    tmpcards = cards.copy()
    for ex, i in enumerate(cards):
        if (ex==len(cards)-1):
            return min(abs(i - x), smlst)
        tmpcards.remove(i)
        idx += 1
        if (x,i,idx) in dic:
            tmp = dic[(x,i,idx)]
        else:
            tmp = getX(x, i, tmpcards, idx)
            dic[(x,i,idx)]= tmp
        if tmp < smlst:
            smlst = tmp
    return smlst

n, z, w = map(int, input().split())
cards = list(map(int, input().split()))
print(getX(z, w, cards, 0))

Submission status: Runtime Error

Solution code:
dic = {}

def getX(x, y, cards, idx):
    if len(cards)==1:
        return abs(cards[0]-y)
    lgst = 0
    tmpcards = cards.copy()
    for ex, i in enumerate(cards):
        if(ex==len(cards)-1):
            return max(abs(i-y),lgst)
        tmpcards.remove(i)
        idx += 1
        if (i,y,idx) in dic:
            tmp = dic[(i,y,idx)]
        else:
            tmp = getY(i, y, tmpcards, idx)
            dic[(i,y,idx)]= tmp
        if tmp > lgst:
            lgst = tmp
    return lgst

def getY(x, y, cards, idx):
    if len(cards)==1:
        return abs(cards[0]-x)
    smlst = 0
    tmpcards = cards.copy()
    for ex, i in enumerate(cards):
        tmpcards.remove(i)
        if (ex==len(cards)-1):
            return min(abs(i - x), smlst)
        idx += 1
        if (x,i,idx) in dic:
            tmp = dic[(x,i,idx)]
        else:
            tmp = getX(x, i, tmpcards, idx)
            dic[(x,i,idx)]= tmp
        if tmp < smlst:
            smlst = tmp
    return smlst

n, z, w = map(int, input().split())
cards = list(map(int, input().split()))
print(getX(z, w, cards, 0))

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[0]-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())

al = list(map(int,input().split()))
if len(al) == 1:
    print(abs(al[-1] - w))
ans1 = abs(al[-1] - al[-2])
ans2 = abs(al[-1] - w)

print(max(ans1, ans2))

Submission status: Runtime Error

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

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

ans1 = abs(al[-1] - al[-2])
ans2 = abs(al[-1] - w)

print(max(ans1, ans2))

Submission status: Runtime Error

Solution code:
n,_,y= map(int,input().split())
a= [-1] + list(map(int,input().split()))
def gs(s,ik,at):
    if ik==n:       return abs(a[n]-at)
    else:
        if s=='x':  return max(gs('x',ik+1,at),gs('y',ik+1,a[ik]))
        elif s=='y':return min(gs('y',ik+1,at),gs('x',ik+1,a[ik]))
print(gs('x',1,y))

Submission status: Runtime Error

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

def func(i, j, xxyy):
    xy = deepcopy(xxyy)
    if i >= n:
        return abs(xy[0] - xy[1])
    if j == 0:
        tmp = 0
        for k in range(i, n):
            if tmp < abs(xy[1] - a[k]):
                xy[0] = a[k]
    if j == 1:
        tmp = inf
        for k in range(i, n):
            if tmp > abs(xy[0] - a[k]):
                xy[1] = a[k]
    res = []
    for k in range(i, n):
        if a[k] == xy[j]:
            debug(k)
            res.append(func(k + 1, int(not bool(j)), xy))
    debug(i, j, res)
    if j == 0:
        return max(res)
    else:
        return min(res)

n, z, w = MAP()
a = LIST()
xy = [z, w]
ans = func(0, 0, xy)
print(ans)

Submission status: Runtime Error

Solution code:
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

turn = True
flag = False
p= max(a)
for i in range(n-1):
  if turn:
    if a[i] <= a[i+1]:
      continue
    elif a[i] < z and a[i] != p:
      continue
    else:
      z = a[i]
      turn = False
      if a[i] < z and a[i] == p:
        q = min(a[i+1:])
  else:
    if a[i] >= a[i+1]:
      continue
    elif a[i] > w and a[i] != q:
      continue
    else:
      w = a[i]
      turn = True
      if a[i] > w and a[i] == q:
        p = max(a[i+1:])
if turn:
  z = a[-1]
else:
  w = a[-1]
print(abs(z-w))

Submission status: Runtime Error

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

turn = True
p= max(a)
for i in range(n-1):
  if turn:
    if a[i] <= a[i+1]:
      continue
    elif a[i] < z and a[i] != p:
      continue
    else:
      z = a[i]
      turn = False
      if a[i] < z and a[i] == p:
        q = min(a[i+1:])
  else:
    if a[i] >= a[i+1]:
      continue
    elif a[i] > w and a[i] != q:
      continue
    else:
      w = a[i]
      turn = True
      if a[i] > w and a[i] == q:
        p = max(a[i+1:])
if turn:
  z = a[-1]
else:
  w = a[-1]
print(abs(z-w))

Submission status: Runtime Error

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

p = max(a)
q = min(a)
if z < p:
  z = p
if w > q:
  w = q
print(abs(p-q))

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]) if n > 1 else 0))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
memof = {}
def f(x,y,i):
    if i==N-1:
        return abs(A[N-1]-y)
    if (x,y,i) in memof:
        return memo[(x,y,i)]
    b = abs(A[N-1]-y)
    for j in range(i,N-1):
        b = max(b,g(A[j],y,j+1))
    memof[(x,y,i)]=b
    return b
memog = {}
def g(x,y,i):
    if i==N-1:
        return abs(x-A[N-1])
    if (x,y,i) in memog:
        return memog[(x,y,i)]
    b = abs(x-A[N-1])
    for j in range(i,N-1):
        b = min(b,f(x,A[j],j+1))
    memog[(x,y,i)] = b
    return b
N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
print(f(Z,W,0))

Submission status: Runtime Error

Solution code:
def f(x,y,i):
    if i==N-1:
        return abs(A[N-1]-y)
    b = abs(A[N-1]-y)
    for j in range(i,N-1):
        b = max(b,g(A[j],y,j+1))
    return b
def g(x,y,i):
    if i==N-1:
        return abs(x-A[N-1])
    b = abs(x-A[N-1])
    for j in range(i,N-1):
        b = min(b,f(x,A[j],j+1))
    return b
N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
print(f(Z,W,0))

Submission status: Runtime Error

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

def trial(n, z, w, t): 
  # n: 残りの枚数
  # z: Xの手持ち
  # w: Yの手持ち
  # t: これまでに引いた枚数
  min_score = [0]*n
  min_j = [0]*n
  for i in range(t,t+n):
    if i == t+n-1:
      min_score[n-1] = abs(l[t+n-1]-w)
      break
    temp = l[i]
    temp_min = 10**9+1
    for j in range(i+1, t+n):
      if abs(temp-l[j]) <= temp_min:
        temp_min = abs(temp-l[j])
        min_score[i-t] = temp_min
        min_j[i-t] = j
    #print(max(min_score))
  #print(min_score)
  #n -= (min_score.index(max(min_score))+1)
  if min_score.index(max(min_score)) == n-1:
    n = 0
    z = l[-1]
    w = w
    t = len(l)
  else:
    n = len(l) - (t+min_j[min_score.index(max(min_score))]+1)
    z = l[t+min_score.index(max(min_score))]
    w = l[t+min_j[min_score.index(max(min_score))]]
    t += (min_score.index(max(min_score))+1)
  return n, z, w, t
  
t = 0
while n > 0:
  n, z, w, t = trial(n, z, w, t)
  #print(n, z, w, t)
print(abs(z-w))

Submission status: Runtime Error

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

def trial(n, z, w, t): 
  # n: 残りの枚数
  # z: Xの手持ち
  # w: Yの手持ち
  # t: これまでに引いた枚数
  min_score = [0]*n
  min_j = [0]*n
  for i in range(t,t+n):
    if i == t+n-1:
      min_score[n-1] = abs(l[t+n-1]-w)
      break
    temp = l[i]
    temp_min = 10**9+1
    for j in range(i+1, t+n):
      if abs(temp-l[j]) <= temp_min:
        temp_min = abs(temp-l[j])
        min_score[i-t] = temp_min
        min_j[i-t] = j
    #print(max(min_score))
  #print(min_score)
  #n -= (min_score.index(max(min_score))+1)
  if min_score.index(max(min_score)) == n-1:
    n = 0
    z = l[t+min_score.index(max(min_score))]
    w = w
  else:
    n = len(l) - (t+min_j[min_score.index(max(min_score))]+1)
    z = l[t+min_score.index(max(min_score))]
    w = l[t+min_j[min_score.index(max(min_score))]]
    t += (min_score.index(max(min_score))+1)
  return n, z, w, t
  
t = 0
while n > 0:
  n, z, w, t = trial(n, z, w, t)
  #print(n, z, w, t)
print(abs(z-w))

Submission status: Runtime Error

Solution code:
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([n-2]-a[n-1])
    tmp2 = abs(a[n-1]-w)
    ans = max(tmp,tmp2)
  print(ans)
solve()