#include <bits/stdc++.h>
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define pb push_back
#define ln << '\n'
#define int long long
using namespace std;

const int N = 2e6 + 22;
int n, k, a[N], ku[N], an[N];

int32_t main() {
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int cur = 0;
    for (int i = 1; i <= n; i++) {
        ku[cur]++;
        an[cur] = max(an[cur], a[i] + ku[cur]);

        cur++;
        cur %= k;
    }
    int ans = 0;
    for (int i = 0; i < k; i++) ans += an[i];
    cout << ans;
    return 0;
}