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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, X, Y = map(int, input().split())
A = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return list(map(int, input().split()))
N, Z, W = inpl()
A = inpl()

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 21 11:28:35 2018
ABC078D
@author: maezawa
"""

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

#if n == 1:
#    cand = [abs(w-a[-1])]
#elif n == 2:
#    cand = [abs(a[-2]-a[-1]), abs(w-a[-1])]
#elif:
#    cand = [abs(a[-2]-a[-1]), abs(w-a[-1]), abs(a[-3]-a[-1])]

cand = [abs(w-a[-1])]
for card in a[-2:]:
    cand.append(abs(card-a[-1]))

score = max(cand)
print(score)

Submission status: Accepted

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

a=[W]+list(map(int,input().split()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,z,w = li()
a = list(li())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(114514)

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

memo = {}
def act(last, turn):
    if (last, turn) in memo:
        return memo[(last, turn)]

    if turn == 0:
        # x turn
        y = w if last == -1 else aa[last]
        ans = abs(y - aa[n - 1])
        for i in range(last + 1, n - 1):
            ans = max(ans, act(i, 1))
    else:
        # y turn
        x = z if last == -1 else aa[last]
        ans = abs(x - aa[n - 1])
        for i in range(last + 1, n - 1):
            ans = min(ans, act(i, 0))
    
    memo[(last, turn)] = ans
    return ans


print(act(-1, 0))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(max(abs(int(a[n-1])-w),abs(int(a[n-2])-int(a[n-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:
    print(max(abs(a[-1]-W), abs(a[-2]-a[-1])))

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
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,z,w=map(int,input().split())
*a,=map(int,input().split())
b,c=max(a),min(a)
pb,pc=a.index(b),a.index(c)  
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:
import sys
from collections import deque
import copy

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, Z, W] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    input_raw = read_func().strip().split()
    A = []
    for i in range(N):
        A.append(int(input_raw[i]))

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

  


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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, Z, W = map(int, input().split())
a = [int(ai) for ai in input().split()]
if len(a) == 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())
A = [int(x) for x in input().split()]
A = [Z] + A
if len(A) > 2:
  print(max(abs(A[-1] - W), abs(A[-2] - A[-1])))
else:
  print(abs(A[-1] - W))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def warshall_floyd(g):
    d = defaultdict(dict)
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v))
    V = set(V)
    for i in V:
        for j in V:
            if i in g and j in g[i]:
                d[i][j] = g[i][j]
            else:
                d[i][j] = sys.maxsize
    for k in g:
        for i in g:
            for j in g:
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]

    return d


@mt
def slv(N, Z, W, A):
    if N > 1:
        return max(abs(W-A[-1]), abs(A[-1] - A[-2]))
    else:
        return abs(W-A[-1])


def main():
    N, Z, W = read_int_n()
    A = read_int_n()
    print(slv(N, Z, W, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

c=max((abs(b[len(b)-1]-a[2])), (abs(b[len(b)-2]-b[len(b)-1])))
print(c)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def m():
    N, Z, W = map(int, input().split())
    a = list(map(int, input().split()))
    if N == 1:
        return abs(a[0] - W)
    return max(abs(a[N - 1] - a[N - 2]), abs(a[N - 1] - W))


print(m())

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[0]-w))
else: print(max(abs(a[-1]-w),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:
    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, x, y = map(int,input().split())
numbers = list(map(int,input().split()))
print(max(abs(numbers[n-1]-y), abs(numbers[n-2] - numbers[n-1])))

Submission status: Accepted

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

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: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10000)

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 + 1, 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: 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-2]-a[N-1])))

Submission status: Accepted

Solution code:
N,Z,W = map(int,input().split())
list = [0]*N
tmp = input().split()
for i in range(N):
  list[i] = int(tmp[i])
print(max(abs(W-list[N-1]),abs(list[N-1]-list[N-2])))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding=utf-8
line = input().split(" ")
n = int(line[0])
z = int(line[1])
w = int(line[2])

a = []
for x in input().split(" "):
    a.append(int(x))

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

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

# --------------------------------------------

dp = None

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

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if abs(a[N-1] - W) >= abs(a[N-2] - a[N-1]):
    print(abs(a[N-1] - W))
elif abs(a[N-1] - W) <= abs(a[N-2] - a[N-1]):
    print(abs(a[N-2] - a[N-1]))

Submission status: Accepted

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: Accepted

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


# 相手がi番目を引いたときにだせる最大/最小のスコア
def dfs(turn, i):
    global memo, a
    if memo[turn][i] != -1:
        return memo[turn][i]

    ans = 0 if turn == 0 else INF
    for j in range(i + 1, len(a)):
        if j == len(a) - 1:
            s = abs(a[j] - a[i])
        else:
            s = abs(dfs(1 - turn, j))

        # X
        if turn == 0:
            ans = max(ans, s)
        # Y
        else:
            ans = min(ans, s)

    memo[turn][i] = ans
    return ans


def solve2(N, Z, W):
    global a, memo
    a = [W] + a
    memo = [[-1] * len(a) for _ in range(2)]
    return dfs(0, 0)


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:
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
INF = float("inf")
import sys
sys.setrecursionlimit(10000)


def solve(N, Z, W, a):
    ans = abs(a[-1] - W)
    if len(a) > 1:
        ans = max(ans, abs(a[-2] - a[-1]))
    return ans


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#abc078d

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

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

Submission status: Accepted

Solution code:


def takeAllByX(z, w, xs):
    return abs(w - xs[-1])

def forceLastByX(z, w, xs):
    return abs(xs[-2] - xs[-1])

def forceLast2ByX(z, w, xs):
    return play2ByY(z, w, xs[-2:])


def takeAllByY(z, w, xs):
    return abs(z - xs[-1])

def forceLastByY(z, w, xs):
    return abs(xs[-2] - xs[-1])

def play2ByY(z, w, xs):
    ta = takeAllByY(z, w, xs)
    fl = forceLastByY(z, w, xs)
    return min(ta, fl)



if __name__ == "__main__":
    n, z, w = list(map(int, input().split()))
    xs = tuple(map(int, input().split()))
    i = len(xs)
    if i == 1:
        print(takeAllByX(z, w, xs))
    elif i == 2:
        print(max(takeAllByX(z, w, xs), forceLastByX(z, w, xs)))
    else:
        print(max(takeAllByX(z, w, xs), forceLastByX(z, w, xs), forceLast2ByX(z, w, xs)))

Submission status: Accepted

Solution code:


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

Submission status: Accepted

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

if len(a)>1:
  l0=abs(a[-1]-a[-2])
else:
  l0=-1000000000000000000
l1=abs(a[-1]-w)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
w=int(input().split()[-1])
*a,b,c=map(int,[w]+input().split())
print(max(abs(b-c),abs(w-c)))

Submission status: Accepted

Solution code:
# coding: utf-8

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

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

Submission status: Accepted

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

result1 = abs(w-a[-1])
if len(a) >= 2:
    result2 = abs(a[-2]-a[-1])
else:
    result2 = result1

print(max(result1,result2))

Submission status: Accepted

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

Submission status: Accepted

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):
    if len(cards) > 1:
        cand1 = abs(W - int(cards[-1]))
        cand2 = abs(int(cards[-1]) - int(cards[-2]))
        if cand1 >= cand2:
            print(cand1)
        else:
            print(cand2)
    else:
        print(abs(W - int(cards[-1])))

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

main()

Submission status: Accepted

Solution code:
n, z, w = list(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:
N, Z, W = map(int,input().split(" "))
a = list(map(int,input().split(" ")))
b = a[::-1]
b.append(W)
alpha = abs(b[0]-b[1])
beta = abs(b[0]-b[N])
ans = max(alpha,beta)
print(ans)

Submission status: Accepted

Solution code:
print(lambda n,c:max(abs(n[2]-c[-1]),abs(([n[2]]+c)[-2]-c[-1])))(map(int,raw_input().split()),map(int,raw_input().split()))

Submission status: Accepted

Solution code:
print (lambda nzw,c: abs(nzw[2]-c[-1]) if nzw[0] == 1 else (abs(nzw[2]-c[-1]) if abs(nzw[2]-c[-1]) > abs(c[-2]-c[-1]) else abs(c[-2]-c[-1])))(map(int, raw_input().split()), map(int, raw_input().split()))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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: Accepted

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

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

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[N - 1] - 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:
#!/usr/bin/env python3
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

main()

Submission status: Accepted

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

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

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:
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(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(D_abs(N, Z, W, A))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# D問題

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

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

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


print(ans)

Submission status: Accepted

Solution code:
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n,z,w = Is()
a = Is()
ans = ""
if n == 1:
    ans = abs(a[n-1]-w)
else:
    ans = max(abs(a[n-1]-w),abs(a[n-2]-a[n-1]))
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, z, w = [int(x) for x in raw_input().split()]
c = [int(x) for x in raw_input().split()]
if abs(c[n - 1] - w) > abs(c[n - 1] - c[n - 2]):
    print abs(c[n - 1] - w)
else:
    print abs(c[n - 1] - c[n - 2])

Submission status: Accepted

Solution code:
def alphabeta(a, X, Z, W, alpha, beta):
    if len(a) == 0:
        return abs(Z-W)
    if X:
        for i in reversed(range(len(a))):
            Z = a[i]
            alpha = max(alpha, alphabeta(a[i+1:len(a)], not X, Z, W, alpha, beta))
            if alpha >= beta:
                return beta
        return alpha
    else:
        for i in reversed(range(len(a))):
            W = a[i]
            beta = min(beta, alphabeta(a[i+1:len(a)], not X, Z, W, alpha, beta))
            if alpha >= beta:
                return alpha
        return beta

N, Z, W = tuple(map(int, input().split()))
a = list(map(int, input().split()))
print(alphabeta(a, True, Z, W, 0, 2e9))

Submission status: Accepted

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