No tag edit access

E. Maximum Subsequence

time limit per test

1 secondmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are given an array *a* consisting of *n* integers, and additionally an integer *m*. You have to choose some sequence of indices *b*_{1}, *b*_{2}, ..., *b*_{k} (1 ≤ *b*_{1} < *b*_{2} < ... < *b*_{k} ≤ *n*) in such a way that the value of is maximized. Chosen sequence can be empty.

Print the maximum possible value of .

Input

The first line contains two integers *n* and *m* (1 ≤ *n* ≤ 35, 1 ≤ *m* ≤ 10^{9}).

The second line contains *n* integers *a*_{1}, *a*_{2}, ..., *a*_{n} (1 ≤ *a*_{i} ≤ 10^{9}).

Output

Print the maximum possible value of .

Examples

Input

4 4

5 2 4 1

Output

3

Input

3 20

199 41 299

Output

19

Note

In the first example you can choose a sequence *b* = {1, 2}, so the sum is equal to 7 (and that's 3 after taking it modulo 4).

In the second example you can choose a sequence *b* = {3}.

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Feb/26/2018 00:40:12 (d1).

Desktop version, switch to mobile version.

User lists

Name |
---|