func_code_string: #include <bits/stdc++.h>   using namespace std;   const long double Pi = 3.14159265359;   const long long MOD = (long long)1e9 + 7;   const long long MAXN = (long long)1e6 + 10;   const long long INF = (long long)9223372036854775;   const long double EPS = (long double)1e-8;   long long dp[MAXN];   long long dpx[MAXN];   long long a[MAXN];   deque<long long> de;   stack<long long> s;   long long mk[MAXN];   long long lb[MAXN];   int main() {     long long n, k;     scanf( %lld , &n);     scanf( %lld , &k);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     for (int i = 0; i < k - 1; i++) {       while (de.size() != 0) {         if (a[de.back()] <= a[i])           de.pop_back();         else           break;       }       de.push_back(i);     }     for (int i = k - 1; i < n; i++) {       while (de.size() != 0) {         if (a[de.back()] <= a[i])           de.pop_back();         else           break;       }       de.push_back(i);       if (i - de.front() >= k) de.pop_front();       mk[i] = de.front();     }     de.clear();     for (int i = 0; i < n; i++) {       while (de.size() != 0) {         if (a[de.back()] <= a[i])           de.pop_back();         else           break;       }       if (de.size() == 0)         lb[i] = -1;       else         lb[i] = de.back();       de.push_back(i);     }     long long nex, cnt, pa;     for (int i = k - 1; i < n; i++) {       nex = lb[mk[i]];       if (nex == -1) {         dpx[i] = ((a[mk[i]]) * (i / (k - 1))) % MOD;       } else {         cnt = i - nex - 1;         pa = cnt / (k - 1);         dpx[i] = (dpx[i - (pa * (k - 1))] + ((a[mk[i]]) * pa)) % MOD;       }     }     long long ans = 0;     for (int i = 0; i < n; i++) ans = (ans + dpx[i]) % MOD;     printf( %lld , ans);     return 0;   }   