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

ans = abs(A[-1] - W)

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

print(ans)

Submission status: Accepted

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

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, X, Y = mapint()
As = list(mapint())

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from itertools import product
input = sys.stdin.readline

def main():
    n, z, w = map(int, input().split())
    
    a = list(map(int, input().split()))
    
    ans = abs(w-a[-1])
    if n != 1:
        ans = max(ans, abs(a[-2]-a[-1]))
    
    print(ans)
        

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

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, x, y = tin()
	#s = input()
	if n == 1:
		return abs(int(input())-y)
	else:
		al=lin()
		return max(abs(al[-1]-y), abs(al[-2]-al[-1]))
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

"""
xの選択肢は2つ。最後を取ってwと比較するか、最後から2番目を取って最後と比較する
"""

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,X,Y=map(int,input().split())
L=list(map(int,input().split()))
if N>2:
  print(max(abs(L[-2]-L[-1]),abs(Y-L[-1])))
else:
  print(abs(L[-1]-Y))

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

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

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

N, Z, W = getNM()
A = getList()

# 相手に手番を渡さない
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()))
print(abs(W-a[0])if N==1 else max(abs(W-a[-1]),abs(a[-1]-a[-2])))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10**7)

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

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()))
    """
    dpかと思ってずっとウンウン唸ってたのに、解説見て唖然。。。
    """
    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(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())
a = [int(i) for i in input().split()]

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

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

Submission status: Accepted

Solution code:
import collections
def main():
    n,z,w=map(int, input().split())
    a=[int(i) for i in input().split()]
    #途中選り好みしても結局a_n - a_n-1になる
    if(n==1):
        print((abs(w-a[0])))
    else:
        print(max(abs(a[n-1]-a[n-2]), abs(a[n-1]-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))
    exit()
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:
    X = abs(W-A[0])
    print(X)
else:
    X = abs(W-A[N-1])
    Y = abs(A[N-1]-A[N-2])
    print(max(X,Y))

Submission status: Accepted

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

dpx = [0]*(N+1)
dpy = [0]*(N+1)
x = [Z]+a[:]
y = [W]+a[:]

for i in range(1, N+1):
    if i == 1:
        dpx[i] = abs(x[N] - y[N-1])
        dpy[i] = abs(y[N] - x[N-1])
    else:
        dpx[i] = max([abs(x[N] - y[N-i])] + [dpy[j] for j in range(1,i)])
        dpy[i] = min([abs(y[N] - x[N-i])] + [dpx[j] for j in range(1,i)])

print(dpx[N])

Submission status: Accepted

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

if n == 1:
  print(ans)
  exit()
  
l = len(a)
for i in range(l-1):
  chk = 10**9
  for j in range(i+1,l):
    if j == l-1:
      chk = min(chk,abs(a[i]-a[j]))
    else:
      chk = min(chk,abs(a[l-1]-a[j]))
  ans = max(ans,chk)
  
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[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[-1] - 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[-1]-A[-2]),abs(A[-1]-W)))

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = list(map(int, input().split()))
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    n, z, w = map(int, input().split())
    a_s = list(map(int, input().split()))

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

# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3 100 100
10 1000 100"""
        output = """900"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3 100 1000
10 100 100"""
        output = """900"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """5 1 1
1 1 1 1 1"""
        output = """0"""
        self.assertIO(test_input, output)

    def test_input_4(self):
        test_input = """1 1 1
1000000000"""
        output = """999999999"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.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:
  ans=max(abs(a[-1]-a[-2]),abs(a[-1]-w))
print(ans)

Submission status: Accepted

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

cand = []
cand.append( abs(A[N-1]-W))
cand.append( abs(A[N-2]-A[N-1]))

print(max(cand))

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

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

# 最後の一枚を取るか、その直前を取るかしかない
# なぜなら、最後から数えて3枚目を取る場合は相手に最後から2枚目を取ることを期待するが、
# それなら自分が最後から2枚目を取ったほうが有利なため。

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

if N == 1:
  # 1枚の場合は取るしかない
  print(abs(A[0] - W))
  exit(0)
  
# 最後の一枚を取る場合
last_one = abs(A[-1] - W)

# 最後から二枚目を取る場合
last_two = abs(A[-1] - A[-2])

if last_one > last_two:
  print(last_one)
else:
  print(last_two)

Submission status: Accepted

Solution code:
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[n-2]-a[n-1]))
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *
sys.setrecursionlimit(2100)

def rec(sta, t):
    if memo[sta][t]!=-1:
        return memo[sta][t]
    
    if t==0:
        res = -10**18
        
        for i in range(sta, N):
            if i<N-1:
                res = max(res, rec(i+1, 1))
            else:
                if sta==0:
                    res = max(res, abs(a[N-1]-W))
                else:
                    res = max(res, abs(a[N-1]-a[sta-1]))
    else:
        res = 10**18
        
        for i in range(sta, N):
            if i<N-1:
                res = min(res, rec(i+1, 0))
            else:
                if sta==0:
                    res = min(res, abs(a[N-1]-Z))
                else:
                    res = min(res, abs(a[N-1]-a[sta-1]))
    
    memo[sta][t] = res
    
    return res

N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
memo = [[-1]*2 for _ in range(N)]
print(rec(0, 0))

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, z, w = map(int, readline().split())
    a = list(map(int, readline().split()))

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
b=[abs(a[i]-a[-1]) for i in range(n-1)]
b=[abs(w-a[-1])]+b
if n==1:print(abs(w-a[0]));exit()
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()))
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 = tuple(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: 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]-a[N-2]),abs(a[N-1]-W)))

Submission status: Accepted

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

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

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

al1 = al[-2]
al2 = al[-1]

d1 = abs(al1-al2)
d2 = abs(al2-w)

print(max(d1,d2))

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,z,w = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    if n == 1:
        print(abs(w-a[0]))
    else:
        print(max(abs(w-a[-1]),abs(a[-2]-a[-1])))
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

dp = [[0, 0] for i in range(N)]
dp[-1][0] = abs(A[-1]- W)
dp[-1][1] = - 1
dp[-2][0] = dp[-2][1] = dp1min = abs(A[-2] - A[-1])
dp0max = max(dp1min, dp[-1][0])

for i in range(N-3, -1, -1):
  ai = A[i]
  diff = abs(ai - A[-1])
  dp[i][0] = min(diff, dp1min)
  dp[i][1] = max(diff, dp0max)
  dp0max = max(dp0max, dp[i][0])
  dp1min = min(dp1min, dp[i][1])

print(dp0max)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, _, w = mi()
    L = lmi()
    if n == 1:
        print(abs(w - L[-1]))
    else:
        print(max(abs(w - L[-1]), abs(L[-1]-L[-2])))



if __name__ == "__main__":
    main()

Submission status: Accepted

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

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:
# -*- 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()

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

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[-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()))
idea = abs(A[-1] - W)
try: idea2 = abs(A[-2] - A[-1])
except:
    print(idea)
    quit()
print(max(idea,idea2))

Submission status: Accepted

Solution code:
n, z, w = map(int, input().split())
cards = list(map(int, input().split()))
#print(getX(z, w, cards, 0))
if(abs(cards[len(cards)-1]-w)>abs(cards[len(cards)-1]-cards[len(cards)-2])):
    print(abs(cards[len(cards)-1]-w))
else:
    print(abs(cards[len(cards)-1]-cards[len(cards)-2]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, Z, W = read_values()
    A = read_list()
    res = V(max, abs(W - A[-1]))
    if N >= 2:
        res.ud(abs(A[-1] - A[-2]))

    print(res)


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

Submission status: Accepted

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

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

print(max(ans1, ans2))

Submission status: Accepted

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

# Xが全部とる
t1=abs(a[N-1]-W)
# Xが1個残しでとる
if N>1:
    t2=abs(a[N-1-1]-a[N-1])
else:
    t2=0
# Xが2個残しで取る場合、Yの都合に従う
if N>2:
    t3=min( abs(a[N-2-1]-a[N-1]),abs(a[N-1]-a[N-1-1]) )
else:
    t3=0

print(max(t1,t2,t3))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)

def sort(a):
	a.sort()

def rev(a):
	a.reverse()

def sd():
	return int(input())

def _sd():
	return map(int,input().split())

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

def ss():
	return input()

def sf():
	return float(input())
 
def main():
	N,Z,W=_sd()
	a=sa()
	if(N>1):
		print(max(abs(a[N-1]-W),abs(a[N-2]-a[N-1])))
	else:
		print(abs(a[0]-W))
main()

Submission status: Accepted

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, Z, W = getlist()
	A = getlist()
	if N == 1:
		print(abs(A[0] - W))
	else:
		ans = max(abs(A[-1] - W), abs(A[-1] - A[-2]))
		print(ans)
	


if __name__ == '__main__':
	main()