CodeEff/ECCO huggingface dataset:
# Original solution
from operator import itemgetter
from collections import defaultdict
N = int(eval(input()))
A = [int(v) for v in input().split()]
cnt = 0
left_list = [i + a for i, a in enumerate(A, 1)]
right_list = [i - a for i, a in enumerate(A, 1)]
right_dict = defaultdict(set)
for i, right in enumerate(right_list, 1):
    right_dict[right].add(i)
for i, left in enumerate(left_list, 1):
    pair_num = len(right_dict[left] - set([i]))
    cnt += pair_num
print(cnt)

# Optimized solution
from operator import itemgetter
from collections import defaultdict
N = int(eval(input()))
A = [int(v) for v in input().split()]
cnt = 0
left_list = [i + a for i, a in enumerate(A, 1)]
right_list = [i - a for i, a in enumerate(A, 1)]
right_dict = defaultdict(set)
for i, right in enumerate(right_list, 1):
    right_dict[right].add(i)
for i, left in enumerate(left_list, 1):
    pair_num = len(right_dict[left])
    cnt += pair_num
print(cnt)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
l = [0]*n
ans = 0

for i in range(n):
    l[i] = i + 1 + a[i]
    ans += l[:i].count(i + 1 - a[i])


print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
d = {}
ans = 0

for i in range(n):
    l = i + a[i]
    r = i - a[i]
    if l not in d:
        d[l] = 1
    else:
        d[l] += 1
    if r in d:
        ans += d[r]

print(ans)
# Original solution
alpha = 'abcdefghijklmnopqrstuvwxyz'
text = ''

while True:
    try:
        text += input().lower()
    except:
        break
        
for key in alpha:
        print(('{} : {}'.format(key, text.count(key))))


# Optimized solution
alpha = 'abcdefghijklmnopqrstuvwxyz'
text = ''

while True:
    try:
        text += input().lower()
    except:
        break
 
[print('{} : {}'.format(key, text.count(key))) for key in alpha]
# Original solution
import sys
strs = sys.stdin.readlines()
for c in range(ord('a'), ord('z') + 1):
    count = 0
    for str in strs:
        count += str.lower().count(chr(c))
    print(('{0} : {1}'.format(chr(c), count)))

# Optimized solution
import sys
strs = sys.stdin.readlines()
for c in range(ord('a'), ord('z') + 1):
    count = 0
    for s in strs:
        count += s.lower().count(chr(c))
    print(('{0} : {1}'.format(chr(c), count)))
# Original solution
import sys
az =["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
sum_az = [0 for x in range(26)]

for x in sys.stdin.read().lower():
    for i in range(26):
        for j in range(len(x)):
            if x[j] == az[i]:
                sum_az[i] += 1


for i in range(26):
    print(("%s : %d" % (az[i], sum_az[i])))
                

# Optimized solution
import sys
az =["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
sum_az = [0 for x in range(26)]

for x in sys.stdin.read().lower():
    for i in range(26):
        if x == az[i]:
            sum_az[i] += 1


for i in range(26):
    print(("%s : %d" % (az[i], sum_az[i])))
# Original solution
# #バブルソート
# def BubbleSort(C,N):
#     for i in range (0,N,1):
#         for j in range(N-1,i-1,-1):
#             if int(C[j][1:2]) < int(C[j-1][1:2]):
#                 tmp = C[j]
#                 C[j] = C[j-1]
#                 C[j-1] = tmp
#     print(' '.join(C))

#バブルソート
def BubbleSort(C,N):
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1,0,-1):
            if int(C[j][1:2]) < int(C[j-1][1:2]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
                flag = 1
    print((' '.join(C)))
    
    
                
                
#選択ソート
def SelectionSort(C,N):
    for i in range(0,N,1):
        minj = i
        for j in range(i,N,1):
            if int(C[j][1:2]) < int(C[minj][1:2]):
                minj = j
        tmp = C[i]
        C[i] = C[minj]
        C[minj] = tmp
    print((' '.join(C)))
        
#安定かどうかの判定
def isStable(inp, out,N):
    for i in range(0,N):
        for j in range(i+1,N):
            for a in range(0,N):
                for b in range(a+1,N):
#                     print("inp(i,j):",inp[i],inp[j],"out(b,a):",out[b],out[a]+"\n")
                    if int(inp[i][1]) == int(inp[j][1]) and inp[i] == out[b] and inp[j] == out[a]:
                        print('Not stable')
                        return
    print('Stable')


#愚直に調べるパターン
N = int(eval(input()))
A = list(input().split())
Bubble_A = A.copy()
Selection_A = A.copy()

BubbleSort(Bubble_A,N)
isStable(A,Bubble_A,N)
SelectionSort(Selection_A,N)
isStable(A,Selection_A,N)


# Optimized solution
#バブルソート
def BubbleSort(C,N):
    for i in range (0,N,1):
        for j in range(N-1,i,-1):
            if int(C[j][1:2]) < int(C[j-1][1:2]):
                tmp = C[j]
                C[j] = C[j-1]
                C[j-1] = tmp
    print((' '.join(C)))

    
                
#選択ソート
def SelectionSort(C,N):
    for i in range(0,N,1):
        minj = i
        for j in range(i,N,1):
            if int(C[j][1:2]) < int(C[minj][1:2]):
                minj = j
        tmp = C[i]
        C[i] = C[minj]
        C[minj] = tmp
    print((' '.join(C)))



N = int(eval(input()))
A = list(input().split())
Bubble_A = A.copy()
Selection_A = A.copy()

BubbleSort(Bubble_A,N)
print("Stable")
SelectionSort(Selection_A,N)
flag = True
for Bubble,Selection in zip(Bubble_A,Selection_A):
    if Bubble != Selection:
        flag = False
if flag :
    print("Stable")
else:
    print("Not stable")
# Original solution
class Card():
    def __init__(self, card):
        self.card = card
        self.mark = card[0]
        self.number = card[1]
        
    def __lt__(self, other):
        if not isinstance(other, Card):
            return NotImplemented
        return self.number < other.number
    
    def __eq__(self, other):
        if not isinstance(other, Card):
            return NotImplemented
        return self.mark == other.mark and self.number == other.number
        
    def __repr__(self):
        return '{}{}'.format(self.mark, self.number)


def BubbleSort(target):
    ls = target.copy()
    flag = 1
    while flag:
        flag = 0
        for i in range(len(ls)-1, 0, -1):
            if ls[i] < ls[i-1]:
                ls[i], ls[i-1] = ls[i-1], ls[i]
                flag = 1
    print((' '.join(map(str, ls))))
    return sorted(ls)


def SelectSort(target):
    ls = target.copy()
    for i in range(len(ls)):
        minj = i
        for j in range(i+1, len(ls)):
            if ls[j] < ls[minj]:
                minj = j
        if ls[i] != ls[minj]:
            ls[i], ls[minj] = ls[minj], ls[i]
    
    print((' '.join(map(str, ls))))
    return sorted(ls)

def judge(original, sorted_list):
    if original == sorted_list:
        print('Stable')
    else:
        print('Not stable')


_ = int(eval(input()))
l2 =  [Card(i) for i in input().split()]
l2_sort = sorted(l2)

bubble = BubbleSort(l2)
judge(l2_sort, bubble)

select = SelectSort(l2)
judge(l2_sort, select)



# Optimized solution
class Card():
    def __init__(self, card):
        self.card = card
        self.mark = card[0]
        self.number = card[1]
        
    def __lt__(self, other):
        if not isinstance(other, Card):
            return NotImplemented
        return self.number < other.number
        
    def __repr__(self):
        return '{}{}'.format(self.mark, self.number)


def BubbleSort(target):
    ls = target.copy()
    flag = 1
    while flag:
        flag = 0
        for i in range(len(ls)-1, 0, -1):
            if ls[i] < ls[i-1]:
                ls[i], ls[i-1] = ls[i-1], ls[i]
                flag = 1
    print((' '.join(map(str, ls))))
    return sorted(ls)


def SelectSort(target):
    ls = target.copy()
    for i in range(len(ls)):
        minj = i
        for j in range(i+1, len(ls)):
            if ls[j] < ls[minj]:
                minj = j
        if ls[i] != ls[minj]:
            ls[i], ls[minj] = ls[minj], ls[i]
    
    print((' '.join(map(str, ls))))
    return sorted(ls)

def judge(original, sorted_list):
    if original == sorted_list:
        print('Stable')
    else:
        print('Not stable')


_ = int(eval(input()))
l2 =  [Card(i) for i in input().split()]
l2_sort = sorted(l2)

bubble = BubbleSort(l2)
judge(l2_sort, bubble)

select = SelectSort(l2)
judge(l2_sort, select)
# Original solution
def bubbleSort( cards ):
    n = len( cards )
    for i in range( 0, n ):
        for j in range( n-1 , i, -1 ):
            if int( cards[j][1] ) < int( cards[ j-1 ][1] ):
                cards[j], cards[ j-1 ] = cards[ j-1 ], cards[j]
 
    print(( " ".join( map( str, cards ) ) ))
 
def selectionSort( cards ):
	n = len( cards )
	for i in range( 0, n ):
		mini = i
		for j in range( i , n ):
			if int( cards[j][1] ) < int( cards[ mini ][1] ):
				mini = j
		if mini != i:
			cards[i], cards[ mini ] = cards[ mini ], cards[i]

	print(( " ".join( map( str, cards ) ) ))


n = int( eval(input( )) )
cards = input( ).split( " " )
cards2 = list( cards )
bubbleSort( cards )
print( "Stable" )
selectionSort( cards2 )
if " ".join( map( str, cards2 ) ) == " ".join( map( str, cards ) ):
	print( "Stable" )
else:
	print( "Not stable" )

# Optimized solution
def bubbleSort( cards ):
    n = len( cards )
    for i in range( 0, n ):
        for j in range( n-1 , i, -1 ):
            if int( cards[j][1] ) < int( cards[ j-1 ][1] ):
                cards[j], cards[ j-1 ] = cards[ j-1 ], cards[j]
 
    print(( " ".join( map( str, cards ) ) ))
 
def selectionSort( cards ):
	n = len( cards )
	for i in range( 0, n ):
		mini = i
		for j in range( i , n ):
			if int( cards[j][1] ) < int( cards[ mini ][1] ):
				mini = j
		if mini != i:
			cards[i], cards[ mini ] = cards[ mini ], cards[i]

	print(( " ".join( map( str, cards ) ) ))


n = int( input( ) )
cards = input( ).split( " " )
cards2 = list( cards )
bubbleSort( cards )
print( "Stable" )
selectionSort( cards2 )
if cards2 == cards:
	print( "Stable" )
else:
	print( "Not stable" )
# Original solution
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)

def maxValue(z:int, w:int, a:"List[int]", player:str) -> int:
    if not a:
        return abs(z-w)

    if player == "X": ## playerXが操作する。価値がmaxになるように
        value = 0
        for i in range(len(a)):
            value = max(maxValue(a[i],w,a[i+1:],"Y"),value)
    else: ## yが操作,価値がminになるように
        value = 10**9
        for i in range(len(a)):
            value = min(maxValue(z,a[i],a[i+1:],"X"),value)
    return value        

def solve(N: int, Z: int, W: int, a: "List[int]"):
    print((maxValue(Z,W,a,"X")))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, Z, W, a)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys

def solve(N: int, Z: int, W: int, a: "List[int]"):
    print((max(abs(a[N-1]-a[N-2]),abs(a[N-1]-W))))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, Z, W, a)

if __name__ == '__main__':
    main()
# Original solution
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 = list(map(int, input().split()))
a = list(map(int, input().split()))
memo = [[-1]*2 for _ in range(N)]
print((rec(0, 0)))

# Optimized solution
import sys
input = sys.stdin.readline

N, Z, W = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = [[0]*(2) for _ in range(N)]

for i in range(N-1, -1, -1):
    if i==0:
        dp[i][0] = abs(a[N-1]-W)
    else:
        dp[i][0] = abs(a[N-1]-a[i-1])
    
    for j in range(i+1, N):
        dp[i][0] = max(dp[i][0], dp[j][1])
    
    if i==0:
        dp[i][1] = abs(a[N-1]-Z)
    else:
        dp[i][1] = abs(a[N-1]-a[i-1])
    
    for j in range(i+1, N):
        dp[i][1] = min(dp[i][1], dp[j][0])

print((dp[0][0]))
# Original solution
import sys
input = sys.stdin.readline

N, Z, W = list(map(int, input().split()))
A = [W] + list(map(int, input().split()))

S = set(A)
GX = {s:[None]*N + [abs(A[N]-s)] for s in S}
GY = {s:[None]*N + [abs(A[N]-s)] for s in S}
minGX = {s:10**10 for s in S}
maxGY = {s:0      for s in S}

for k in range(N-1, -1, -1):
    ak = A[k]
    gx = max(GY[ak][k+1], maxGY[ak])
    gy = min(GX[ak][k+1], minGX[ak])
    for s in S:
        GX[s][k] = gx
        GY[s][k] = gy

    for s in S:
        maxGY[s] = max(GY[s][k+1], maxGY[s])
        minGX[s] = min(GX[s][k+1], minGX[s])

print((GX[W][0]))

# Optimized solution
import sys
input = sys.stdin.readline

N, Z, W = list(map(int, input().split()))
A = [W] + list(map(int, input().split())) # A[0]=W, A[i]=ai

GX = [None]*N # GX[i] := YがA[i] を取った直後の状況から到達しうる最大のスコア
GY = [None]*N # GY[i] := XがA[i] を取った直後の状況から到達しうる最小のスコア
minGX = 10**20
maxGY = 0

for k in range(N-1, -1, -1):
    GX[k] = max(abs(A[k]-A[N]), maxGY)
    GY[k] = min(abs(A[k]-A[N]), minGX)
    minGX = min(minGX, GX[k])
    maxGY = max(maxGY, GY[k])

print((GX[0]))
# Original solution
import sys

sys.setrecursionlimit(10**6)
INF = 10**12
N, Z, W = list(map(int, input().split()))
a = [Z] + list(map(int, input().split()))

def rec(X,Y,i,count):# i枚目まで取った
    if i == N:# 山札がないので得点計算して更新
        return abs(X-Y)
    else:
        if count % 2 == 0:# 今はXのターン
            tmp = -INF
            for j in range(i+1,N+1):
                tmp = max(tmp, rec(a[j], Y, j, count+1))
            return tmp
        else:# 今はYのターン
            tmp = INF
            for j in range(i+1,N+1):
                tmp = min(tmp, rec(X, a[j], j, count+1))
            return tmp

ans = rec(Z,W,0,0)
print(ans)

# Optimized solution
#!/usr/bin/env python3
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]))))
# Original solution
import sys
from functools import lru_cache
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10**7)

def main():
    N, Z, W = list(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()


# Optimized solution
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10**7)

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


# Optimized solution
import sys
input = sys.stdin.readline

N, Z, W = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = abs(a[-1] - W)
if N > 1:
    ans = max(ans, abs(a[-2] - a[-1]))
print(ans)
# Original solution
#!/usr/bin/env python3
#ABC78 D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,z,w = LI()
a = LI()
que = deque(a)
tmp1 = que.popleft()
tmp2 = w
turn = 0
cnt = 0
while que:
    if turn == 0:
        if tmp1 <= que[0]:
            tmp1 = que.popleft()
        else:
            turn = 1
    else:
        if tmp2 >= que[0]:
            tmp2 = que.popleft()
        else:
            turn = 0
    cnt += 1
    if cnt > n:
        print((abs(tmp1 - tmp2)))
print((abs(tmp1-tmp2)))


# Optimized solution
#!/usr/bin/env python3
#ABC78 D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,z,w = LI()
a = LI()
if n == 1:
    print((abs(a[-1] - w)))
else:
    print((max(abs(a[-1]-w),abs(a[-2]-a[-1]))))
# Original solution
n,z,w = list(map(int,input().split()))
a = list(map(int,input().split()))
xp = [0]*(n)
yp = [10000000000]*(n)
xp[0] = abs(a[n-1]-w)
for i in reversed(list(range(n))):
    for j in range(i+1,n):
        xp[i] = max(xp[i], yp[j])
        yp[i] = min(yp[i], xp[j])
    xp[i] = max(xp[i], abs(a[i-1]-a[n-1]))
    yp[i] = min(yp[i], abs(a[i-1]-a[n-1]))
print((xp[0]))

# Optimized solution
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[n-1]-w),abs(a[n-1]-a[n-2]))))
# Original solution
import sys
sys.setrecursionlimit(10 ** 5)

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

def calc(n, flag): #n: 残りの山の枚数　flag: ターンの管理
    #既に計算済みの場合その値を返す
    # if flag == True and dp_T[n] != -1:
    #     return dp_T[n]
    # if flag == False and dp_F[n] != -1:
    #     return dp_F[n]

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

print((calc(N, True)))


# Optimized solution
N, Z, W = list(map(int, input().split()))
a = list(map(int, input().split()))
print((max(abs(a[N-1] - W), abs(a[N-1] - a[N - 2]))))
# Original solution
N,Z,W=list(map(int,input().split()))
A=list(map(int,input().split()))
A.append(Z)
A.append(W)

dp=[[[0 for i in range(0,2)] for j in range(0,N+2)] for k in range(0,N+1)]

for i in range(0,N+2):
    dp[N-1][i][0]=abs(A[N-1]-A[i])
    dp[N-1][i][1]=abs(A[N-1]-A[i])


for i in range(1,N):
    for j in range(0,N+2):
        I=N-1-i
        dp[I][j][0]=max(dp[I+1][I][1],dp[I+1][j][0],abs(A[N-1]-A[j]))
        dp[I][j][1]=min(dp[I+1][I][0],dp[I+1][j][1],abs(A[N-1]-A[j]))

print((dp[0][N+1][0]))

# Optimized solution
N,Z,W=list(map(int,input().split()))
A=list(map(int,input().split()))
A.append(Z)
A.append(W)


dpx=[[0 for j in range(0,N+2)] for k in range(0,N+1)]
dpy=[[0 for j in range(0,N+2)] for k in range(0,N+1)]

for i in range(0,N+2):
    dpx[N-1][i]=abs(A[N-1]-A[i])
    dpy[N-1][i]=abs(A[N-1]-A[i])


for i in range(1,N):
    for j in range(0,N+2):
        I=N-1-i
        dpx[I][j]=max(dpy[I+1][I],dpx[I+1][j],abs(A[N-1]-A[j]))
        dpy[I][j]=min(dpx[I+1][I],dpy[I+1][j],abs(A[N-1]-A[j]))

print((dpx[0][N+1]))
# Original solution
N,Z,W=list(map(int,input().split()))
a=list(map(int,input().split()))
INF=10**19
dp=[[0]*2 for i in range(N+1)]
for i in range(N-1,-1,-1):
    dp[i][0]=-INF
    if i: Y=a[i-1]
    else: Y=W
    dp[i][0]=max(dp[i][0],abs(Y-a[N-1]))
    for j in range(i+1,N): dp[i][0]=max(dp[i][0],dp[j][1])

    dp[i][1]=INF
    if i: X=a[i-1]
    else: X=Z
    dp[i][1]=min(dp[i][1],abs(X-a[N-1]))
    for j in range(i+1,N): dp[i][1]=min(dp[i][1],dp[j][0])
print((dp[0][0]))


# Optimized solution
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]))))