N, M = map(int, input().split())
a = list(map(int, input().split()))


prefiks_zbir = [0] * (N + 1)
for i in range(N):
    prefiks_zbir[i + 1] = prefiks_zbir[i] + a[i]


dp = [[0] * N for _ in range(N)]
for d in range(1, N + 1):
    for l in range(N - d + 1):
        r = l + d - 1
        zbir = prefiks_zbir[r + 1] - prefiks_zbir[l]
        dp[l][r] = max(zbir - dp[l + 1][r], zbir - dp[l][r - 1])


rezultati = [0] * M
for i in range(M):
    for j in range(i, N, M):
        rezultati[i] += dp[j][min(j + M - 1, N - 1)]


print(" ".join(map(str, rezultati)))