CF958C2 Encryption (medium)

Description

Heidi has now broken the first level of encryption of the Death Star plans, and is staring at the screen presenting her with the description of the next code she has to enter. It looks surprisingly similar to the first one – seems like the Empire engineers were quite lazy... Heidi is once again given a sequence $ A $ , but now she is also given two integers $ k $ and $ p $ . She needs to find out what the encryption key $ S $ is. Let $ X $ be a sequence of integers, and $ p $ a positive integer. We define the score of $ X $ to be the sum of the elements of $ X $ modulo $ p $ . Heidi is given a sequence $ A $ that consists of $ N $ integers, and also given integers $ k $ and $ p $ . Her goal is to split $ A $ into $ k $ part such that: - Each part contains at least $ 1 $ element of $ A $ , and each part consists of contiguous elements of $ A $ . - No two parts overlap. - The total sum $ S $ of the scores of those parts is maximized. Output the sum $ S $ – the encryption code.

Input Format

N/A

Output Format

N/A

Explanation/Hint

In the first example, if the input sequence is split as $ (3,4) $ , $ (7) $ , $ (2) $ , the total score would be ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF958C2/d4a5357e9a4720ebdcbfc92aa797cf51b7b836c8.png). It is easy to see that this score is maximum. In the second example, one possible way to obtain score $ 37 $ is to make the following split: $ (16,3,24) $ , $ (13,9) $ , $ (8) $ , $ (7) $ , $ (5,12,12) $ .