CF1100A.Roman and Browser

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Roman and Browser

This morning, Roman woke up and opened the browser with nn opened tabs numbered from 11 to nn. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.

He decided to accomplish this by closing every kk-th (2kn12 \leq k \leq n - 1) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be bb) and then close all tabs with numbers c=b+ikc = b + i \cdot k that satisfy the following condition: 1cn1 \leq c \leq n and ii is an integer (it may be positive, negative or zero).

For example, if k=3k = 3, n=14n = 14 and Roman chooses b=8b = 8, then he will close tabs with numbers 22, 55, 88, 1111 and 1414.

After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it ee) and the amount of remaining social network tabs (ss). Help Roman to calculate the maximal absolute value of the difference of those values es|e - s| so that it would be easy to decide what to do next.

Input

The first line contains two integers nn and kk (2k<n1002 \leq k \lt n \leq 100) — the amount of tabs opened currently and the distance between the tabs closed.

The second line consists of nn integers, each of them equal either to 11 or to 1-1. The ii-th integer denotes the type of the ii-th tab: if it is equal to 11, this tab contains information for the test, and if it is equal to 1-1, it's a social network tab.

Output

Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types es|e - s|.

Note

In the first example we can choose b=1b = 1 or b=3b = 3. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, e=2e = 2 and s=0s = 0 and es=2|e - s| = 2.

In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.

Samples

4 2
1 1 -1 1
2
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
9

在线编程 IDE

建议全屏模式获得最佳体验