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


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

Buggy python submission (verdict: Time Limit Exceeded):
#!/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
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
print(abs(tmp1-tmp2))


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