Buggy python submission (verdict: Time Limit Exceeded):
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])

Fixed submission:
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])

Buggy python submission (verdict: Time Limit Exceeded):
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 s in S:
#    GX[s][N-1] = GY[A[N-1]][N]
#    GY[s][N-1] = GX[A[N-1]][N]

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


Fixed submission:
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])

Buggy python submission (verdict: Time Limit Exceeded):
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 s in S:
#    GX[s][N-1] = GY[A[N-1]][N]
#    GY[s][N-1] = GX[A[N-1]][N]

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

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

Fixed submission:
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])

Buggy python submission (verdict: Time Limit Exceeded):
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):
    for s in S:
        GX[s][k] = max(GY[A[k]][k+1], maxGY[A[k]])
        GY[s][k] = min(GX[A[k]][k+1], minGX[A[k]])

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

Fixed submission:
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])