#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
const int mod = 1e9 + 7;
const int maxn = 1000100;
int val[maxn * 4];
pair<int, int> a[maxn];
int n, k;
set<int> s;
int dy[maxn];
void init() {
  for (int i = 0; i <= 4000000; i++) val[i] = i / (k - 1);
  for (int i = 0; i <= 4000000; i++) (val[i] += val[i - 1]) %= mod;
}
inline int fnd(int x) {
  if (x >= 0)
    return val[x];
  else
    return 0;
}
inline int calc(int t, int j) {
  long long ret = 0;
  ret += (fnd(j + t) - fnd(j - 1) + mod) % mod;
  ret = (ret + mod - fnd(t - 1)) % mod;
  return (int)(ret);
}
int main() {
  n = read(), k = read();
  for (register int i = (int)(1); i <= (int)(n); i++)
    a[i].first = read(), a[i].second = i;
  init();
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  s.insert(1);
  dy[1] = n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int x = a[i].first, pos = a[i].second;
    set<int>::iterator it = s.lower_bound(pos);
    if ((*it) != pos) {
      if (it == s.begin()) continue;
      it--;
    }
    int l = *it, r = dy[l];
    if (r - l + 1 < k) continue;
    ans = (ans + calc(pos - l, r - pos) * 1ll * x % mod) % mod;
    if (pos == l)
      s.erase(l);
    else
      dy[l] = pos - 1;
    if (pos < r) {
      s.insert(pos + 1);
      dy[pos + 1] = r;
    }
  }
  cout << ans << endl;
  return 0;
}
