#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using dbl = double;
const int INF = (int)1e9 + 10;
const ll LINF = ll(2e18) + 10;
const double PI = acosl(-1);
const double eps = 1e-8;
const int P = 1e9 + 7;
int sum(int a, int b) {
  a += b;
  return a >= P ? a - P : a;
}
int sub(int a, int b) { return sum(a, P - b); }
int mul(int a, int b) { return (ll)a * b % P; }
const int N = 1e6 + 10;
const int H = (P + 1) / 2;
int a[N], n, k;
int get(int x, int y) {
  if (min(x, y) == -1) return max(x, y);
  if (a[x] < a[y]) return y;
  return x;
}
struct Segt {
  int arr[4 * N];
  void build(int ind, int l, int r) {
    if (l == r) {
      arr[ind] = l;
      return;
    }
    int m = (l + r) / 2;
    build(ind * 2, l, m);
    build(ind * 2 + 1, m + 1, r);
    arr[ind] = ::get(arr[ind * 2], arr[ind * 2 + 1]);
  }
  int get(int ind, int l, int r, int L, int R) {
    if (L <= l && r <= R) return arr[ind];
    if (r < L || R < l) return -1;
    int m = (l + r) / 2;
    return ::get(get(ind * 2, l, m, L, R), get(ind * 2 + 1, m + 1, r, L, R));
  }
  int get(int l, int r) { return get(1, 0, n - 1, l, r); }
} segt;
int prog(int len) {
  --len;
  (void)0;
  int rem = len % (k - 1);
  len /= (k - 1);
  return sum(mul(k - 1, mul(len, mul(len + 1, H))), mul(rem, len + 1));
}
int cnt(int pos, int len) {
  auto p = prog(pos + 1);
  int q = sub(prog(len + 1), prog(len - pos));
  return sub(sub(q, p), 1);
}
int solve(int l, int r) {
  if (l > r) return 0;
  int id = segt.get(l, r);
  int ans = sum(solve(id + 1, r), solve(l, id - 1));
  int add = mul(a[id], cnt(id - l, r - l + 1));
  return sum(ans, add);
}
void solve() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  segt.build(1, 0, n - 1);
  printf("%d\n", solve(0, n - 1));
}
int main() {
  solve();
  (void)0;
}
