#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
int a[N], l[N], r[N];
stack<int> st;
int main() {
  int n, k, ans, minx, maxx;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  while (!st.empty()) st.pop();
  for (int i = 1; i <= n; i++) {
    while (!st.empty() && a[st.top()] < a[i]) st.pop();
    if (st.empty())
      l[i] = 1;
    else
      l[i] = st.top() + 1;
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (int i = n; i >= 1; i--) {
    while (!st.empty() && a[st.top()] <= a[i]) st.pop();
    if (st.empty())
      r[i] = n;
    else
      r[i] = st.top() - 1;
    st.push(i);
  }
  ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i - l[i] < r[i] - i) {
      for (int j = l[i]; j <= i; j++) {
        minx = max(i - j, k - 1);
        maxx = r[i] - j + 1;
        if (minx < maxx) {
          ans += 1LL *
                 (max(0, maxx - 1) / (k - 1) - max(0, minx - 1) / (k - 1)) *
                 a[i] % mod;
          ans %= mod;
        }
      }
    } else {
      for (int j = i; j <= r[i]; j++) {
        minx = max(j - i, k - 1);
        maxx = j - l[i] + 1;
        if (minx < maxx) {
          ans += 1LL *
                 (max(0, maxx - 1) / (k - 1) - max(0, minx - 1) / (k - 1)) *
                 a[i] % mod;
          ans %= mod;
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
