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

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
constexpr int INF = (1 << 29);
constexpr ll INF_ = (1LL << 58);
constexpr ld EPS = (1e-10);
constexpr ld PI_ = 3.141592653589793238;//46264338327950288
constexpr ld E_ = 2.71828182845904523;//5360287471352
constexpr ll MOD = 1000000007;
//// functions (integer)_________________________________
ll modpow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a % m;
		a = a * a%m; n >>= 1;
	}
	return res;
}
ll modinv(ll a, ll p, ll mod){
  return modpow(a,p-2,mod);
}
////-----------------------------------------------------
int main(void){
  int N, K; ll A[100005], factorial[200005], invfactorial[200005], Comb[200005];
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  RPT(i,0,N) cin >> A[i];
  if(K==1) {cout << 0 << endl; return 0;}
  sort(A,A+N);
  factorial[0] = 1;
  invfactorial[0] = 1;
  RPT(i,1,2*N+1){
    factorial[i] = (i*factorial[i-1])%MOD;
    invfactorial[i] = modpow(factorial[i],MOD-2,MOD);
  }
  FOR(i,K-2,N-1){
    Comb[i] = ((factorial[i]*invfactorial[K-2]%MOD)*invfactorial[i-K+2])%MOD;
  }
  ll ans = 0;
  FOR(i,0,N-K+1){
    FOR(j,i+K-1,N){
      ll df = A[j] - A[i];//comb(j-i-1,K-2)j-i-1-K+2
      df = df * comb[j-i-1] % MOD;
      ans += df;
      ans %= MOD;
    }
  }
  ll Min_ = 0, Max_ = 0, _N = 0; 
  RPT(i,0,N-K+1){
    int Min_i = N - K - i, Max_i = K - 1 + i;
    _N += Comb[K-2+i];
    _N %= MOD;
    Min_ += ((A[Min_i]+MOD)*_N)%MOD;
    Max_ += ((A[Max_i]+MOD)*_N)%MOD;
    Min_ %= MOD;
    Max_ %= MOD;
  }
  ans = (Max_ - Min_ + MOD) % MOD;
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:17: error: 'comb' was not declared in this scope; did you mean 'Comb'?
   49 |       df = df * comb[j-i-1] % MOD;
      |                 ^~~~
      |                 Comb
Language: C++

#include <bits/stdc++.h>
using namespace std;
inline char getcha()
{
    if (ci - cn == cm)
    {
        fread_unlocked(cn, 1, cm, stdin);
        ci = cn;
    }
    return *ci++;
}
template <typename t>
void read(t &x)
{
    char ch = getcha();
    x = 0;
    t f = 1;
    while (ch < '0' || ch > '9')
        f = (ch == '-' ? -1 : f), ch = getcha();
    while (ch >= '0' && ch <= '9')
        x = x * 10 + ch - '0', ch = getcha();
    x *= f;
}
//---------------https://lunatic.blog.csdn.net/-------------------//
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 100005
#define fil(a, n) rep(0, n, i) read(a[i])
ll power(ll a, ll b, ll p)
{
    ll ans = 1 % p;
    for (; b; b >>= 1)
    {
        if (b & 1)
            ans = ans * a % p;
        a = a * a % p;
    }
    return ans;
}
long long mm[500000];
void init(ll n, ll k)
{
    mm[1] = 1;
    for (ll i = 2; i <= n; i++)
    {
        mm[i] = ((mm[i - 1] * (k + i - 1)) % MOD * power(i - 1, MOD - 2, MOD)) % MOD;
        //cout<<mm[i]<<endl;
    }
}
ll a[N];
int main()
{
    int n, k;
    read(n), read(k);
    fil(a, n);
    sort(a, a + n);
    init(n - k + 2, k - 1);
    long long sum = 0;
    rrep(n - 1, k - 2, i)
        sum = (sum + (mm[i - k + 2] * (a[i] - a[n - i - 1]) % MOD) % MOD) % MOD;
    wl((sum + MOD) % MOD);
    P;
}

Compiler output:
a.cc: In function 'char getcha()':
a.cc:5:9: error: 'ci' was not declared in this scope; did you mean 'wi'?
    5 |     if (ci - cn == cm)
      |         ^~
      |         wi
a.cc:5:14: error: 'cn' was not declared in this scope; did you mean 'yn'?
    5 |     if (ci - cn == cm)
      |              ^~
      |              yn
a.cc:5:20: error: 'cm' was not declared in this scope; did you mean 'tm'?
    5 |     if (ci - cn == cm)
      |                    ^~
      |                    tm
a.cc:10:13: error: 'ci' was not declared in this scope; did you mean 'wi'?
   10 |     return *ci++;
      |             ^~
      |             wi
Language: C++

#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

// 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;
  }
};

mint choose(ll n, ll k) {
  mint x = 1, y = 1;
  for(ll i=0; i<k; i++) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

// 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];
  }
};

void solve(long long N, long long K, std::vector<long long> A){
  mint ans = 0;
  combination c(1001001);
  sort(A.begin(), A.end());
  for(ll i=K-1; i<N; i++) {
    mint now = 0;
    for(ll j=0; j+i<N; j++) {
      now+=A[i+j]-A[j];
    }
    now*=c(i-1, K-2);
    ans += now;
  }
  std::cout << ans.x << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}



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

#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;


const int mod = 1000000007;
struct mint {
  ll x;

  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;
  }
};

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];
  }
};

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

  combination com(100001);

  std::sort(A.begin(), A.end());
  mint mxsum = 0;
  rep(i,N) {
    if(i < K-1) continue;
    mint a = A[i];
    mxsum += com(i,K-1) * a;
  }

  std::sort(A.begin(), A.end(), greater<>());
  mint mnsum = 0;
  rep(i,N) {
    if(i < K-1) continue;
    mint a = A[i];
    mnsum += com(i,K-1) * a;
  }

  mint ans = mxsum - mnsum;
  cout << ans.x << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:88:8: error: 'sort' is not a member of 'std'; did you mean 'sqrt'?
   88 |   std::sort(A.begin(), A.end());
      |        ^~~~
      |        sqrt
a.cc:96:8: error: 'sort' is not a member of 'std'; did you mean 'sqrt'?
   96 |   std::sort(A.begin(), A.end(), greater<>());
      |        ^~~~
      |        sqrt
Language: C++

#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;


const int mod = 1000000007;
struct mint {
  ll x;

  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;
  }
};

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<ll> A(N);
  rep(i,N) cin >> A[i];

  combination com(100001);

  sort(A.begin(), A.end());
  mint mxsum = 0;
  rep(i,N) {
    if(i < K-1) continue;
    mint a = A[i];
    mxsum += com(i,K-1) * a;
  }

  sort(A.begin(), A.end(), greater<>());
  mint mnsum = 0;
  rep(i,N) {
    if(i < K-1) continue;
    mint a = A[i];
    mnsum += com(i,K-1) * a;
  }

  mint ans = mxsum - mnsum;
  cout << ans.x << endl;
  return 0;
}


Compiler output:
a.cc: In constructor 'combination::combination(int)':
a.cc:69:5: error: 'assert' was not declared in this scope
   69 |     assert(n < mod);
      |     ^~~~~~
a.cc:6:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    5 | #include<queue>
  +++ |+#include <cassert>
    6 | #define rep(i, n) for (int i = 0; i < (n); ++i)
a.cc: In function 'int main()':
a.cc:89:3: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   89 |   sort(A.begin(), A.end());
      |   ^~~~
      |   sqrt
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

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

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
    
  int main(){
      lint N,K;
      cin>>N>>K;
      lint A[N];
      rep(i,N){
          cin>>A[i];
      }
      sort(A,A+N);
      lint min=0;
      lint max=0;
      COMinit();
      rep(i,N-K+1){
          lint g=A[i]*COM(N-i-1,K-1);
          g%=MOD;
          min+=g;
          min%=MOD;
      }
       sort(A,A+N,greater<lint>());
         rep(i,N-K+1){
             lint g=A[i]*COM(N-i-1,K-1);
             g%=MOD;
          max+=g
          max%=MOD;
      }
     if(max-min<0)cout<<max-min+MOD;
     else cout<<max-min;
      

    }
     
  


Compiler output:
a.cc: In function 'int main()':
a.cc:81:17: error: expected ';' before 'max'
   81 |           max+=g
      |                 ^
      |                 ;
   82 |           max%=MOD;
      |           ~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

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

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
    
  int main(){
      lint N,K;
      cin>>N>>K;
      lint A[N];
      rep(i,N){
          cin>>A[i];
      }
      sort(A,A+N);
      lint min=0;
      lint max=0;
      COMinit();
      rep(i,N-K+1){
          lint g=A[i]*COM(N-i-1,K-1);;
          g%=MOD;
          min+=g
          min%=MOD;
      }
       sort(A,A+N,greater<lint>());
         rep(i,N-K+1){
             lint g=A[i]*COM(N-i-1,K-1);
             g%=MOD;
          max+=g
          max%=MOD;
      }
     if(max-min<0)cout<<max-min+MOD;
     else cout<<max-min;
      

    }
     
  


Compiler output:
a.cc: In function 'int main()':
a.cc:74:17: error: expected ';' before 'min'
   74 |           min+=g
      |                 ^
      |                 ;
   75 |           min%=MOD;
      |           ~~~    
a.cc:81:17: error: expected ';' before 'max'
   81 |           max+=g
      |                 ^
      |                 ;
   82 |           max%=MOD;
      |           ~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define pb push_back
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define bit(n) (1LL<<(n))
typedef vector<i64> vi;
typedef vector<vi> vvi;
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;}

i64 pow_mod(i64 n, i64 k, i64 m){
  i64 r = 1;
  for(;k;k>>=1){
    if(k&1) r=(r*n)%m;
    n=(n*n)%m;
  }
  return r;
}

void Main()
{
  i64 n,k;
  cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(rng(a));

  i64 ans = 0;
  i64 c = 1;
  rep(i,n-k){
    ans += a[k-1+i]*c;
    ans %= MOD;
    c *= i+k;
    c *= pow_mod(i+1,MOD-2,MOD);
    c %= MOD;
  }
  i64 c = 1;
  rep(i,n-k){
    ans -= a[n-k-1-i]*c;
    ans %= MOD;
    c *= i+k;
    c *= pow_mod(i+1,MOD-2,MOD);
    c %= MOD;
  }  
  cout << ans << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}


Compiler output:
a.cc: In function 'void Main()':
a.cc:51:7: error: redeclaration of 'i64 c'
   51 |   i64 c = 1;
      |       ^
a.cc:43:7: note: 'i64 c' previously declared here
   43 |   i64 c = 1;
      |       ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
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() {
	ll n,k;
	cin>>n>>k;
	vector<ll>a;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	COMinit();

    // 計算例
    ll mi=0,ma=0;
    for(ll i=0;i<n;i++){
    	if(n-(i+1)<k-1){
    		break;
    	}
    	ll now=COM(n-(i+1),k-1);
    	mi+=now*a[i];
    	mi%=inf;
    	ma+=now*a[n-i-1];
    	ma%=inf;
    }
    cout << (ma-mi)%inf; << endl;	
	// your code goes here
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:26: error: expected primary-expression before '<<' token
   53 |     cout << (ma-mi)%inf; << endl;
      |                          ^~
Language: C++

#include<iostream>
#include<vector>
#include<cassert>
#include<algorithm>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

struct mint {
	ll x;
	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;
	}

	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) {
		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);
	for (auto&& x : a)cin >> x;
	sort(a.begin(), a.end());
	combination c(n + 5);

	mint ans = 0;
	for (int ri = 0; ri < 2; i++) {
		for (int i = 0; i < n; i++) {
			mint now = c(i, k - 1);
			if (ri == 1)now = -now;
			ans += now * a[i];
		}
		reverse(a.begin(), a.end());
	}
	cout << ans.x << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:80:34: error: 'i' was not declared in this scope; did you mean 'ri'?
   80 |         for (int ri = 0; ri < 2; i++) {
      |                                  ^
      |                                  ri
Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
 
const ll MOD = 1000000007;
 
ll fact[100005];
 
int N, K;
ll A[100005];
 
void init_fact() {
    ll f = 1;
    fact[0] = 1;
    for (int i = 1; i <= 100004; i ++) {
        f = (f * i) % MOD;
        fact[i] = f;
    }
}
 
ll Power(ll base , ll e)
{
    if(e == 0) return 1;
    ll ans = base; e--;
    while(e)
	{
        if(e & 1) ans = (ans * base) %MOD
        base = (base * base) %MOD
        e >>= 1;
	}
	return ans % MOD
}
 
ll inv(ll a) {
    ll x;
    x=Power(a,MOD-2);
    x=x%MOD;
    
    return (x + MOD) % MOD;
}
 
ll combination(int n, int r) {
    return (fact[n] * inv(fact[r]) % MOD * inv(fact[n - r]) % MOD)%MOD;
}
 
int main() {
    init_fact();
    cin >> N >> K;
    rep(i, N) cin >> A[i];
    sort(A, A + N);
    ll ans = 0;
    for (int i = K - 1; i < N; i ++) {
        ll c = combination(i, K - 1);
        ans = (ans + c * A[i] % MOD) % MOD;
    }
    for (int i = 0; i <= N - K; i ++) {
        ll c = combination(N - 1 - i, K - 1);
        ans = (ans + MOD - (c%MOD * A[i]%MOD) % MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'll Power(ll, ll)':
a.cc:29:42: error: expected ';' before 'base'
   29 |         if(e & 1) ans = (ans * base) %MOD
      |                                          ^
      |                                          ;
   30 |         base = (base * base) %MOD
      |         ~~~~                              
a.cc:33:25: error: expected ';' before '}' token
   33 |         return ans % MOD
      |                         ^
      |                         ;
   34 | }
      | ~
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;

ll N = 100001;
ll K = 100001;
ll mod = 1000000007;

vector<ll> fac(N), finv(N), inv(N);

void Cinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < N;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(ll n,ll 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(){
    Cinit();
    cin >> N >> K;
    vector<ll> 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++){
        if(i >= k - 1)
        ans += A[i] * com(i, K - 1)  % mod;
        if(n - 1 - i >= k - 1)
        ans -= A[i] * com(N - i - 1, K - 1) % mod;
        ans %= mod;
    }
    if(ans < 0)
        ans -= mod;
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:17: error: 'k' was not declared in this scope
   43 |         if(i >= k - 1)
      |                 ^
a.cc:45:12: error: 'n' was not declared in this scope
   45 |         if(n - 1 - i >= k - 1)
      |            ^
a.cc:45:25: error: 'k' was not declared in this scope
   45 |         if(n - 1 - i >= k - 1)
      |                         ^
Language: C++

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}


int main(){
    int N, K;
    cin >> N >> K;
    long int A[N];
    long int ans=0;
    for(int i=0;i<N;i++) cin >> A[i];
    if(K==1) {
        cout << 0 << endl;
        return 0;
    }
    sort(A, A+N);
    long int Caled_nCr[N]={0};
    for(int i=K-2;i<N;i++){
        Caled_nCr[i]=nCr(i,K-2);
    }
    for(int max_index=N-1;max_index>=0;max_index--){
        for(int min_index=0;min_index<max_index-K+2;min_index++){
            long int f=A[max_index]-A[min_index];
            if(K==2) { ans+=f; ans%=MAX_ANS; }
            else {
                ans+=f*Caled_nCr[max_index-min_index-1];
                ans%=MAX_ANS;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:5: error: 'cin' was not declared in this scope
   15 |     cin >> N >> K;
      |     ^~~
a.cc:20:9: error: 'cout' was not declared in this scope
   20 |         cout << 0 << endl;
      |         ^~~~
a.cc:20:22: error: 'endl' was not declared in this scope
   20 |         cout << 0 << endl;
      |                      ^~~~
a.cc:23:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   23 |     sort(A, A+N);
      |     ^~~~
      |     short
a.cc:31:37: error: 'MAX_ANS' was not declared in this scope
   31 |             if(K==2) { ans+=f; ans%=MAX_ANS; }
      |                                     ^~~~~~~
a.cc:34:22: error: 'MAX_ANS' was not declared in this scope
   34 |                 ans%=MAX_ANS;
      |                      ^~~~~~~
a.cc:38:5: error: 'cout' was not declared in this scope
   38 |     cout << ans << endl;
      |     ^~~~
a.cc:38:20: error: 'endl' was not declared in this scope
   38 |     cout << ans << endl;
      |                    ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define MAX 1e9+7
int ncr(int n,int r){
  int ans=1;
  for(int i=n-r+1;i<=n;i++) ans*=i;
  for(int i=1;i<=r;i++) ans/=i;
  return(ans);
}
int main(){
  int n,k,sum=0;
  cin>>n>>k;
  int a[n+1];
  for(int i=1;i<=n;i++) cin>>a[i];
  for(int i=1;i<=n;i++){
    if(i>=k) sum+=(a[i]*ncr(i-1,k-1))%MAX;
    if(i+k-1<=n) sum-=(a[i]*ncr(n-i,k-1))%MAX;
  }
  cout<<sum%MAX;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:38: error: invalid operands of types 'int' and 'double' to binary 'operator%'
   16 |     if(i>=k) sum+=(a[i]*ncr(i-1,k-1))%MAX;
      |                   ~~~~~~~~~~~~~~~~~~~^
      |                        |
      |                        int
a.cc:17:42: error: invalid operands of types 'int' and 'double' to binary 'operator%'
   17 |     if(i+k-1<=n) sum-=(a[i]*ncr(n-i,k-1))%MAX;
      |                       ~~~~~~~~~~~~~~~~~~~^
      |                            |
      |                            int
a.cc:19:12: error: invalid operands of types 'int' and 'double' to binary 'operator%'
   19 |   cout<<sum%MAX;
      |         ~~~^
      |         |
      |         int
Language: C++

#include <algorithm>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

const int MAX = 1100000;
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() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  ll maxX = 0, minX = 0;
  COMinit();
  sort(A.begin(), A.end(), greater<ll>());
  for (int i = 0; i < N; i++) {
    maxX += (A[i] * COM(N - i - 1, K - 1));
    maxX %= MOD;
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    minX += (A[i] * COM(N - i - 1, K - 1));
    minX %= MOD;
  }

  cout << (maxX - minX　＋MOD) % MOD << endl;
}


Compiler output:
a.cc:54:19: error: extended character 　 is not valid in an identifier
   54 |   cout << (maxX - minX　＋MOD) % MOD << endl;
      |                   ^
a.cc: In function 'int main()':
a.cc:54:19: error: 'minX\U00003000\U0000ff0bMOD' was not declared in this scope
   54 |   cout << (maxX - minX　＋MOD) % MOD << endl;
      |                   ^~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int mod = 1000000007;
const int INF = 1001001001;

vector<long long> fct(0),invfct(0);

long long modpow(long long a,long long n, long long mod){
    long long res = 1;
    while(n>0){
        if ( n & 1 ) res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

void fct_input(long long maximum,long long mod){
    fct.resize(maximum+1,-1);
    fct.at(0) = 1;
    fct.at(1) = 1;
    long long x = 1;
    for(long long i=2;i<=maximum;i++){
        x = x * i % mod;
        fct.at(i) = x;
    }
 }

void invfct_input(long long maximum,long long mod){
    invfct.resize(maximum+1,-1);
    invfct.at(0) = 1;
    invfct.at(1) = 1;
    long long x = 1;
    for(long long i=2;i<=maximum;i++){
        x = x * i % mod;
        invfct.at(i) = modpow(x,mod - 2,mod);
    }
}

ll nck(int n,int k){
  if(n<k) return 0;
  return ((invfct.at(k) * invfct.at(n-k) % mod) * fct.at(n) ) % mod; 
}

int main(){
  ll n,k;
  cin >> n >> k;

  fct_input(n,mod);
  invfct_input(n,mod);

  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  sort(a.begin(),a.end());
  ll minus = 0, plus = 0;
  
  rep(i,n){
    int a = (a.at(i)) * nck(i,k-1)%mod;
    if(a<0) a+=mod;    
    plus = (plus + a)%mod;
  }
  rep(i,n){
    int a = a.at(i) * nck(n-1-i,k-1)%mod;
    if(a<0) a+mod;
    minus = (minus + a)%mod;
  }
  ll ans = (plus-minus)%mod;
  if(ans<0) ans+=mod;
  cout << ans << endl;


  /*
  rep(i,n-k+1) minus = (minus+((n-k+1-i)%mod)*(a.at(i)%mod))%mod;
  rep(i,n-k+1) plus  = (plus+((n-k+1-i)%mod)*(a.at(n-1-i)%mod))%mod;
  cout << plus-minus << endl;
  */
}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:16: error: request for member 'at' in 'a', which is of non-class type 'int'
   61 |     int a = (a.at(i)) * nck(i,k-1)%mod;
      |                ^~
a.cc:66:15: error: request for member 'at' in 'a', which is of non-class type 'int'
   66 |     int a = a.at(i) * nck(n-1-i,k-1)%mod;
      |               ^~
Language: C++

#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int n,k,i,v[100001],s,w;
int f(int n)
{int c=1; for(int i=1;i<=n;i++){c*=i;}return c;}
long long C(int n,int k)
{return f(n)/(f(k)*f(n-k));}
int main()
{cin>>n>>k;
for(i=1;i<=n;i++){fin>>v[i];}
sort(v+1,v+n+1);
for(i=1;i<=n;i++)
{s=(s+v[i]*C(i-1,k-1)-v[i]*C(n-i,k-1))%1000000007;}
cout<<s;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:12:19: error: 'fin' was not declared in this scope
   12 | for(i=1;i<=n;i++){fin>>v[i];}
      |                   ^~~
Language: C++

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

typedef long long ll;
const ll mod =1e9+7;
const int maxn = 1e5+5;
ll a[maxn];
ll b[maxn];

ll C[maxn];
ll inv[maxn];

int n,k;
void getinv()
{
	inv[1] = 1;
	for (int i = 2; i <= n; ++i) inv[i] = (long long)(mod-mod/i) * inv[mod%i]%mod;	
}
void exgcd(ll a,ll b,ll &x,ll &y)
{
	if(b==0) 
	{
		x=1;y=0;
		return;
	}
	exgcd(b,a%b,y,x);
	y-=a/b*x;
}


void getC()
{
	memset(C,0,sizeof(C));
	C[n-k+1] = 1;
	ll beg = k-1, end = 1;
	for(int i=n-k;i>=1;i--)
	{
		ll x=0,y=0;
		beg++;
		exgcd(end,mod,x,y);
		C[i] = C[i+1]%mod*beg%mod*x%mod;
		C[i] = (C[i]%mod+mod)%mod;
		end++;
	}


bool cmp(ll a,ll b)
{
	return a>b;
}
int main()
{
    
	while(cin>>n>>k)
	{
		memset(b,0,sizeof(b));
		
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			a[i] = a[i]%mod;
		}
		sort(a+1,a+1+n,cmp);
		getC();
		ll ans = 0;
		for(int i=1;i<=n;i++)
		{
			b[i] = (C[i]%mod - C[n+1-i]%mod)%mod;
		}
		for(int i=1;i<=n;i++)
		{
			ans = (ans%mod + a[i]*b[i]%mod)%mod;
		}
		
		cout<<ans<<"\n";
	}
 } 
 
 /*
 10 5
 1000000000 999999999 999999998 999999997 999999996 123456789 111111111 9 8 7
 */

Compiler output:
a.cc: In function 'void getC()':
a.cc:48:1: error: a function-definition is not allowed here before '{' token
   48 | {
      | ^
a.cc:51:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   51 | int main()
      |         ^~
a.cc:51:9: note: remove parentheses to default-initialize a variable
   51 | int main()
      |         ^~
      |         --
a.cc:51:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:52:1: error: a function-definition is not allowed here before '{' token
   52 | {
      | ^
a.cc:77:3: error: expected '}' at end of input
   77 |  }
      |   ^
a.cc:32:1: note: to match this '{'
   32 | {
      | ^
Language: C++

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

long long fac[100005]; 
long long infact[100005];   

/* Iterative Function to calculate (x^y)%p 
  in O(log y) */
int power(int x, int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
int modInverse(int n, int p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
int nCrModP(int n, int r, int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    return fac[n]*infact[r]*infact[n-r]%p;
} 

int main(){
   int p = 1000000007;
  
  // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
   fac[0] = 1; 
   infact[0] = 1;
   for (int i=1 ; i<=100001; i++){
        fac[i] = (fac[i-1]*i)%p; 
        infact[i] = modInverse(fact[i], p);
   }  
  int n, k; cin>>n>>k;
  
  vector<int>a(n);
  
  for(int & i : a) cin>>i;
  
  sort(a.begin(), a.end());
  
  long long ans = 0;
  
  for(int i = 0; i<n; i++){
    if(i >= k - 1 ){
  		ans = (ans - ( (nCrModP(i, k - 1, p)*a[i])%p) + p )%p;
  		cout<<i<<"  "<< nCrModP(i, k - 1, p) <<endl;
    }
    
    if(n - i - 1 >= k - 1)
   		ans = (ans - (   - ( (nCrModP(n - i - 1, k - 1, p)*a[i])%p)  ) + p )%p;
  }
  
  cout<< ans <<'\n';
  
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:56:32: error: 'fact' was not declared in this scope; did you mean 'fac'?
   56 |         infact[i] = modInverse(fact[i], p);
      |                                ^~~~
      |                                fac
Language: C++

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

int fac[1e5 + 2]; 
   

/* Iterative Function to calculate (x^y)%p 
  in O(log y) */
int power(int x, int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
int modInverse(int n, int p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
int nCrModP(int n, int r, int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 

int main(){
   int p = 1e9 + 7;
  
  // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
   fac[0] = 1; 
   for (int i=1 ; i<=1e5; i++) 
        fac[i] = fac[i-1]*i%p; 
  
  int n, k; cin>>n>>k;
  
  vector<int>a(n);
  
  for(int & i : a) cin>>i;
  
  sort(a.begin(), a.end());
  
  long long ans = 0;
  
  for(int i = k - 1; i<n; i++){
    if(i >= k - 1 )
  		ans = (ans - ( (nCrModP(i, k - 1, p)*a[i])%p) + p )%p;
    
    if(n - i - 1 >= k - 1)
   		ans = (ans - (   - ( (nCrModP(n - i - 1, k - 1, p)*a[i])%p)  ) + p )%p;
  }
  
  cout<< ans <<'\n';
  
  return 0;
}


Compiler output:
a.cc:4:13: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    4 | int fac[1e5 + 2];
      |         ~~~~^~~
a.cc:4:13: error: could not convert '(1.0e+5 + (double)2)' from 'double' to 'long unsigned int'
    4 | int fac[1e5 + 2];
      |         ~~~~^~~
      |             |
      |             double
a.cc:4:13: error: size of array 'fac' has non-integral type 'double'
Language: C++

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

int fac[1e5 + 2]; 
   

/* Iterative Function to calculate (x^y)%p 
  in O(log y) */
int power(int x, int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
int modInverse(int n, int p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
int nCrModP(int n, int r, int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 

int main(){
   int p = 1e9 + 7;
  
  // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
   fac[0] = 1; 
   for (int i=1 ; i<=1e5; i++) 
        fac[i] = fac[i-1]*i%p; 
  
  int n, k; cin>>n>>k;
  
  vector<int>a(n);
  
  for(int & i : a) cin>>i;
  
  sort(a.begin(), a.end());
  
  long long ans = 0;
  
  for(int i = k - 1; i<n; i++){
    if(i >= k - 1 )
  		ans = (ans - ( (nCrModP(i, k - 1)*a[i])%p) + p )%p;
    
    if(n - i - 1 >= k - 1)
   		ans = (ans - (   - ( (nCrModP(n - i - 1, k - 1)*a[i])%p)  ) + p )%p;
  }
  
  cout<< ans <<'\n';
  
  return 0;
}


Compiler output:
a.cc:4:13: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    4 | int fac[1e5 + 2];
      |         ~~~~^~~
a.cc:4:13: error: could not convert '(1.0e+5 + (double)2)' from 'double' to 'long unsigned int'
    4 | int fac[1e5 + 2];
      |         ~~~~^~~
      |             |
      |             double
a.cc:4:13: error: size of array 'fac' has non-integral type 'double'
a.cc: In function 'int main()':
a.cc:69:40: error: too few arguments to function 'int nCrModP(int, int, int)'
   69 |                 ans = (ans - ( (nCrModP(i, k - 1)*a[i])%p) + p )%p;
      |                                 ~~~~~~~^~~~~~~~~~
a.cc:37:5: note: declared here
   37 | int nCrModP(int n, int r, int p)
      |     ^~~~~~~
a.cc:72:46: error: too few arguments to function 'int nCrModP(int, int, int)'
   72 |                 ans = (ans - (   - ( (nCrModP(n - i - 1, k - 1)*a[i])%p)  ) + p )%p;
      |                                       ~~~~~~~^~~~~~~~~~~~~~~~~~
a.cc:37:5: note: declared here
   37 | int nCrModP(int n, int r, int p)
      |     ^~~~~~~
Language: C++

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

int fac[1e5 + 2]; 
   

/* Iterative Function to calculate (x^y)%p 
  in O(log y) */
int power(int x, int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
int modInverse(int n, int p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
int nCrModP(int n, int r, int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 

int main(){
   int p = 1e9 + 7;
  
  // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
   fac[0] = 1; 
   for (int i=1 ; i<=1e5; i++) 
        fac[i] = fac[i-1]*i%p; 
  
  int n, k; cin>>n>>k;
  
  vector<int>a(n);
  
  for(int & i : a) cin>>i;
  
  sort(a.begin(), a.end());
  
  long long ans = 0;
  
  for(int i = k - 1; i<n; i++){
    if(i >= k - 1 )
  		ans = (ans - ( (nCrModP(i, k - 1)*a[i])%p) + p )%p;
    
    if(n - i - 1 >= k - 1)
   		ans = (ans - (   - ( (nCrModP(n - i - 1, k - 1)*a[i])%p)  ) + p )%p
  }
  
  cout<< ans <<'\n';
  
  return 0;
}


Compiler output:
a.cc:4:13: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    4 | int fac[1e5 + 2];
      |         ~~~~^~~
a.cc:4:13: error: could not convert '(1.0e+5 + (double)2)' from 'double' to 'long unsigned int'
    4 | int fac[1e5 + 2];
      |         ~~~~^~~
      |             |
      |             double
a.cc:4:13: error: size of array 'fac' has non-integral type 'double'
a.cc: In function 'int main()':
a.cc:69:40: error: too few arguments to function 'int nCrModP(int, int, int)'
   69 |                 ans = (ans - ( (nCrModP(i, k - 1)*a[i])%p) + p )%p;
      |                                 ~~~~~~~^~~~~~~~~~
a.cc:37:5: note: declared here
   37 | int nCrModP(int n, int r, int p)
      |     ^~~~~~~
a.cc:72:46: error: too few arguments to function 'int nCrModP(int, int, int)'
   72 |                 ans = (ans - (   - ( (nCrModP(n - i - 1, k - 1)*a[i])%p)  ) + p )%p
      |                                       ~~~~~~~^~~~~~~~~~~~~~~~~~
a.cc:37:5: note: declared here
   37 | int nCrModP(int n, int r, int p)
      |     ^~~~~~~
Language: C++

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
const int mod = 1e9+7;
typedef long long ll;

const int MAX=510000;
long long fac[MAX], finv[MAX], inv[MAX];

struct mint {
  ll x;
  mint(ll x=0):x(x%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;
  }
};

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);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  combination c(n+5);

  mint ans = 0;
  for(int r = 0; r < 2; r++) {
    for(int i = 0; i < n; i++) {
      mint now = c(i, k-1);
      if(r == 1) now = -now;
      ans += now*a[i];
    }
    reverse(a.begin(), a.end());
  }
  cout << ans.x << endl;
  return 0;
}


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

public class Entended_Euclidean_Algorithms {

    //given integer a, b, there must be a pair of (x, y) to make ax + by = gcd(a, b);
    public static void main(String[] args) {
        int first = 27;
        int second = 107;
        int[] res = getInverse(first, second);
        //System.out.println(res[0] + " " + res[1]);
    }

    private static int[] getInverse(int a, int b) {
        //a = 27, b = 107, find x to make ax % b = 1;
        //107 = 27 * 3 + 26
        //27 = 26 * 1 + 1
        //26 = 1 * 26 + 0

        //1 = 27 - 26
        //1 = 27 - (107 - 27 * 3) = -107 + 4 * 27;
        //return 4;
        if (b == 0) {
            System.out.println("exit" + a + " " + b);
            return new int[]{1, 0};
        }
        int[] temp = getInverse(b, a % b);
        System.out.println(a + " " + b + " " + temp[0] + " " + temp[1]);
        return new int[]{temp[1], temp[0] - (a / b) * temp[1]};
    }


    public  static long[] ex_gcd(long a,long b){

        long ans;
        long[] result=new long[3];
        if(b==0)
        {
            result[0]=a;
            result[1]=1;
            result[2]=0;
            return result;
        }
        long [] temp=ex_gcd(b,a%b);
        ans = temp[0];
        result[0]=ans;
        result[1]=temp[2];
        result[2]=temp[1]-(a/b)*temp[2];
        return result;
    }
}


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

#include <bits/stdc++.h>
#define int long long
#define INF 1000000007ll
using namespace std;

int n,k;
int a[100010],pw[100010];

inline int my_pow(int x,int y)
{
  if(y==0) return 1;
  if(y==1) return x;
  int res=my_pow(x,y/2);
  if(y%2==0) return (res*res)%INF;
  else return (((res*res)%INF)*x)%INF;
}

int main()
{
  ios::sync_with_stdio(false);
  cin>>n>>k;
  for(int i=1;i<=n;i++) cin>>a[i];
  sort(a+1,a+n+1);
  pw[0]=1;rev[0]=1;
  for(int i=1;i<=n;i++){
    pw[i]=(pw[i-1]*i)%INF;
    rev[i]=my_pow(pw[i],INF-2ll);
  }
  int ans=0ll;
  for(int i=1;i<=n-k+1;i++){
    int val=pw[n-i+1]*rev[n-i+1-k];
    val%=INF;
    val*=rev[k];val%=INF;
    val*=a[i];val%=INF;
    ans-=val;
  }
  for(int i=k;i<=n;i++){
    int val=pw[i]*rev[i-k];
    val%=INF;
    val*=rev[k];val%=INF;
    val*=a[i];val%=INF;
    ans+=val;
  }
  ans%=INF;
  if(ans<0) ans+=INF;
  cout<<ans<<endl;
  return 0;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
a.cc: In function 'int main()':
a.cc:24:11: error: 'rev' was not declared in this scope
   24 |   pw[0]=1;rev[0]=1;
      |           ^~~