Language: C++

#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

//////////////////////////////////////////////////

const int mod = 1e9+7;

// combination c(n+10)
// c(n, k) => nCk
struct combination {
    const int max = 510000;
    vector<long long> fact, ifact, inv;
    combination() {
        fact.resize(max);
        ifact.resize(max);
        inv.resize(max);
        fact[0] = fact[1] = 1;
        ifact[0] = ifact[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < max; i++) {
            fact[i] = fact[i-1] * i % mod;
            inv[i] = mod - inv[mod%i] * (mod/i) % mod;
            ifact[i] = ifact[i-1] * inv[i] % mod;
        }
    }

    long long operator()(int n, int k) {
        if (n < k) return 0;
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]%mod*ifact[n-k]%mod;
    }
};

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());

    int ans = 0;
    combination c;

    rep(i,n) {
        ll cnt = c(i,k-1);
        ll mx = cnt*a[i]%mod, mn = cnt*a[n-i-1]%mod;
        ans = (ans+mx-mn) % mod;
        if (ans < 0) ans += mod;
    }
    cout << ans << endl;
    return 0;
}#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

//////////////////////////////////////////////////

const int mod = 1e9+7;

// combination c(n+10)
// c(n, k) => nCk
struct combination {
    const int max = 510000;
    vector<long long> fact, ifact, inv;
    combination() {
        fact.resize(max);
        ifact.resize(max);
        inv.resize(max);
        fact[0] = fact[1] = 1;
        ifact[0] = ifact[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < max; i++) {
            fact[i] = fact[i-1] * i % mod;
            inv[i] = mod - inv[mod%i] * (mod/i) % mod;
            ifact[i] = ifact[i-1] * inv[i] % mod;
        }
    }

    long long operator()(int n, int k) {
        if (n < k) return 0;
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]%mod*ifact[n-k]%mod;
    }
};

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());

    int ans = 0;
    combination c;

    rep(i,n) {
        ll cnt = c(i,k-1);
        ll mx = cnt*a[i]%mod, mn = cnt*a[n-i-1]%mod;
        ans = (ans+mx-mn) % mod;
        if (ans < 0) ans += mod;
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc:70:2: error: stray '#' in program
   70 | }#include<iostream>
      |  ^
a.cc:70:3: error: 'include' does not name a type
   70 | }#include<iostream>
      |   ^~~~~~~
a.cc:87:23: error: redefinition of 'template<class T> bool chmax(T&, const T&)'
   87 | template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
      |                       ^~~~~
a.cc:18:23: note: 'template<class T> bool chmax(T&, const T&)' previously declared here
   18 | template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
      |                       ^~~~~
a.cc:88:23: error: redefinition of 'template<class T> bool chmin(T&, const T&)'
   88 | template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
      |                       ^~~~~
a.cc:19:23: note: 'template<class T> bool chmin(T&, const T&)' previously declared here
   19 | template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
      |                       ^~~~~
a.cc:90:5: error: redefinition of 'int dx []'
   90 | int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
      |     ^~
a.cc:21:5: note: 'int dx [4]' previously defined here
   21 | int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
      |     ^~
a.cc:90:27: error: redefinition of 'int dy []'
   90 | int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
      |                           ^~
a.cc:21:27: note: 'int dy [4]' previously defined here
   21 | int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
      |                           ^~
a.cc:94:11: error: redefinition of 'const int mod'
   94 | const int mod = 1e9+7;
      |           ^~~
a.cc:25:11: note: 'const int mod' previously defined here
   25 | const int mod = 1e9+7;
      |           ^~~
a.cc:98:8: error: redefinition of 'struct combination'
   98 | struct combination {
      |        ^~~~~~~~~~~
a.cc:29:8: note: previous definition of 'struct combination'
   29 | struct combination {
      |        ^~~~~~~~~~~
a.cc:122:5: error: redefinition of 'int main()'
  122 | int main() {
      |     ^~~~
a.cc:53:5: note: 'int main()' previously defined here
   53 | int main() {
      |     ^~~~