criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお


const int mod = 1000000007;
const int MAX = 300001;
 
ll fc[MAX];
ll fci[MAX];
 
ll modpow(ll a,ll b){
  return b?modpow(a*a%mod,b/2)*(b%2?a:1)%mod:1;
}
 
void init_fact() {
    fc[0] = fc[1] = 1;
    for (int i=2; i<MAX; ++i) {
        fc[i] = (fc[i-1] * i) % mod;
    }
    fci[1] = 1;
    for (int i=2; i<MAX; ++i) {
        fci[i] = (fci[i-1] * modpow(i, mod-2)) % mod;
    }
}
 
ll C(ll n, ll k) {
    if (k == 0 || n == k) return 1;
    return ((fc[n] * fci[k] % mod) * fci[n-k]) % mod;
}
 
ll add(ll a, ll b) { return (a + b) % mod; }
ll sub(ll a, ll b) { return (a - b + mod) % mod; }
ll mul(ll a, ll b) { return (a * b) % mod; }
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(ALL(a));

    ll ans = 0;
    rep(ri,2) {
        rep(i,n) {
            ll now = C(i,k-1);
            if (ri == 1) now = -now;
            ans = add(ans,now);
        }
        reverse(ALL(a));
    }
    cout << ans << endl;
    
    return 0;
}

Compiler output:
a.cc:34:11: error: conflicting declaration 'const int mod'
   34 | const int mod = 1000000007;
      |           ^~~
a.cc:24:17: note: previous declaration as 'const long long int mod'
   24 | const long long mod = 1000000007;
      |                 ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define MAX 200000

long int fac[MAX],inv[MAX],finv[MAX];

void pre(){
  fac[0]=fac[1]=1;
  inv[1]=1;
  finv[0]=finv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=(fac[i-1]*i)%MOD;
    inv[i]=MOD-(inv[MOD%i]*(MOD%i))%MOD;
    finv[i]=finv[i-1]*inv[i];
  }
}

long int com(int n,int k){
  return ((fac[n]*finv[k])%MOD)*finv[n-k]%MOD;
}

int main(){
  pre();
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  
  sort(A.begin(),A.end());
  long int sum=0;
  for(int i=0;i<N-K+1;i++){
    sum+=A.at(i+K-1)*com(i+K-1,K-1)%MOD-A.at(N-K-i)*com(i+K-1,K-1)%MOD;
    if(sum<0){
      sum+=MOD;
    }
    sum%=MOD;
  }
  cout<<sum<<endl;
}
  
  
  
  

Compiler output:
a.cc: In function 'int main()':
a.cc:35:19: error: 'K' was not declared in this scope
   35 |   for(int i=0;i<N-K+1;i++){
      |                   ^
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<queue>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second

typedef pair<lint, lint> P;
const lint MOD = 1e9+7;
const lint INF = MOD * MOD;

Compiler output:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
Language: Java

import java.util.*;

public class Problem5Solution {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
      int[] A = new int[N];
      for (int i = 0; i < N; i++) {
         A[i] = sc.nextInt() % 1000000007;
      }
      Arrays.sort(A);
      int min_sum = 0;
      for (int i = 0; i < A.length; i++) {
         int end = nCr(A.length - i - 1, K - 1);
         for (int j = 0; j < end; j++) {
            min_sum += A[i];
            min_sum %= 1000000007;
         }
      }
      int max_sum = 0;
      for (int i = A.length - 1; i >= 0; i--) {
         int end = nCr(i, K - 1);
         for (int j = 0; j < end; j++) {
            max_sum += A[i];
            max_sum %= 1000000007;
         }
      }
      System.out.println((max_sum - min_sum) % 1000000007);
   }
   
   public static int nCr(int n, int r) {
      if (n == 0 || n < r) {
         return 0;
      }
      int result = 1;
      r = Math.min(r, n-r);
      for (int i = n; i > n - r; i--) {
         result *= i;
      }
      for (int i = r; i >= 1; i--) {
         result /= i;
      }
      return result;
   }
}

Compiler output:
Main.java:3: error: class Problem5Solution is public, should be declared in a file named Problem5Solution.java
public class Problem5Solution {
       ^
1 error
Language: C++

#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const ll mod = 1000000000+7;

//二項係数
/*繰り返し自乗法*/
ll fac[1001001];
ll invfac[1001001];
ll mod_pow(ll a, ll n, ll p){
    if(n == 0){
        return 1;
    }
    if(n%2){
        return (a * mod_pow(a, n-1, p)) % p;
    }
    ll t = mod_pow(a, n/2, p);
    return (t*t)%p;
}

ll combination(ll n, ll r, ll mod){
    if(r < 0 || r > n)  return 0;
    ll ret = fac[n];
    (ret *= invfac[n-r]) %= mod;
    (ret *= invfac[r]) %= mod;
    return ret;
}

int main(){
    int n, k;   cin >> n >> k;  
    fac[0] = 1;
    for(ll i = 1; i <= 1001001; i++){
        fac[i] = fac[i-1] * i;
        fac[i] %= mod;
    } 
    for(ll i = 0; i <= 1001001; i++) invfac[i] = mod_pow(fac[i], mod-2, mod);
    vector<ll>a(n);
    rep(i, n)   cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    rep(j, 2){
        for(int i = n-1; i >= k-1; i--){
            switch(j){
                case 0:
                    ll tmp = a[i] * combination(i, k-1, mod);
                    tmp %= mod;
                    ans += tmp;
                break;
                case 1:
                    ll tmp = a[i] * combination(i, k-1, mod);
                    tmp %= mod;
                    ans -= tmp;
                break;
            }
            ans %= mod;
        }
        reverse(a.begin(), a.end());
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:55:22: error: jump to case label
   55 |                 case 1:
      |                      ^
a.cc:51:24: note:   crosses initialization of 'll tmp'
   51 |                     ll tmp = a[i] * combination(i, k-1, mod);
      |                        ^~~
a.cc:56:24: error: redeclaration of 'll tmp'
   56 |                     ll tmp = a[i] * combination(i, k-1, mod);
      |                        ^~~
a.cc:51:24: note: 'll tmp' previously declared here
   51 |                     ll tmp = a[i] * combination(i, k-1, mod);
      |                        ^~~
Language: C++

//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const ll N=100005;
ll p[N],pp[N],bb[N];
ll power(ll x,ll y){
	ll re=1;
	while(y>0){
		if(y%2)re=re*x%hell;
		y=y/2;
		x=x*x%hell;
	}
	return re;
}
fun(ll n,ll k){
	ll re=p[n]*power(p[k],hell-2)%hell;
    re=re*power(p[n-k],hell-2)%hell;
	return re;
}
int main(){
	ll n,k;
	cin>>n>>k;
	ll a[n+1],sum1=0,sum2=0;
	for(ll i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	for(ll i=1;i<=n;i++){
		pp[i]=a[i];
		bb[i]=a[n-i+1];
	}
	for(ll i=n-1;i>=1;i--)pp[i]=(pp[i]+pp[i+1])%hell;
	for(ll i=n-1;i>=1;i--)bb[i]=(bb[i]+bb[i+1])%hell;
	p[0]=1;
	for(ll i=1;i<N;i++)p[i]=p[i-1]*i%hell;
	for(ll i=k;i<=n;i++){
		sum1=(sum1+fun(i-2,k-2)*pp[i]%hell)%hell;
		sum2=(sum2+fun(i-2,k-2)*bb[i]%hell)%hell;
		//cout<<sum1<<" "<<sum2<<endl;
	}
	cout<<(sum1-sum2+hell)%hell;
}

Compiler output:
a.cc:37:1: error: ISO C++ forbids declaration of 'fun' with no type [-fpermissive]
   37 | fun(ll n,ll k){
      | ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int k;
vector<ll> a(100000);
int MOD=1000000007;
vector<ll> memo(100000);
vector<ll> memo_inv(100000);


int combination(int i,int j);
long long modinv(long long a,long long m);
int main(){
  cin >> n;
  cin >> k;
  for(int i=0;i<n;i++){
    cin >> a.at(i); 
  }
  memo.at(0)=1;
  for(int i=1;i<n;i++){
    memo.at(i)=(memo.at(i-1)*(i))%MOD;
  }
  for(int i=0;i<n;i++){
    memo_inv.at(i)=modinv(memo.at(i),MOD);
  }



  sort(a.begin(),a.begin()+n);
  reverse(a.begin(),a.begin()+n);
  ll ans=0;
  for(int i=0;i<n;i++){
    int p = n-i-1;
    if(p>=k-1){
      ll c = combination(p,k-1);
      ans = (ans + (c*a.at(i))%MOD)%MOD;
    }
  }
  reverse(a.begin(),a.begin()+n);
  for(int i=0;i<n;i++){
    int p=n-i-1;
    if(p>=k-1){
      ll c = combination(p,k-1);
      ans = (ans + (-c*a.at(i))%MOD)%MOD;
    }
  }
  cout << ans << endl;
}

ll combination(int i,int j){
  ll n_kai = memo.at(i);
  ll r_kai = memo_inv.at(j);
  ll n_r_kai = memo_inv.at(i-j);
  return (((n_kai*r_kai)%MOD)*n_r_kai)%MOD;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

Compiler output:
a.cc:51:4: error: ambiguating new declaration of 'll combination(int, int)'
   51 | ll combination(int i,int j){
      |    ^~~~~~~~~~~
a.cc:12:5: note: old declaration 'int combination(int, int)'
   12 | int combination(int i,int j);
      |     ^~~~~~~~~~~
Language: C++

fun main(args: Array<String>) {

    val mod = 1e9.toLong() + 7

    class Comb {

        val n = 1e5.toInt()

        val fact = LongArray(n + 1)
        val factInv = LongArray(n + 1)

        init {
            fact[1] = 1L
            for (i in 2 .. n) {
                fact[i] = fact[i - 1] * i % mod
            }
            factInv[n] = inv(fact[n])
            for (i in n downTo 1) {
                factInv[i - 1] = factInv[i] * i % mod
            }
        }

        private fun pow(base: Long, exp: Long): Long {
            if (exp == 0L) return 1L
            var a = pow(base, exp shr 1)
            a *= a
            a %= mod
            if (exp and 1L == 0L) return a
            return base * a % mod
        }

        private fun inv(x: Long): Long {
            return pow(x, mod - 2)
        }

        fun comb(n: Int, k: Int): Long {
            if (k !in 0..n) return 0L
            return fact[n] * factInv[k] % mod * factInv[n - k] % mod
        }

    }

    val cb = Comb()

    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    var a = readLine()!!.split(' ').map { it.toLong() }.sorted()

    val ans = LongArray(2)

    repeat(2) {
        for (i in 0 until n) {
            if (i + 1 < k) continue
            if (a[i] >= 0) {
                val b = a[i] * cb.comb(i, k - 1) % mod
                ans[it] = ans[it] + b % mod
            } else {
                val b = -a[i] * cb.comb(i, k - 1) % mod
                ans[it] = (ans[it] + mod - b) % mod
            }
        }
        a = a.reversed()
    }

    println((ans[0] + mod - ans[1]) % mod)
}


Compiler output:
a.cc:37:23: error: too many decimal points in number
   37 |             if (k !in 0..n) return 0L
      |                       ^~~~
a.cc:1:1: error: 'fun' does not name a type
    1 | fun main(args: Array<String>) {
      | ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<vector<double>> vvd;
typedef vector<double> vd;

#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_LOG = 21;
const int MAX_N = 12800;

#define forn(i, n) for(int i = 0; i < n; i++)
#define forsn(i, s, n) for(int i = s; i < n; i++)
#define all(x) x.begin(), x.end()

ll expmod(ll x, ll n, ll mod){
	if(n == 0) return 1;
	else if(n % 2 == 0){
		ll temp = expmod(x, n / 2, mod);
		return (temp * temp) % mod;
	}
	else{
		return (expmod(x, n - 1, mod) * x) % mod;
	}
}

ll modinv(ll x, ll mod){
	return expmod(x, mod - 2, mod);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n, k;
	cin >> n >> k;
	ll a[n], maxi = 0, mini = 0;
	forn(i, n){
		cin >> a[i];
	}
	sort(a, a + n);
	ll fac[n + 1], inv_fac[n + 1];
	fac[0] = 1; inv_fac[0] = 1;
	for(int i = 1; i <= n; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv_fac[i] = inv_fac[i - 1] * modinv(i, MOD) % MOD;
	}
	for(ll i = k - 1; i < n; i++){
		const ll mult = fac[i] * inv_fac[k - 1] % MOD * inv_fac[i - k + 1] %;
		maxi += mult * a[i] % MOD;
		maxi %= MOD;
		mini += mult * a[n - i - 1] % MOD;
		mini %= MOD;
		// trace3(mult, maxi, mini);
	}
	ll ans = maxi - mini;
	ans %= MOD;
	if(ans < 0){
		ans += MOD;
	}
	cout << ans << endl;
}		


Compiler output:
a.cc: In function 'int main()':
a.cc:67:85: error: expected primary-expression before ';' token
   67 |                 const ll mult = fac[i] * inv_fac[k - 1] % MOD * inv_fac[i - k + 1] %;
      |                                                                                     ^
Language: C

H, K = map(int,input().split())
A = list(map(int, input().split()))
mod = int(10**9) + 7
A.sort()

nCkminu1 = [1] * H
for n in range(K, H):
    nCkminu1[n] = nCkminu1[n-1] * n // (n - (K-1))
    nCkminu1[n] %= mod

ans = 0
for nCk, amin, amax in zip(nCkminu1[K-1:], A[:-(K-1)][::-1], A[K-1:]):
    ans +=  nCk * (amax - amin)

print(ans % mod)


Compiler output:
main.c:1:1: warning: data definition has no type or storage class
    1 | H, K = map(int,input().split())
      | ^
main.c:1:1: error: type defaults to 'int' in declaration of 'H' [-Wimplicit-int]
main.c:1:4: error: type defaults to 'int' in declaration of 'K' [-Wimplicit-int]
    1 | H, K = map(int,input().split())
      |    ^
main.c:1:8: error: implicit declaration of function 'map' [-Wimplicit-function-declaration]
    1 | H, K = map(int,input().split())
      |        ^~~
main.c:1:12: error: expected expression before 'int'
    1 | H, K = map(int,input().split())
      |            ^~~
main.c:2:1: error: expected ',' or ';' before 'A'
    2 | A = list(map(int, input().split()))
      | ^
Language: C++

#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x(x % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
} comb(100005);

mint f(int n, int k) {
    if (n < 0) return 0;
    // nPk = nCk * k!
    mint res = comb(n, k);
    res *= comb.fact[k];
    return res;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    mint ans = 0;
    rep(i, N) {
        if (i >= K - 1) {
            ans += mint(A[i]) * comb(i, K - 1); // max
        } else {
           // ans += mint(A[i]) * comb(i, K - 1); // max
          //mint tmp = mint(A[i]) * comb(i, K - 1);
          //if(tmp.x) {
          //cerr << "i:" << i << " K:" << K << " tmp:" << tmp.x << " comb" << comb(i, K - 1).x << endl;
          }
        }

        ans -= mint(A[i]) * comb(N - 1 - i, K - 1); // min
    }

    cout << ans.x % mod << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:115:23: error: 'i' was not declared in this scope
  115 |         ans -= mint(A[i]) * comb(N - 1 - i, K - 1); // min
      |                       ^
a.cc: At global scope:
a.cc:118:5: error: 'cout' does not name a type
  118 |     cout << ans.x % mod << endl;
      |     ^~~~
a.cc:119:1: error: expected declaration before '}' token
  119 | }
      | ^
Language: C++

#include <bits/stdc++.h>

const long long MODULO = 1000000007;

using namespace std;

vector<long long> fact(100001);

void precalc() {
  	fact[0] = 1;
  	for (int i = 1; i <= n; ++i) {
      fact[i] = fact[i - 1] * i;
  	  fact[i] %= MODULO;
	}
  	return;
}

long long binpow(long long a, long long b) {
	long long res = 1;
  	while (b) {
    	if (b & 1) {
        	res *= a;
          	res %= MODULO;
        }
      	a *= a;
      	a %= MODULO;
      	b >>= 1;
    }
  	return res;
}

long long C(long long n, long long k) {
	if (n < k) return 0;
  	return ((fact[n] * binpow(fact[n - k], MODULO - 2)) % MODULO) * binpow(fact[k], MODULO - 2)) % MODULO;
}

int main() {
  	precalc();
	int n, k;
  	cin >> n >> k;
  	vector<long long> a(n);
  	for (int i = 0; i < n; ++i)
    	cin >> a[i];
  	sort(a.begin(), a.end());
  	ll ans = 0;
  	for (int i = 0; i < n; ++i) {
    	ans += (a[i] * C(i, k))	% MODULO;
     	ans %= MODULO;
      	ans += MODULO;
      	ans -= (a[i] * C(n - k - 1, k)) % MODULO;
      	ans %= MODULO;
    }
  	cout << ans << '\n';
  	return 0;
}

Compiler output:
a.cc: In function 'void precalc()':
a.cc:11:30: error: 'n' was not declared in this scope
   11 |         for (int i = 1; i <= n; ++i) {
      |                              ^
a.cc: In function 'long long int C(long long int, long long int)':
a.cc:34:100: error: expected ';' before ')' token
   34 |         return ((fact[n] * binpow(fact[n - k], MODULO - 2)) % MODULO) * binpow(fact[k], MODULO - 2)) % MODULO;
      |                                                                                                    ^
      |                                                                                                    ;
a.cc:34:100: error: expected primary-expression before ')' token
a.cc: In function 'int main()':
a.cc:45:9: error: 'll' was not declared in this scope
   45 |         ll ans = 0;
      |         ^~
a.cc:47:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   47 |         ans += (a[i] * C(i, k)) % MODULO;
      |         ^~~
      |         abs
a.cc:53:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   53 |         cout << ans << '\n';
      |                 ^~~
      |                 abs
Language: C++

/*
 Σf(x) = Σ(max(x)-min(x)) = Σ max(x) - Σ min(x)
 まず入力をソートする
 N = 7, K = 4
 {1 , 2 , 3 , 4 , 4 , 5 , 6}
 ここで,5が最大値になる集合のパターンは
 5以下の数から集合を選んだ場合になる、そのパターンの数はcombination(5,3)
 最小の場合は、これをreverseでソートする.
 ※※※※※※ combination=nCk ※※※※※※
 これはライブラリを使う。
*/

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];

  sort(all(A));
  combination c(N + 5);

  mint maxSum = 0, minSum = 0;
  REP(i, N) { maxSum += c(i, K - 1) * A[i]; }
  reverse(all(A));
  REP(i, N) { minSum += c(i, K - 1) * A[i]; }

  mint ans = maxSum - minSum;
  cout << ans.x << endl;
  return 0;
}

Compiler output:
a.cc: In constructor 'combination::combination(int)':
a.cc:76:5: error: 'assert' was not declared in this scope
   76 |     assert(n < mod);
      |     ^~~~~~
a.cc:17:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
   16 | #include <vector>
  +++ |+#include <cassert>
   17 | using namespace std;
Language: C++

/*
 Σf(x) = Σ(max(x)-min(x)) = Σ max(x) - Σ min(x)
 まず入力をソートする
 N = 7, K = 4
 {1 , 2 , 3 , 4 , 4 , 5 , 6}
 ここで,5が最大値になる集合のパターンは
 5以下の数から集合を選んだ場合になる、そのパターンの数はcombination(5,3)
 最小の場合は、これをreverseでソートする.
 ※※※※※※ combination=nCk ※※※※※※
 これはライブラリを使う。
*/

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  sort(all(A));
  combination c(N + 5);

  mint maxSum = 0, minSum = 0;
  REP(i, N) { maxSum += c(i, K - 1) * A[i]; }
  reverse(all(A));
  REP(i, N) { minSum += c(i, K - 1) * A[i]; }

  mint ans = maxSum - minSum;
  cout << ans.x << endl;
  return 0;
}

Compiler output:
a.cc: In constructor 'combination::combination(int)':
a.cc:75:5: error: 'assert' was not declared in this scope
   75 |     assert(n < mod);
      |     ^~~~~~
a.cc:16:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
   15 | #include <vector>
  +++ |+#include <cassert>
   16 | using namespace std;
Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define iiii tuple<int, int, int, int>
#define iii tuple<int, int, int>
#define ii pair<int, int>
#define fi first
#define vi vector<int>
#define vvi vector<vector<int>>
#define se second

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
const int M = 1e9 + 7;

int fpow(int x, int n) {
    int res = 1;
    while (n) {
        if (n & 1) res = (1LL * res * x) % M;
        n >>= 1;
        x = (1LL * x * x) % M;
    }
    return res;
}
int gcdex(int x, int m) { return fpow(x, m - 2); }

void solve() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());

    if (k == 1) {
        cout << "0\n";
        return;
    }

    for (auto& i : a) i = (i + M) % M;
    // for (int i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1];
    vi nCk(n + 1, 1);
    vi fac(n + 1, 1);
    for (int i = 2; i <= n; ++i) fac[i] = (1LL * fac[i - 1] * i) % M;
    // for (int i = 0; i <= n; ++i) cout << fac[i] << " \n"[i == n];
    for (int i = k; i <= n; ++i) {
        ll tmp = fac[i - 2];
        tmp = (tmp * gcdex(fac[k - 2], M)) % M;
        nCk[i] = (tmp * gcdex(fac[i - k], M)) % M;
        if (nCk[i] == 0) nCk[i] = 1;
    }
    partial_sum(nCk.begin() + k, nCk.end(), nCk.begin() + k);

    ll max_sum = 0, min_sum = 0;
    int j = k;
    for (int i = k - 1; i < n; ++i)
        max_sum = (max_sum + 1LL * a[i] * nCk[j++] + (ll)M*(ll)M) % M;

    j = k;
    for (int i = n - k; i >= 0; --i)
        min_sum = (min_sum + 1LL * a[i] * nCk[j++] + (ll)M*(ll)M) % M;

    cout << (max_sum - min_sum + M) % M << '\n';
    // cout << max_sum << ' ' << min_sum << '\n';
    // for (int i = k; i <= n; ++i) cout << nCk[i] << " \n"[i == n];
}

int main() {
    // ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

Compiler output:
a.cc:4:12: error: 'long long long' is too long for GCC
    4 | #define ll long long
      |            ^~~~
a.cc:20:19: note: in expansion of macro 'll'
   20 | typedef long long ll;
      |                   ^~
a.cc:4:17: error: 'long long long' is too long for GCC
    4 | #define ll long long
      |                 ^~~~
a.cc:20:19: note: in expansion of macro 'll'
   20 | typedef long long ll;
      |                   ^~
a.cc:4:17: error: declaration does not declare anything [-fpermissive]
    4 | #define ll long long
      |                 ^~~~
a.cc:20:19: note: in expansion of macro 'll'
   20 | typedef long long ll;
      |                   ^~
Language: C

#include <stdio.h>
#include <stdlib.h>
#define MOD 1000000007


const int MAX = 100001;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit(int nmax) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i <= nmax; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int int_sort( const void * a , const void * b ) {
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}


int main(void){
    int long long ans=0,cmb;
    int n,k,i,j;
    int a[MAX];
    scanf("%d %d",&n,&k);
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
    };
    qsort(&a[1],n,sizeof(*a),int_sort);
    /*for(i=1;i<=n;i++){
        printf("%d ",a[i]);
    };*/
    //putchar('\n');
    COMinit(n);
    for(i=k;i<=n;i++){
        cmb=COM(i-1,k-1);
        ans+=a[i]*cmb;
        //printf("a[%d]=%d, a[%d]=%d, f=%d, cmb=%lld, ans=%lld\n",i,a[i],j,a[j],f,cmb,ans);
        while(ans>MOD)ans-=MOD;
    };
    for(i=1;i<=n-k+1;i++){
        cmb=COM(n-i,k-1);
        ans-=a[i]*cmb;
        while(ans<0)ans+=MOD;
    };
    printf("%lld",ans);
    return 0;
}


Compiler output:
main.c:8:11: error: variably modified 'fac' at file scope
    8 | long long fac[MAX], finv[MAX], inv[MAX];
      |           ^~~
main.c:8:21: error: variably modified 'finv' at file scope
    8 | long long fac[MAX], finv[MAX], inv[MAX];
      |                     ^~~~
main.c:8:32: error: variably modified 'inv' at file scope
    8 | long long fac[MAX], finv[MAX], inv[MAX];
      |                                ^~~
Language: C++

#include <iostream>
#include <vector>
#include <algorighm>

using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

template <long long Modulus> class mint {
    long long a;
public:

    constexpr mint(const long long a = 0) noexcept : a((a % Modulus + Modulus) % Modulus) {}

    constexpr long long& value() noexcept {
        return a;
    }

    constexpr mint& operator +=(const mint& rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) a -= Modulus;
        return *this;
    }

    constexpr mint& operator -=(const mint& rhs) noexcept {
        a += Modulus - rhs.a;
        if (a >= Modulus) a -= Modulus;
        return *this;
    }

    constexpr mint& operator *=(const mint& rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }

    constexpr mint operator +(const mint rhs) const noexcept {
        return mint(*this) += rhs;
    }

    constexpr mint operator -(const mint rhs) const noexcept {
        return mint(*this) -= rhs;
    }

    constexpr mint operator *(const mint &rhs) const noexcept {
        return mint(*this) *= rhs;
    }

    constexpr mint pow(long long t) const noexcept {
        if (!t) return 1;
        mint<Modulus> ret = pow(t >> 1u);
        ret *= ret;
        if (t & 1) ret *= *this;
        return ret;
    }

    constexpr mint inv() const noexcept {
        return pow(Modulus - 2);
    }

    constexpr mint operator /=(const mint rhs) {
        return (*this) *= rhs.inv();
    }

    constexpr mint operator /(const mint &rhs) const noexcept {
        return mint(*this) /= rhs;
    }
};

using mi = mint<MOD>;

mi powmod(mi a, ll p) {
    mi ans = 1;
    mi mul = a;
    for (; p > 0; p >>= 1, mul = mul * mul) {
        if (p & 1) ans *= mul;
    }
    return ans;
}

mi fact[100005];
mi rev[100005];

mi nCk(ll n, ll k) {
    if (n < 0 || k < 0) return 0;
    if (n < k) return 0;
    return fact[n] * rev[n-k] * rev[k];
}

signed main() {
    fact[0] = 1;
    for (int i = 0; i < 100000; i++) fact[i+1] = fact[i] * (i + 1);
    rev[100000] = powmod(fact[100000], MOD-2);
    for (int i = 100000-1; i >= 0; i--) rev[i] = rev[i+1] * (i+1);

    int N, K;
    cin >> N >> K;

    if (K == 1) {
        cout << 0 << endl;
        return 0;
    }
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());

    mi tmp1 = 0;
    mi tmp2 = 0;

    for (int i = K-1; i < N; i++) {
        tmp1 += nCk(i, K-1) * A[i];
    }

    /*
    for (int i = N - K; i >= 0; i--) {
        tmp2 += nCk(N-i-1, K-1) * A[i];
    }
     */

    sort(A.begin(), A.end(), greater<ll>());
    for (int i = K-1; i < N; i++) {
        tmp2 += nCk(i, K-1) * A[i];
    }

    cout << (tmp1 - tmp2).value() << endl;
}

Compiler output:
a.cc:3:10: fatal error: algorighm: No such file or directory
    3 | #include <algorighm>
      |          ^~~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

template <long long Modulus> class mint {
    long long a;
public:

    constexpr mint(const long long a = 0) noexcept : a((a % Modulus + Modulus) % Modulus) {}

    constexpr long long& value() noexcept {
        return a;
    }

    constexpr mint& operator +=(const mint& rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) a -= Modulus;
        return *this;
    }

    constexpr mint& operator -=(const mint& rhs) noexcept {
        a += Modulus - rhs.a;
        if (a >= Modulus) a -= Modulus;
        return *this;
    }

    constexpr mint& operator *=(const mint& rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }

    constexpr mint operator +(const mint rhs) const noexcept {
        return mint(*this) += rhs;
    }

    constexpr mint operator -(const mint rhs) const noexcept {
        return mint(*this) -= rhs;
    }

    constexpr mint operator *(const mint &rhs) const noexcept {
        return mint(*this) *= rhs;
    }

    constexpr mint pow(long long t) const noexcept {
        if (!t) return 1;
        mint<Modulus> ret = pow(t >> 1u);
        ret *= ret;
        if (t & 1) ret *= *this;
        return ret;
    }

    constexpr mint inv() const noexcept {
        return pow(Modulus - 2);
    }

    constexpr mint operator /=(const mint rhs) {
        return (*this) *= rhs.inv();
    }

    constexpr mint operator /(const mint &rhs) const noexcept {
        return mint(*this) /= rhs;
    }
};

using mi = mint<MOD>;

mi powmod(mi a, ll p) {
    mi ans = 1;
    mi mul = a;
    for (; p > 0; p >>= 1, mul = mul * mul) {
        if (p & 1) ans *= mul;
    }
    return ans;
}

mi fact[100005];
mi rev[100005];

mi nCk(ll n, ll k) {
    if (n < 0 || k < 0) return 0;
    if (n < k) return 0;
    return fact[n] * rev[n-k] * rev[k];
}

signed main() {
    fact[0] = 1;
    for (int i = 0; i < 100000; i++) fact[i+1] = fact[i] * (i + 1);
    rev[100000] = powmod(fact[100000], MOD-2);
    for (int i = 100000-1; i >= 0; i--) rev[i] = rev[i+1] * (i+1);

    int N, K;
    cin >> N >> K;

    if (K == 1) {
        cout << 0 << endl;
        return 0;
    }
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());

    mi tmp1 = 0;
    mi tmp2 = 0;

    for (int i = K-1; i < N; i++) {
        tmp1 += nCk(i, K-1) * A[i];
    }

    /*
    for (int i = N - K; i >= 0; i--) {
        tmp2 += nCk(N-i-1, K-1) * A[i];
    }
     */

    sort(A.begin(), A.end(), greater<ll>());
    for (int i = K-1; i < N; i++) {
        tmp2 += nCk(i, K-1) * A[i];
    }

    cout << (tmp1 - tmp2).value() << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:103:5: error: 'sort' was not declared in this scope; did you mean 'short'?
  103 |     sort(A.begin(), A.end());
      |     ^~~~
      |     short
Language: C++

#include <bits/stdc++.h>
using namespace std;

const int MAX = 50000;
const int MOD = 1000000007;

int64_t fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


int64_t COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){

  COMinit();

  int N,K;
  cin>>N>>K;
  vector<int64_t> A(N);
  for(int i=0;i<N;++i) cin>>A[i];

  sort(A.begin(),A.end());

  int64_t ans=0;
  for(int i=0;i<N;++i){
    ans += A[i]*(COM(i,K-1)-COM(N-i-1,K-1))%MOD;
  }
  cout<<ans%MOD<<endl;


Compiler output:
a.cc: In function 'int main()':
a.cc:42:23: error: expected '}' at end of input
   42 |   cout<<ans%MOD<<endl;
      |                       ^
a.cc:27:11: note: to match this '{'
   27 | int main(){
      |           ^
Language: C++

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;


template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

typedef long long ll;
typedef pair<ll, ll> Pa;

modint<MOD> comb(modint<MOD> n, modint<MOD> r) {
    modint<MOD> zero;
    zero.a = 0;
    if(n.a <= 0 || n.a < r.a) {
        return zero;
    }
    modint<MOD> sum = 1;
    for(ll i=n.a;i>max(n.a-r.a,r.a);i--) sum *= i;
    for(ll i=min(n.a-r.a,r.a);i>0;i--) sum /= i;
    return sum;
}

const int MAX = 510000;
 
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
 
// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

typedef modint<MOD> m;
ll a[100000];
m arr[100000];
int main() {
    m _sum;
    _sum.a = 0;
    cin >> N >> K;
    rep(i, N){
        cin >> a[i];
    }    
    sort(a, a+N);
    COMinit();
    rep(i, N){
        arr[i].a = a[i];
    }
    for(int i=0;i<N;i++){
        _sum -= arr[i]*COM(N-i-1, K-1);
        _sum += arr[i]*COM(i, K-1);
    }
    cout << _sum.a;
}


Compiler output:
a.cc:77:11: error: conflicting declaration 'const int MAX'
   77 | const int MAX = 510000;
      |           ^~~
a.cc:4:30: note: previous declaration as 'const long long int MAX'
    4 | const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
      |                              ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define MAX 100003

// define MOD before using this function
void mult(int &a, int b) {
    ll p = (a * 1ll) * b;
    if (p >= MOD) p %= MOD;
    a = (int)p;
}

//Fast Exponentiation
ll fexp(ll base, ll exp, ll mod) {
    ll result = 1;
    while (exp > 0) {
        if (exp % 2 == 1)
            result = (result * base) % mod;
        exp >>= 1;
        base = (base * base) % mod;
    }
    return result;
}

int fact[MAX], invf[MAX];

void pre() {
    fact[0] = 1;
    for (int i = 1; i < MAX; i++) {
        fact[i] = i; 
        mult(fact[i], fact[i - 1]);
    }

    invf[MAX - 1] = fexp(fact[MAX - 1], MOD - 2, MOD);
    for (int i = MAX - 2; i >= 0; i--) {
        invf[i] = invf[i + 1]; mult(invf[i], i + 1);
    }
}

inline int nCr(int n, int k) {
    if (n < k) return 0;
    int x = fact[n];
    mult(x, invf[k]); mult(x, invf[n - k]);
    return x;
}

int a[MAX];

int main() {
    pre();

    int n, k; scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    sort(a, a + n);
    
    // first maximum
    int ansm = 0;
    for (int i = n - 1; i >= 0; i--) {
        int x = a[i]; mult(x, nCr(i, k - 1));
        ansm += x;
        if (ansm >= MOD) ansm -= MOD;
    }

    // next minimum
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x = a[i]; mult(x, nCr(n - 1 - i, k - 1));
        ans += x;
        if (ans >= MOD) ans -= MOD;
    }

    int res = ansm - ans;
    if (res < 0) res += MOD;
    cout << res;

    return 0;
}

Compiler output:
a.cc: In function 'void mult(int&, int)':
a.cc:10:14: error: 'MOD' was not declared in this scope
   10 |     if (p >= MOD) p %= MOD;
      |              ^~~
a.cc: In function 'void pre()':
a.cc:35:41: error: 'MOD' was not declared in this scope
   35 |     invf[MAX - 1] = fexp(fact[MAX - 1], MOD - 2, MOD);
      |                                         ^~~
a.cc: In function 'int main()':
a.cc:62:21: error: 'MOD' was not declared in this scope
   62 |         if (ansm >= MOD) ansm -= MOD;
      |                     ^~~
a.cc:70:20: error: 'MOD' was not declared in this scope
   70 |         if (ans >= MOD) ans -= MOD;
      |                    ^~~
a.cc:74:25: error: 'MOD' was not declared in this scope
   74 |     if (res < 0) res += MOD;
      |                         ^~~
Language: C++

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
/* 4 方向への隣接頂点への移動を表すベクトル */
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  ll n,k;
  cin>>n>>k;
  vec a(n);
  ll ans=0;
  loop(i,n)cin>>a[i];
  ll ans=0;
  sort(all(a));
  loop(i,n-1){
    ans+=((a[i+1]-a[i])%1000000007)*((COM(n,k)-COM(i+1,k)-COM(n-i-1,k)%1000000007));
    ans%=1000000007;
  }
    putout(ans);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:94:6: error: redeclaration of 'll ans'
   94 |   ll ans=0;
      |      ^~~
a.cc:92:6: note: 'll ans' previously declared here
   92 |   ll ans=0;
      |      ^~~