pog loves szh II

Accepts: 97
Submissions: 834
Time Limit: 4000/2000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description
Pog and Szh are playing games. There is a sequence with $n$ numbers, Pog will choose a number A from the sequence. Szh will choose an another number named B from the rest in the sequence. Then the score will be $(A+B)$ mod $p$. They hope to get the largest score. And what is the largest score?
Input
Several groups of data (no more than $5$ groups,$n \geq 1000$). For each case: The following line contains two integers,$n(2 \leq n \leq 100000)$£¬$p(1 \leq p \leq 2^{31}-1)$¡£ The following line contains $n$ integers $a_i(0 \leq a_i \leq 2^{31}-1)$¡£
Output
For each case,output an integer means the largest score.
Sample Input
4 4
1 2 3 0
4 4
0 0 2 2
Sample Output
3
2