#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * inf;
const int N = 1000000 + 7;
const int M = 10000 + 7;
const int multipleTest = 0;
const double pi = acos(-1);
int n, k;
int a[N];
vector<pair<int, int> > h;
set<int> present;
long long dp[N];
void solve() {
  cin >> n >> k;
  for (int i = (0), _b = (n); i < _b; ++i) {
    scanf("%d", a + i);
    h.push_back({-a[i], i + 1});
  }
  sort(h.begin(), h.end());
  dp[0] = 0;
  long long low = 0;
  for (int i = 1; i <= n; ++i) {
    long long t = i / (k - 1);
    dp[i] = (i * t - (1ll * t * (t + 1) / 2) * (k - 1)) % inf;
    if (dp[i] < 0) dp[i] += inf;
  }
  long long res = 0;
  for (auto& p : h) {
    long long u = p.first;
    int i = p.second;
    int lhs = 1, rhs = n;
    auto it = present.lower_bound(i);
    if (it != present.end()) rhs = (*it) - 1;
    if (it != present.begin()) {
      --it;
      lhs = (*it) + 1;
    }
    long long cur = (dp[rhs - lhs + 1] - dp[i - lhs] - dp[rhs - i]);
    if (cur < 0) cur += inf;
    cur = (cur * -u);
    res = (res + cur) % inf;
    if (res < 0) res += inf;
    present.insert(i);
  }
  cout << res << '\n';
}
int main() {
  int Test = 1;
  if (multipleTest) {
    cin >> Test;
  }
  for (int i = 0; i < Test; ++i) {
    solve();
  }
}
