#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
vector<long long> len, slen;
long long f(long long l, long long r, int k) {
  ++l;
  ++r;
  if (l > r) swap(l, r);
  long long res = 0;
  int it = upper_bound(len.begin(), len.end(), l) - len.begin();
  if (it > 0) res = (res + slen[it]) % mod;
  int itr = upper_bound(len.begin(), len.end(), r) - len.begin();
  if (itr > it) res = (res + l * (itr - it)) % mod;
  int it2 = upper_bound(len.begin(), len.end(), r + l) - len.begin();
  if (it2 > itr)
    res = (res + (l + r) * (it2 - itr) - (slen[it2] - slen[itr])) % mod;
  return res % mod;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (long long t = 1;; ++t) {
    long long cur = k + (k - 1) * (t - 1);
    if (cur > n) break;
    len.push_back(cur);
  }
  slen.assign(len.size() + 1, 0);
  for (int i = 0; i < (int)len.size(); ++i) {
    slen[i + 1] = slen[i] + len[i];
  }
  vector<int> a(n);
  vector<pair<int, int> > ts(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    ts[i] = pair<int, int>(a[i], i);
  }
  sort(ts.begin(), ts.end());
  vector<int> pr(n), nx(n);
  for (int i = 0; i < n; ++i) {
    pr[i] = i - 1;
    nx[i] = i + 1;
  }
  long long res = 0;
  for (int t = 0; t < n; ++t) {
    int i = ts[t].second;
    int l = i - pr[i] - 1, r = nx[i] - i - 1;
    res = (res + a[i] * f(l, r, k)) % mod;
    if (pr[i] >= 0) nx[pr[i]] = nx[i];
    if (nx[i] < n) pr[nx[i]] = pr[i];
  }
  cout << (res % mod + mod) % mod << endl;
  return 0;
}
