#include <bits/stdc++.h>
using namespace std;
long long int cons;
long long int check(long long int a) {
  if (a >= cons) a %= cons;
  return a;
}
long long int check2(long long int a) {
  a %= cons;
  if (a < 0) a += cons;
  return a;
}
long long int fast_check(long long int a) {
  if (a >= cons) a -= cons;
  return a;
}
long long int GCD(long long int a, long long int b) {
  while (a && b) {
    a = a % b;
    if (a != 0) b = b % a;
  }
  return a + b;
}
long long int exp(long long int a, long long int n) {
  long long int ans = 1;
  a = check(a);
  while (n) {
    if (n & 1) ans = check(ans * a);
    a = check(a * a);
    n = (n >> 1);
  }
  return ans;
}
void print_pair(pair<int, int> p) {
  cout << p.first << " " << p.second << endl;
}
long long int nc2(long long int a) { return (a * (a - 1)) / 2; }
const int N = 1e6 + 2;
long long int arr[N];
long long int l[N], r[N];
long long int n, k;
long long int getSum(long long int i) {
  long long int temp = (i * (i + 1)) / 2;
  temp = check(temp);
  return check(temp * (k - 1) + i);
}
long long int coun(int i) {
  long long int lef = i - l[i] - 1;
  long long int rig = r[i] - i - 1;
  long long int temp = k - 1;
  long long int less = min(lef, rig) / temp;
  long long int mid_less = max(lef, rig) / temp;
  long long int tot = (lef + rig) / temp;
  long long int sum1 = getSum(less);
  long long int sum2 = check((mid_less - less) * (min(lef, rig) + 1));
  long long int sum3 = (getSum(tot) - getSum(mid_less)) % cons;
  if (sum3 < 0) sum3 += cons;
  long long int sum4 = (tot - mid_less) * (rig + lef + 2);
  sum4 -= sum3;
  sum4 %= cons;
  if (sum4 < 0) sum4 += cons;
  return check(sum1 + sum2 + sum4);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cons = 1e9 + 7;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  arr[0] = 2e9;
  arr[n + 1] = 2e9;
  stack<int> s;
  s.push(0);
  for (int i = 1; i <= n; i++) {
    while (arr[i] > arr[s.top()]) s.pop();
    l[i] = s.top();
    s.push(i);
  }
  while (!s.empty()) s.pop();
  s.push(n + 1);
  for (int i = n; i >= 1; i--) {
    while (arr[i] >= arr[s.top()]) s.pop();
    r[i] = s.top();
    s.push(i);
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    long long int temp = coun(i);
    ans += check(temp * arr[i]);
  }
  cout << check(ans) << endl;
}

### Prompt

Construct a cpp code solution to the problem outlined:

Given an array a of n integers and an integer k (2 ≤ k ≤ n), where each element of the array is denoted by a_i (0 ≤ i < n). Perform the operation z given below on a and print the value of z(a,k) modulo 10^{9}+7.
    
    
      
    function z(array a, integer k):  
        if length(a) < k:  
            return 0  
        else:  
            b = empty array  
            ans = 0  
            for i = 0 .. (length(a) - k):  
                temp = a[i]  
                for j = i .. (i + k - 1):  
                    temp = max(temp, a[j])  
                append temp to the end of b  
                ans = ans + temp  
            return ans + z(b, k)  
    

Input

The first line of input contains two integers n and k (2 ≤ k ≤ n ≤ 10^6) — the length of the initial array a and the parameter k.

The second line of input contains n integers a_0, a_1, …, a_{n - 1} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a.

Output

Output the only integer, the value of z(a,k) modulo 10^9+7.

Examples

Input

3 2
9 1 10


Output

29


Input

5 3
5 8 7 1 9


Output

34

Note

In the first example: 

  * for a=(9,1,10), ans=19 and b=(9,10), 
  * for a=(9,10), ans=10 and b=(10), 
  * for a=(10), ans=0. 



So the returned value is 19+10+0=29.

In the second example: 

  * for a=(5,8,7,1,9), ans=25 and b=(8,8,9), 
  * for a=(8,8,9), ans=9 and b=(9), 
  * for a=(9), ans=0. 



So the returned value is 25+9+0=34.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int cons;
long long int check(long long int a) {
  if (a >= cons) a %= cons;
  return a;
}
long long int check2(long long int a) {
  a %= cons;
  if (a < 0) a += cons;
  return a;
}
long long int fast_check(long long int a) {
  if (a >= cons) a -= cons;
  return a;
}
long long int GCD(long long int a, long long int b) {
  while (a && b) {
    a = a % b;
    if (a != 0) b = b % a;
  }
  return a + b;
}
long long int exp(long long int a, long long int n) {
  long long int ans = 1;
  a = check(a);
  while (n) {
    if (n & 1) ans = check(ans * a);
    a = check(a * a);
    n = (n >> 1);
  }
  return ans;
}
void print_pair(pair<int, int> p) {
  cout << p.first << " " << p.second << endl;
}
long long int nc2(long long int a) { return (a * (a - 1)) / 2; }
const int N = 1e6 + 2;
long long int arr[N];
long long int l[N], r[N];
long long int n, k;
long long int getSum(long long int i) {
  long long int temp = (i * (i + 1)) / 2;
  temp = check(temp);
  return check(temp * (k - 1) + i);
}
long long int coun(int i) {
  long long int lef = i - l[i] - 1;
  long long int rig = r[i] - i - 1;
  long long int temp = k - 1;
  long long int less = min(lef, rig) / temp;
  long long int mid_less = max(lef, rig) / temp;
  long long int tot = (lef + rig) / temp;
  long long int sum1 = getSum(less);
  long long int sum2 = check((mid_less - less) * (min(lef, rig) + 1));
  long long int sum3 = (getSum(tot) - getSum(mid_less)) % cons;
  if (sum3 < 0) sum3 += cons;
  long long int sum4 = (tot - mid_less) * (rig + lef + 2);
  sum4 -= sum3;
  sum4 %= cons;
  if (sum4 < 0) sum4 += cons;
  return check(sum1 + sum2 + sum4);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cons = 1e9 + 7;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  arr[0] = 2e9;
  arr[n + 1] = 2e9;
  stack<int> s;
  s.push(0);
  for (int i = 1; i <= n; i++) {
    while (arr[i] > arr[s.top()]) s.pop();
    l[i] = s.top();
    s.push(i);
  }
  while (!s.empty()) s.pop();
  s.push(n + 1);
  for (int i = n; i >= 1; i--) {
    while (arr[i] >= arr[s.top()]) s.pop();
    r[i] = s.top();
    s.push(i);
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    long long int temp = coun(i);
    ans += check(temp * arr[i]);
  }
  cout << check(ans) << endl;
}

```