Language: C++

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <unordered_set>
using namespace std;

#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr<< name << ": "<< arg1<<endl;
}

template<typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1,',');
        cerr.write(names, comma-names) <<": "<<arg1<<" |";
        __f(comma+1,args...);
}


struct modint{
	using i64 = int_fast64_t;
	i64 a;
	static constexpr i64 MOD= 1e9+7;
	modint(){
		a=0;
	};
	modint(i64 a_){
		a=a_ %MOD;
		if(a<0) a+=MOD;
	}

	modint inv()const{
		i64 n=1,m=MOD-2, A=a;
		while(m){
			if(m&1)(n*=A)%=MOD;
			(A*=A) %= MOD;
			m>>=1;
		}
		modint y(n);
		return y;
	}

	bool operator==(const modint& x){
		return a==x.a;
	}
	bool operator!=(const modint& x){
		return a!=x.a;
	}

	modint&  operator =(const modint& x){
		a= x.a;
		return *this;
	}
	modint operator+(const modint& x){

		modint y;
		y.a= a+x.a;
		if(y.a < 0) y.a+=MOD;
		return y;
	}
	modint operator-(const modint& x){

		modint y;
		y.a= a-x.a;
		if(y.a<0) y.a+=MOD;
		return y;
	}
	modint operator*(const modint& x){
		modint y;
		y.a=(a*x.a)%MOD;
		return y;
	}
	modint operator/(const modint& x){
		modint y;
		y.a=(a*(x.inv().a))%MOD;
		return y;
	}

	modint& operator +=(const modint& x){
		a=a+x.a;
		if(a>=MOD)a-=MOD;
		return *this;
	}
	modint& operator -=(const modint& x){
		a=a-x.a;
		if(a<0) a+=MOD;
		return *this;
	}
	modint& operator *=(const modint& x){
		(a*=x.a)%=MOD;
		return *this;
	}
	modint& operator /=(const modint& x){

		(a*=x.inv().a)%=MOD;
		return *this;
	}
};

istream& operator>> (istream& in, modint& x){
	int_fast64_t a_;
	in>>a_;
	modint y(a_);
	x=y;
	return in;
}

ostream& operator<< (ostream& out, const modint& x){
	out<<x.a;
	return out;
}

modint pwr(int_fast64_t a, int_fast64_t b){
	modint _;
	int_fast64_t n=1,A=a;
	while(b){
		if(b&1)(n*=A)%=modint::MOD;
		(A*=A)%=modint::MOD;
		b>>=1;
	}
	_.a=n;
	return _;
}

template<int n> struct COMB{
	int_fast64_t fc[n],ifc[n];

	constexpr COMB():fc(), ifc(){
		fc[0]=1;
		for(int i=1;i<n;++i) fc[i]=fc[i-1]* i % modint::MOD;
		int_fast64_t N=1, A=fc[n-1], b=modint::MOD-2;

		while(b){
			if(b & 1) (N*=A)%=modint::MOD;
			(A*=A)%= modint::MOD;
			b>>=1;
		}
		ifc[n-1]=N;
		for(int i=n-1 ;i>=1 ;--i) ifc[i-1]=ifc[i]*i % modint::MOD;
	};
	modint operator()(int N,int R)const{

		if(N<0|| R<0||N<R)return 0;
		return fc[N]*ifc[R]%modint::MOD* ifc[N-R];
	}
	modint operator[](int N)const{
		modint _;
		_.a= fc[N];
		return _;
	}
	modint operator()(int N)const{
		modint _;
		_.a=ifc[N];
		return _;
	}
};

constexpr COMB<200010> comb;

int main(){

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

	sort(A.begin(),A.end());
	
	modint ans{};

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

	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'void __f(const char*, Arg1&&, Args&& ...)':
a.cc:31:29: error: there are no arguments to 'strchr' that depend on a template parameter, so a declaration of 'strchr' must be available [-fpermissive]
   31 |         const char* comma = strchr(names+1,',');
      |                             ^~~~~~
a.cc:31:29: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc: At global scope:
a.cc:38:21: error: 'int_fast64_t' does not name a type
   38 |         using i64 = int_fast64_t;
      |                     ^~~~~~~~~~~~
a.cc:39:9: error: 'i64' does not name a type
   39 |         i64 a;
      |         ^~~
a.cc:40:26: error: 'i64' does not name a type
   40 |         static constexpr i64 MOD= 1e9+7;
      |                          ^~~
a.cc:44:19: error: expected ')' before 'a_'
   44 |         modint(i64 a_){
      |               ~   ^~~
      |                   )
a.cc: In constructor 'modint::modint()':
a.cc:42:17: error: 'a' was not declared in this scope
   42 |                 a=0;
      |                 ^
a.cc: In member function 'modint modint::inv() const':
a.cc:50:17: error: 'i64' was not declared in this scope
   50 |                 i64 n=1,m=MOD-2, A=a;
      |                 ^~~
a.cc:51:23: error: 'm' was not declared in this scope; did you mean 'tm'?
   51 |                 while(m){
      |                       ^
      |                       tm
a.cc:52:33: error: 'n' was not declared in this scope; did you mean 'yn'?
   52 |                         if(m&1)(n*=A)%=MOD;
      |                                 ^
      |                                 yn
a.cc:52:36: error: 'A' was not declared in this scope
   52 |                         if(m&1)(n*=A)%=MOD;
      |                                    ^
a.cc:52:40: error: 'MOD' was not declared in this scope
   52 |                         if(m&1)(n*=A)%=MOD;
      |                                        ^~~
a.cc:53:26: error: 'A' was not declared in this scope
   53 |                         (A*=A) %= MOD;
      |                          ^
a.cc:53:35: error: 'MOD' was not declared in this scope
   53 |                         (A*=A) %= MOD;
      |                                   ^~~
a.cc:56:26: error: 'n' was not declared in this scope; did you mean 'yn'?
   56 |                 modint y(n);
      |                          ^
      |                          yn
a.cc: In member function 'bool modint::operator==(const modint&)':
a.cc:61:24: error: 'a' was not declared in this scope
   61 |                 return a==x.a;
      |                        ^
a.cc:61:29: error: 'const struct modint' has no member named 'a'
   61 |                 return a==x.a;
      |                             ^
a.cc: In member function 'bool modint::operator!=(const modint&)':
a.cc:64:24: error: 'a' was not declared in this scope
   64 |                 return a!=x.a;
      |                        ^
a.cc:64:29: error: 'const struct modint' has no member named 'a'
   64 |                 return a!=x.a;
      |                             ^
a.cc: In member function 'modint& modint::operator=(const modint&)':
a.cc:68:17: error: 'a' was not declared in this scope
   68 |                 a= x.a;
      |                 ^
a.cc:68:22: error: 'const struct modint' has no member named 'a'
   68 |                 a= x.a;
      |                      ^
a.cc: In member function 'modint modint::operator+(const modint&)':
a.cc:74:19: error: 'struct modint' has no member named 'a'
   74 |                 y.a= a+x.a;
      |                   ^
a.cc:74:22: error: 'a' was not declared in this scope
   74 |                 y.a= a+x.a;
      |                      ^
a.cc:74:26: error: 'const struct modint' has no member named 'a'
   74 |                 y.a= a+x.a;
      |                          ^
a.cc:75:22: error: 'struct modint' has no member named 'a'
   75 |                 if(y.a < 0) y.a+=MOD;
      |                      ^
a.cc:75:31: error: 'struct modint' has no member named 'a'
   75 |                 if(y.a < 0) y.a+=MOD;
      |                               ^
a.cc:75:34: error: 'MOD' was not declared in this scope
   75 |                 if(y.a < 0) y.a+=MOD;
      |                                  ^~~
a.cc: In member function 'modint modint::operator-(const modint&)':
a.cc:81:19: error: 'struct modint' has no member named 'a'
   81 |                 y.a= a-x.a;
      |                   ^
a.cc:81:22: error: 'a' was not declared in this scope
   81 |                 y.a= a-x.a;
      |                      ^
a.cc:81:26: error: 'const struct modint' has no member named 'a'
   81 |                 y.a= a-x.a;
      |                          ^
a.cc:82:22: error: 'struct modint' has no member named 'a'
   82 |                 if(y.a<0) y.a+=MOD;
      |                      ^
a.cc:82:29: error: 'struct modint' has no member named 'a'
   82 |                 if(y.a<0) y.a+=MOD;
      |                             ^
a.cc:82:32: error: 'MOD' was not declared in this scope
   82 |                 if(y.a<0) y.a+=MOD;
      |                                ^~~
a.cc: In member function 'modint modint::operator*(const modint&)':
a.cc:87:19: error: 'struct modint' has no member named 'a'
   87 |                 y.a=(a*x.a)%MOD;
      |                   ^
a.cc:87:22: error: 'a' was not declared in this scope
   87 |                 y.a=(a*x.a)%MOD;
      |                      ^
a.cc:87:26: error: 'const struct modint' has no member named 'a'
   87 |                 y.a=(a*x.a)%MOD;
      |                          ^
a.cc:87:29: error: 'MOD' was not declared in this scope
   87 |                 y.a=(a*x.a)%MOD;
      |                             ^~~
a.cc: In member function 'modint modint::operator/(const modint&)':
a.cc:92:19: error: 'struct modint' has no member named 'a'
   92 |                 y.a=(a*(x.inv().a))%MOD;
      |                   ^
a.cc:92:22: error: 'a' was not declared in this scope
   92 |                 y.a=(a*(x.inv().a))%MOD;
      |                      ^
a.cc:92:33: error: 'struct modint' has no member named 'a'
   92 |                 y.a=(a*(x.inv().a))%MOD;
      |                                 ^
a.cc:92:37: error: 'MOD' was not declared in this scope
   92 |                 y.a=(a*(x.inv().a))%MOD;
      |                                     ^~~
a.cc: In member function 'modint& modint::operator+=(const modint&)':
a.cc:97:17: error: 'a' was not declared in this scope
   97 |                 a=a+x.a;
      |                 ^
a.cc:97:23: error: 'const struct modint' has no member named 'a'
   97 |                 a=a+x.a;
      |                       ^
a.cc:98:23: error: 'MOD' was not declared in this scope
   98 |                 if(a>=MOD)a-=MOD;
      |                       ^~~
a.cc: In member function 'modint& modint::operator-=(const modint&)':
a.cc:102:17: error: 'a' was not declared in this scope
  102 |                 a=a-x.a;
      |                 ^
a.cc:102:23: error: 'const struct modint' has no member named 'a'
  102 |                 a=a-x.a;
      |                       ^
a.cc:103:28: error: 'MOD' was not declared in this scope
  103 |                 if(a<0) a+=MOD;
      |                            ^~~
a.cc: In member function 'modint& modint::operator*=(const modint&)':
a.cc:107:18: error: 'a' was not declared in this scope
  107 |                 (a*=x.a)%=MOD;
      |                  ^
a.cc:107:23: error: 'const struct modint' has no member named 'a'
  107 |                 (a*=x.a)%=MOD;
      |                       ^
a.cc:107:27: error: 'MOD' was not declared in this scope
  107 |                 (a*=x.a)%=MOD;
      |                           ^~~
a.cc: In member function 'modint& modint::operator/=(const modint&)':
a.cc:112:18: error: 'a' was not declared in this scope
  112 |                 (a*=x.inv().a)%=MOD;
      |                  ^
a.cc:112:29: error: 'struct modint' has no member named 'a'
  112 |                 (a*=x.inv().a)%=MOD;
      |                             ^
a.cc:112:33: error: 'MOD' was not declared in this scope
  112 |                 (a*=x.inv().a)%=MOD;
      |                                 ^~~
a.cc: In function 'std::istream& operator>>(std::istream&, modint&)':
a.cc:118:9: error: 'int_fast64_t' was not declared in this scope
  118 |         int_fast64_t a_;
      |         ^~~~~~~~~~~~
a.cc:119:13: error: 'a_' was not declared in this scope
  119 |         in>>a_;
      |             ^~
a.cc: In function 'std::ostream& operator<<(std::ostream&, const modint&)':
a.cc:126:16: error: 'const struct modint' has no member named 'a'
  126 |         out<<x.a;
      |                ^
a.cc: At global scope:
a.cc:130:12: error: 'int_fast64_t' was not declared in this scope
  130 | modint pwr(int_fast64_t a, int_fast64_t b){
      |            ^~~~~~~~~~~~
a.cc:130:28: error: 'int_fast64_t' was not declared in this scope
  130 | modint pwr(int_fast64_t a, int_fast64_t b){
      |                            ^~~~~~~~~~~~
a.cc:130:43: error: expected ',' or ';' before '{' token
  130 | modint pwr(int_fast64_t a, int_fast64_t b){
      |                                           ^
a.cc:143:9: error: 'int_fast64_t' does not name a type
  143 |         int_fast64_t fc[n],ifc[n];
      |         ^~~~~~~~~~~~
a.cc: In constructor 'constexpr COMB<n>::COMB()':
a.cc:145:26: error: class 'COMB<n>' does not have any field named 'fc'
  145 |         constexpr COMB():fc(), ifc(){
      |                          ^~
a.cc:145:32: error: class 'COMB<n>' does not have any field named 'ifc'
  145 |         constexpr COMB():fc(), ifc(){
      |                                ^~~
a.cc:146:17: error: 'fc' was not declared in this scope
  146 |                 fc[0]=1;
      |                 ^~
a.cc:147:65: error: 'MOD' is not a member of 'modint'
  147 |                 for(int i=1;i<n;++i) fc[i]=fc[i-1]* i % modint::MOD;
      |                                                                 ^~~
a.cc:148:17: error: 'int_fast64_t' was not declared in this scope
  148 |                 int_fast64_t N=1, A=fc[n-1], b=modint::MOD-2;
      |                 ^~~~~~~~~~