Universal Cup Judging System

Universal Cup

Time Limit: 8 s Memory Limit: 2048 MB Total points: 100
Statistics

Notes: For participants in the Prime Contest, please note that partial scores do not count as a solved problem during the contest. You must achieve a full score (100 points) for the problem to be considered solved.

You are given a sequence of $n$ distinct positive integers $[a_1, a_2, \dots, a_n]$ and a positive integer $k$.

Define that $z$ is contained by $(x, y)$ if and only if $\min(x, y) < z < \max(x, y)$.

Now, for each $1 \leq m \leq n$:

  • Let $b = [a_1, a_2, \dots, a_m]$.
  • You need to partition $b$ into several consecutive segments.
    • In each segment, you select two elements (which can be the same)
    • Suppose the two chosen elements in a segment are $u$ and $v$.
      • If there are at least $k$ elements in the segment that are not contained by $(u, v)$, then you can obtain a gain of $(u-v)^2$ for that segment;
      • otherwise, you can only obtain a gain of $0$ for that segment.
  • You need to determine, under the optimal strategy, the maximum total gain you can achieve.

Input

The first line contains two positive integers $n$ ($1 \le n \le 10^5$) and $k$ ($2 \le k \le 20$).

The second line contains $n$ distinct positive integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^7$). All elements of $a$ are distinct.

Output

Output one line containing $n$ integers $c_1, c_2, \dots, c_n$, where $c_i$ represents the answer for $m=i$.

Sample 1

Input

6 2
9 8 2 4 3 5

Output

0 1 49 49 50 53

Sample 2

Input

20 3
6 15 3 18 1 12 2 16 8 9 10 14 20 11 17 19 13 5 7 4

Output

0 0 81 144 225 225 337 340 340 386 386 386 468 468 468 514 514 612 612 664

Scoring

Notes: For participants in the Prime Contest, please note that partial scores do not count as a solved problem during the contest. You must achieve a full score (100 points) for the problem to be considered solved.

For all data, it is guaranteed that $1 \leq n \leq 10^5,\ 2 \leq k \leq 20,\ 1 \leq a_i \leq 10^7$, and all elements of $a$ are distinct.

Subtask 1 (8 points)

$n \leq 1\,000$

Subtask 2 (21 points)

$k = 2$

Subtask 3 (22 points)

$k \leq 3$

Subtask 4 (20 points)

$k \leq 5$

Subtask 5 (13 points)

$k \leq 8$

Subtask 6 (16 points)

No additional constraints.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.