#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005, mod = 1000000007;
long long f[maxn];
int arr[maxn], lft[maxn], rgt[maxn], sta[maxn], n, K;
int main() {
  scanf("%d%d", &n, &K);
  int tp = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", arr + i);
    while (tp > 0 && arr[sta[tp]] <= arr[i]) rgt[sta[tp--]] = i - 1;
    lft[i] = sta[tp] + 1;
    sta[++tp] = i;
    long long t = i / (K - 1);
    f[i] = (t * i - (K - 1) * t * (t + 1) / 2) % mod;
  }
  for (int i = 1; i <= n; i++)
    if (!rgt[i]) rgt[i] = n;
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    res = ((f[rgt[i] - lft[i] + 1] - f[rgt[i] - i] - f[i - lft[i]]) * arr[i] +
           res) %
          mod;
    if (res < 0) res += mod;
  }
  printf("%lld\n", res);
  return 0;
}
