Under construction

Still being built. Things may change

Stimulant

Interview

Time limit10sMemory limit512 MB

Summary
Given daily study and gaming hours and K stimulants that double the effect from their day on, find the maximum total skill with at most one stimulant per day.
Level

Medium5 of 10

Topics
Prefix sum, Sorting, Greedy
Solved
No attempts yet

Problem

Junhyuk takes special training to become an expert in algorithms. During the training period, on some days he only studies, and on other days he only plays games.

Junhyuk's training lasts NN days. Each hour of studying during the training period raises his skill by 1, and each hour of gaming lowers it by 1. If he studies for 5 hours on day 1 and plays games for 3 hours on day 2, the total increase in skill is 2. To maximize the efficiency of his studying, Junhyuk orders KK stimulants with a special effect. When he takes a stimulant, he becomes awakened from that day on. Every hour of studying and gaming from that day, including that day, has double effect.

The effects of stimulants stack. For example, if he takes a stimulant on day 1 and another on day 2, then on day 3, one hour of studying raises his skill by 4. Conversely, one hour of gaming on day 3 lowers his skill by 4.

Junhyuk takes at most one stimulant per day, and he does not have to take all KK stimulants he ordered. Find the maximum total skill gained from studying by the last day, when he takes the stimulants appropriately.

Input

The first line contains NN and KK (1≤N,K≤10,0001 \le N,K \le 10,000).

The second line contains NN integers separated by spaces. On day ii, if he studies for xx hours, the value is xx. If he plays games for xx hours, the value is −x-x. A day in Junhyuk's training is 1,000,000 hours, not 24. (1≤∣x∣≤1,000,0001 \le |x| \le 1,000,000)

Output

Print the maximum skill Junhyuk can gain by taking stimulants appropriately, taken modulo 1,000,000,0071,000,000,007 (109+710^9+7). If the maximum is negative, print it as is, without taking the modulo.

It can be proven that the maximum is always greater than −263-2^{63}.

Examples1

  1. Example 1

    Input
    10 5
    1 -2 3 1 -1 -3 4 1 -2 1
    
    Expected output
    98