#include <bits/stdc++.h>
using namespace std;
using ivec = vector<int>;
const int mod = 1e9+7;
struct products {
int maxScore = 0;
inline int sum(const ivec &a, int u, int v) {
int s = 0;
while (u < v)
if (s += a[u++], s >= mod)
s -= mod;
return s; }
inline void mac(const ivec &a, int i, int u, int v) {
long long w = 1ll*i*sum(a,u,v);
if (w %= mod, maxScore += w, maxScore >= mod)
maxScore -= mod; }
inline products(ivec &a, int m) {
int n = a.size(), p = n/m, u = 0, v = m;
sort(a.begin(),a.end());
for (int i = 1; i < p; ++i)
mac(a,i,u,v), u = v, v += m;
mac(a,p,u,n); } };
inline int maxScore(ivec &a, int m) { return products(a,m).maxScore; }
int main() {
int n, m; ivec a;
ios_base::sync_with_stdio(0), cin.tie(0), cin >> n >> m, a.resize(n);
for (auto &b: a)
cin >> b;
cout << maxScore(a,m); }
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnVzaW5nIGl2ZWMgPSB2ZWN0b3I8aW50PjsKY29uc3QgaW50IG1vZCA9IDFlOSs3OwoKc3RydWN0IHByb2R1Y3RzIHsKCWludCBtYXhTY29yZSA9IDA7CglpbmxpbmUgaW50IHN1bShjb25zdCBpdmVjICZhLCBpbnQgdSwgaW50IHYpIHsKCQlpbnQgcyA9IDA7CgkJd2hpbGUgKHUgPCB2KQoJCQlpZiAocyArPSBhW3UrK10sIHMgPj0gbW9kKQoJCQkJcyAtPSBtb2Q7CgkJcmV0dXJuIHM7IH0KICAgIGlubGluZSB2b2lkIG1hYyhjb25zdCBpdmVjICZhLCBpbnQgaSwgaW50IHUsIGludCB2KSB7CiAgICAJbG9uZyBsb25nIHcgPSAxbGwqaSpzdW0oYSx1LHYpOwogICAgCWlmICh3ICU9IG1vZCwgbWF4U2NvcmUgKz0gdywgbWF4U2NvcmUgPj0gbW9kKQogICAgCQltYXhTY29yZSAtPSBtb2Q7IH0KICAgIGlubGluZSBwcm9kdWN0cyhpdmVjICZhLCBpbnQgb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