Problem A
Gort
Gort is also a bit greedy and doesn’t want to share. His friends are all sleeping nearby, and if he wakes them, they will all want a share of his harvest. Gort wants to eat as many melons as possible.
But he has a very strange superstition. Gort believes that if the total count of melons he picks is an exact multiple of $k$, his munching will be perfectly quiet, and his friends will stay asleep. If he picks a number of melons that is not a multiple of k, he’ll make a loud noise, which will wake up everyone.
Gort eats only whole melons; he thinks fractional slices are for the weak.
Your task is to help Gort figure out the maximum total size of all melons he can eat while ensuring that the number of melons eaten is a multiple of $k$.
Input
The first line of input contains an integer $N$ ($1 \le N \le 10^5$). The following $N$ lines contain the sizes $s$ of the melons, one integer per line ($1 \le s \le 10^9$). The final line contains the integer $k$ ($1 \le k \le N$).
Output
Print a single integer representing the maximum total size of melons Gort can eat.
| Sample Input 1 | Sample Output 1 |
|---|---|
4 10 20 30 40 1 |
100 |
| Sample Input 2 | Sample Output 2 |
|---|---|
5 1 2 3 4 5 2 |
14 |
