Picking Numbers on a Circle

Pick exactly K numbers from a circle of N values so that no two chosen are adjacent, maximizing the sum.

Hard8Dynamic programmingGreedyHeapLinked listNo attempts yetTime limit1sMemory limit512 MB

Problem

kcm1700 gave ntopia the following task. NN numbers are placed around a circle. Pick KK of them so that no two picked numbers are neighbors, and make the sum of the picked numbers as large as possible. Picking neighbors means that among the picked numbers there are two that sit next to each other on the circle.

The numbers form a circle, so the first number and the last number are neighbors too. Write a program that computes the largest sum you can get by picking KK numbers with no two of them adjacent.

Input

The first line contains a positive integer NN (3N1063 \le N \le 10^6) and an integer KK (1KN/21 \le K \le N/2), separated by a space.

The second line contains the NN natural numbers of the circle in clockwise order, separated by spaces. Each number is smaller than 2312^{31}.

Output

Print the maximum sum on the first line. The answer is smaller than 2312^{31}.