cswork / OAOpen practice workspace

AmazonOA #103

Calculate Maximum Quality Score

Estimated MediumJudge-ready

Topics (AI-labelled)State MachinesDP Basics

You must choose a non-empty range and either multiply all of it by impactFactor or divide all of it by that factor, rounding toward 0. After the operation, find the maximum possible sum of a non-empty contiguous subarray.

Input

The first line contains n impactFactor (1≤n≤200000, 1≤impactFactor≤10000); the second line contains n ratings (−100000..100000).

Output

Output a single integer answer.

Example 1

Input:

5 2
5 -3 -3 2 4

Output:

12

Example 2

Input:

4 1
-2 3 -3 -1

Output:

3

Example 3

Input:

2 2
-5 -3

Output:

-1

Example notes

Example 1: multiplying the last 2 and 4 by 2 turns them into 4 and 8, for a maximum sum of 12. Example 2: a factor of 1 changes nothing, so choosing 3 gives 3. Example 3: −3 divided by 2 rounded toward 0 is −1, which is the maximum quality score obtainable.

Editorial

Loading solution…