#include <bits/stdc++.h>
using namespace std;
const int mo = 1e9 + 7;
const int maxn = 1000010;
int n, k, l[maxn], r[maxn], lc;
long long ans, a[maxn], h[maxn];
int main() {
  scanf("%d%d", &n, &k);
  l[1] = 1;
  r[n] = n;
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]), h[i] = (h[i - 1] + 1ll * i / (k - 1)) % mo;
  for (int i = 2; i <= n; i++) {
    lc = i;
    while (lc > 1 && a[lc - 1] <= a[i]) {
      lc = l[lc - 1];
    }
    l[i] = lc;
  }
  for (int i = n - 1; i >= 1; i--) {
    lc = i;
    while (lc < n && a[lc + 1] < a[i]) {
      lc = r[lc + 1];
    }
    r[i] = lc;
  }
  for (int x = 1; x <= n; x++)
    ans = (ans +
           a[x] *
               (h[r[x] - l[x]] - h[r[x] - x - 1] - h[x - l[x] - 1] + 2ll * mo) %
               mo) %
          mo;
  printf("%lld\n", ans);
  return 0;
}
