Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(114514)

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

memo = {}
def act(xlast, ylast, turn):
    x = z if xlast == -1 else aa[xlast]
    y = w if ylast == -1 else aa[ylast]

    if xlast == n - 1 or ylast == n - 1:
        return abs(x - y)
    
    if (xlast, ylast, turn) in memo:
        return memo[(xlast, ylast, turn)]
    
    if turn == 0:
        # x turn
        ans = 0
        for i in range(ylast + 1, n):
            ans = max(ans, act(i, ylast, 1))
    else:
        # y turn
        ans = 1 << 30
        for i in range(xlast + 1, n):
            ans = min(ans, act(xlast, i, 0))
    
    memo[(xlast, ylast, turn)] = ans
    return ans

print(act(-1, -1, 0))


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

Buggy python submission (verdict: Runtime Error):
n, z, w = map(int, input().split())
aa = list(map(int, input().split()))

memo = {}
def act(xlast, ylast, turn):
    x = z if xlast == -1 else aa[xlast]
    y = w if ylast == -1 else aa[ylast]

    if xlast == n - 1 or ylast == n - 1:
        return abs(x - y)
    
    if (xlast, ylast, turn) in memo:
        return memo[(xlast, ylast, turn)]
    
    if turn == 0:
        # x turn
        ans = 0
        for i in range(ylast + 1, n):
            ans = max(ans, act(i, ylast, 1))
    else:
        # y turn
        ans = 1 << 30
        for i in range(xlast + 1, n):
            ans = min(ans, act(xlast, i, 0))
    
    memo[(xlast, ylast, turn)] = ans
    return ans

print(act(-1, -1, 0))


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

Buggy python submission (verdict: Runtime Error):
n, z, w = map(int, input().split())
aa = list(map(int, input().split()))

memo = {}
def act(xlast, ylast, turn):
    x = z if xlast == -1 else aa[xlast]
    y = w if ylast == -1 else aa[ylast]

    if xlast == n - 1 or ylast == n - 1:
        return abs(x - y)
    
    if (xlast, ylast, turn) in memo:
        return memo[(xlast, ylast, turn)]
    
    if turn == 0:
        # x turn
        ans = 0
        for i in range(ylast + 1, n):
            ans = max(ans, act(i, ylast, 1))
    else:
        # y turn
        ans = 1 << 30
        for i in range(xlast + 1, n):
            ans = min(ans, act(xlast, i, 0))
    
    memo[(xlast, ylast, turn)] = ans
    return ans

print(act(-1, -1, 0))


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