Problem list
Log in
#coci00629 · COCI 2022/2023 Contest 1

Neboderi

Platinum II 2.5 s 512 MB

Domagoj is in the big city of London! Right now, there is a sequence of tall skyscrapers in front of him and he wants to take a photograph to remember the moment. The sequence of skyscrapers can be represented as a sequence of $n$ numbers $h_{1}$, $h_{2}$, . . . , $h_{n}$ where the number $h_{i}$ represents the height of the $i$-th skyscraper. Domagoj will photograph a contiguous subsequence of skyscrapers. To capture more of the city’s beauty, he wants to photograph at least $k$ skyscrapers. Domagoj has a strange sense of beauty of a photograph. He is very happy when there are tall skyscrapers in the photograph, but he is even happier when their heights have a large common divisor! If we label the heights of the contiguous skyscrapers on the photograph with $h_{l}$, . . . , $h_{r}$, and with $g$ the greatest common divisor of the selected heights, then Domagoj defines the beauty of the photograph as $g$ · ($h_{l}$ + . . . + $h_{r}$). Help Domagoj determine the beauty of the most beautiful photograph with at least $k$ skyscrapers!

Input

The first line contains two integers $n$, $k$ ($1 \le k \le n \le 10^{6}$), the number of skyscrapers, and the number $k$. The second line contains $n$ integers $h_{1}$, $h_{2}$, . . . , $h_{n}$ ($1 \le h_{i} \le 10^{6}$), the heights of the skyscrapers, in order.

Output

Print a single line with the required number from the task.

Example 1

Input
6 2
2 1 4 4 4 2
Output
48

Example 2

Input
4 1
7 3 9 4
Output
81

Clarification of the first example: Domagoj photographed skyscrapers ( 4, 4, 4 ), so the total beauty is 4 · (4 + 4 + 4) = 48 Clarification of the second example: Domagoj photographed only the skyscraper ( 9 ), so the total beauty is 9 · 9 = 81.

Source
COCI 2022/2023 Contest 1
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code