#P8663. Maximum Triple Sum Divisible by $K$
Maximum Triple Sum Divisible by $K$
Maximum Triple Sum Divisible by
You are given an integer n and an integer K. Following that, there are n integers. Your task is to select exactly three numbers from these n numbers such that their sum is a multiple of $K$ (i.e. the sum modulo $K$ equals 0) and the sum is as large as possible. It is guaranteed that at least one such triple exists.
Note: The number K in the problem statement appears in the conditions as $K$.
inputFormat
The first line contains two integers n and K separated by a space.
The second line contains n integers separated by spaces.
Constraints: It is guaranteed that there is at least one valid triple.
outputFormat
Output a single integer, representing the maximum sum of any three numbers that is divisible by $K$.
sample
5 3
1 5 3 7 9
21