Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
INF=10**18

def main():
    N,Z,W=map(int,input().split())
    a=list(map(int,input().split()))
    dic={}
    def rec(z,w,now,t):
        if dic.get((now,t),None)!=None:
            return dic[(now,t)]
        if now>=N-1:
            return abs(z-w)
        if not t:
            res=-INF
            for i in range(now+1,N):
                r=rec(a[i],w,i,1)
                res=max(res,r)
        else:
            res=INF
            for i in range(now+1,N):
                r=rec(z,a[i],i,0)
                res=min(res,r)
        dic[(now,t)]=res
        return res

    return rec(Z,W,-1,0)
    
print(main())

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
INF=10**18

def main():
    N,Z,W=map(int,input().split())
    a=list(map(int,input().split()))
    dic={}
    def rec(z,w,now,t):
        if dic.get((now,t),None)!=None:
            return dic[(now,t)]
        if now>=N-1:
            return abs(z-w)
        if not t:
            res=-INF
            for i in range(now+1,N):
                r=rec(a[i],w,i,1)
                res=max(res,r)
        else:
            res=INF
            for i in range(now+1,N):
                r=rec(z,a[i],i,0)
                res=min(res,r)
        dic[(now,t)]=res
        return res

    return rec(Z,W,-1,0)
    
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
INF=10**18
def rec(z,w,now,t):
    global N
    if dic.get((z,w,now,t),None)!=None:
        return dic[(z,w,now,t)]
    if now==N-1:
        dic[(z,w,now,t)]=abs(z-w)
        return abs(z-w)
    if t==0:
        res=-INF
        for i in range(now+1,N):
            res=max(res,rec(a[i],w,i,1))
    elif t==1:
        res=INF
        for i in range(now+1,N):
            res=min(res,rec(z,a[i],i,0))
    dic[(z,w,now,t)]=res
    return res

N,Z,W=map(int,input().split())
a=list(map(int,input().split()))
dic={}

print(rec(Z,W,-1,0))

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
INF=10**18

def main():
    N,Z,W=map(int,input().split())
    a=list(map(int,input().split()))
    dic={}
    def rec(z,w,now,t):
        if dic.get((now,t),None)!=None:
            return dic[(now,t)]
        if now>=N-1:
            return abs(z-w)
        if not t:
            res=-INF
            for i in range(now+1,N):
                r=rec(a[i],w,i,1)
                res=max(res,r)
        else:
            res=INF
            for i in range(now+1,N):
                r=rec(z,a[i],i,0)
                res=min(res,r)
        dic[(now,t)]=res
        return res

    return rec(Z,W,-1,0)
    
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
INF=10**18
def rec(z,w,now,t):
    global N
    if dic.get((z,w,now,t),None)!=None:
        return dic[(z,w,now,t)]
    if now==N-1:
        return abs(z-w)
    if t==0:
        res=-INF
        for i in range(now+1,N):
            res=max(res,rec(a[i],w,i,1))
    elif t==1:
        res=INF
        for i in range(now+1,N):
            res=min(res,rec(z,a[i],i,0))
    dic[(z,w,now,t)]=res
    return res

N,Z,W=map(int,input().split())
a=list(map(int,input().split()))
dic={}

print(rec(Z,W,-1,0))

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
INF=10**18

def main():
    N,Z,W=map(int,input().split())
    a=list(map(int,input().split()))
    dic={}
    def rec(z,w,now,t):
        if dic.get((now,t),None)!=None:
            return dic[(now,t)]
        if now>=N-1:
            return abs(z-w)
        if not t:
            res=-INF
            for i in range(now+1,N):
                r=rec(a[i],w,i,1)
                res=max(res,r)
        else:
            res=INF
            for i in range(now+1,N):
                r=rec(z,a[i],i,0)
                res=min(res,r)
        dic[(now,t)]=res
        return res

    return rec(Z,W,-1,0)
    
print(main())