#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
void pd(int &x) {
  if (x >= 1000000007)
    x -= 1000000007;
  else if (x < 0)
    x += 1000000007;
}
int n, k, a[N];
int ans;
set<int> s;
set<int>::iterator it;
pair<int, int> rnk[N];
int f[N], len, l, r;
int solve(int l, int r, int mid) {
  r -= l - 1;
  mid -= l - 1;
  l = 1;
  int ans = f[r] - f[mid - 1];
  pd(ans);
  pd(ans -= f[r - mid]);
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) pd(f[i] = f[i - 1] + (i - 1) / (k - 1));
  for (int i = 1; i <= n; i++) rnk[i] = make_pair(a[i], i);
  sort(rnk + 1, rnk + 1 + n);
  for (int i = n; i >= 1; i--) {
    int cur = rnk[i].second;
    s.insert(cur);
    it = s.find(cur);
    if (it != s.begin()) {
      it--;
      l = (*it) + 1;
      it++;
    } else
      l = 1;
    it++;
    if (it != s.end())
      r = (*it) - 1;
    else
      r = n;
    pd(ans += 1ll * solve(l, r, cur) * a[cur] % 1000000007);
  }
  cout << ans;
  return 0;
}
