Problem:
Score : 500 points

Problem Statement

We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i.

Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action:

Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn.

The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand.

X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?

Constraints

All input values are integers.

1 \leq N \leq 2000

1 \leq Z, W, a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N Z W
a_1 a_2 ... a_N

Output

Print the score.

Sample Input 1

3 100 100
10 1000 100

Sample Output 1

900

If X draws two cards first, Y will draw the last card, and the score will be |1000 - 100| = 900.

Sample Input 2

3 100 1000
10 100 100

Sample Output 2

900

If X draws all the cards first, the score will be |1000 - 100| = 900.

Sample Input 3

5 1 1
1 1 1 1 1

Sample Output 3

0

Sample Input 4

1 1 1
1000000000

Sample Output 4

999999999

Solution in C (GCC 5.4.1) (judge verdict: Runtime Error)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
  scanf("%d %d %d", a1, a2, a3);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 2000
#define NUM2_MAX (1<<11)
#define INF (1e+9)

int asc(const void *a1, const void *a2) {
    return *(int*)a1 - *(int*)a2;
}

struct pair {
    int max;
    int min;
};

struct pair calc(struct pair p1, struct pair p2) {
    return (struct pair){max(p1.max, p2.max), min(p1.min, p2.min)};
}

#define ROOT_NODE 1

void update(struct pair *seg, int num, struct pair new, int idx) {
    int node = num + idx;
    seg[node] = new;
    while((node = node/2)) {
        seg[node] = calc(seg[node*2], seg[node]);
    }
    return;
}

int main(void) {
    int num, xscore, yscore;
    get_int3(&num, &xscore, &yscore);
    static int arr[NUM_MAX];
    fget_array(arr, num);
    int i;
    int num2 = 1;
    while(num > num2) num2 *= 2;

    struct pair seg[NUM_MAX*2];

    for(i = 0; i < num; i++) {
        seg[num2+i] = (struct pair){arr[i], arr[i]};
    }
    for(i = num2-1; i >= 0; i--) {
        seg[i] = calc(seg[i*2], seg[i*2+1]);
    }

    int turn = 0; // X's turn
    for(i = 0; i < num; i++) {
        int val = arr[i];
        struct pair mp = seg[ROOT_NODE];
        // X takes maximum value
        if(turn == 0 && val == mp.max) {
            turn = 1;
            xscore = val;
        // Y takes minimum value
        } else if(turn == 1 && val == mp.min) {
            turn = 0;
            yscore = val;
        }
        struct pair np = {.max = 0, .min = INF};
        update(seg, num2, np, i);
    }
    printf("%d\n", abs(xscore-yscore));
    return 0;
}