Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

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: May/23/2018 02:38:49 (d2).

Desktop version, switch to mobile version.

User lists

Name |
---|