#K61717. Max Sum After Operations

    ID: 31372 Type: Default 1000ms 256MiB

Max Sum After Operations

Max Sum After Operations

You are given an array of N integers along with an integer K. You must choose exactly one of the following operations to perform on the array:

  • Operation 1 (No Change): The array remains the same and the sum is \(S = \sum_{i=1}^{N} a_i\).
  • Operation 2 (Increment Each Element by 1): Each element in the array is increased by 1. The new sum becomes \(S + N\).
  • Operation 3 (Double Each Element): Each element in the array is doubled. The new sum becomes \(2S\).
  • Operation 4 (Modulo Operation): Replace each element \(a_i\) with \(a_i \bmod K\). The new sum is \(\sum_{i=1}^{N} (a_i \bmod K)\).

Your task is to compute the maximum possible sum of the array after applying exactly one of these operations. Choose the operation that yields the maximum total sum and output that sum.

inputFormat

The input is provided via standard input in the following format:

  • The first line contains two space-separated integers: N (the number of elements in the array) and K.
  • The second line contains N space-separated integers representing the array elements.

outputFormat

Output a single integer, which is the maximum sum achievable after applying one of the operations.

## sample
5 10
1 2 3 4 5
30