akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace  std;

#define ll long long
#define ull unsigned long long
#define f first
#define s second
typedef pair<int , int > pii;
typedef pair<ll,ll> pll;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

const ll MOD = 998244353;


void min_self(ll &a , ll b){a=min(a,b);}
void max_self(ll &a, ll b){a=max(a,b);}
ll add(ll x, ll y){return (x + y) % MOD;}
ll sub(ll x, ll y){return add(x, MOD - y);}
ll mul(ll x, ll y){return (x * 1ll * y) % MOD;}
ll binpow(ll x, ll y)
{
    ll z = 1;
    while(y > 0)
    {
        if(y % 2 == 1)
            z = mul(z, x);
        x = mul(x, x);
        y /= 2;
    }
    return z;
}
ll inv(ll x){return binpow(x, MOD - 2);}
const int MXN = 1e6+10;
ll fact[MXN];
void fac_pre()
{
    fact[0]=1;
    for(ll i=1; i<MXN; i++){
        fact[i]=mul(fact[i-1],i);
    }
}
ll C(ll n, ll k)
{
    return mul(fact[n], inv(mul(fact[k], fact[n - k])));
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// BIT //
const int MAXN=2*1e5+10;
vector<int> bit(MAXN,0);
int sump(int idx) {
    int ret = 0;
    for (++idx; idx > 0; idx -= idx & -idx)
        ret += bit[idx];
    return ret;
}

int sum(int l, int r) {
    return sump(r) - sump(l - 1);
}

void upd(int idx, int delta) {
    for (++idx; idx < MAXN; idx += idx & -idx)
        bit[idx] += delta;
}
/////-----//////
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll genRand(ll B) {
    return (ull)rng() % B;
}
///--//
int  main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    /* KEEP IN MIND
     * take care when sorting a 1 based indexed vector
     * const int N is defined way above in the starting
    */
    int n; cin>>n;
    vector<int> v(n);
    int x=0;
    for(int i=0; i<n; i++){
        cin>>v[i];
        x^=v[i];
    }
    for(int i=0; i<n; i++){
        cout<<(x^v[i])<<" ";
    }

}






Measured memory_bytes: 4772
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int n,m;
vector<int> al[100005];
int memo[100005];
int dp(int i){
    if (memo[i]) return memo[i];
    int ans=1;
    for (vector<int>::iterator it=al[i].begin();it!=al[i].end();it++){
        ans=max(ans,dp(*it)+1);
    }
    return memo[i]=ans;
}
int main(){
    scanf("%d%d",&n,&m);
    int a,b;
    while (m--){
        scanf("%d%d",&a,&b);
        al[a].push_back(b);
    }
    int ans=0;
    for (int x=1;x<=n;x++){
        ans=max(ans,dp(x));
    }
    printf("%d\n",ans-1);
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int , int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti set <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    ll n;
    cin>>n;
    ld a[n+1];
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    ld dp[n+1][n+1];
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=n;j++)
        {
            dp[i][j]=0;
        }
    }
    dp[1][1]=a[1];
    dp[1][0]=1-a[1];
    for(ll i=2;i<=n;i++)
    {
        dp[i][0]=(1-a[i])*dp[i-1][0];
    }
    for(ll i=2;i<=n;i++)
    {
        for(ll j=1;j<=i;j++)
        {
            dp[i][j]=(dp[i-1][j-1]*a[i])+(dp[i-1][j]*(1-a[i]));
        }
    }
    ld ans=0;
    for(ll i=(n/2)+1;i<=n;i++)
    {
        ans+=dp[n][i];
    }
    cout<<fixed<<stp<<ans;
}

Measured memory_bytes: 140928
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int c=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt();
    if(Math.abs(a-c)>Math.abs(b-c)){
      System.out.println("B");
    }else{
      System.out.println("A");
    }
  }
}


Measured memory_bytes: 21844
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = tmp[0]
	var b = tmp[1]
	var c = tmp[2]
    var s = a[0]+b[0]+c[0]
    s=s.toUpperCase();
  	
  	
	//出力
	console.log('%s',s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	string S; cin >> S;

	if (N % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}

	Yes(S.substr(0, N / 2) == S.substr(N / 2, N / 2));


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B; cin >> A >> B;
  
  if (A % 2 != 0 && B % 2 != 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int H, W;
int A[80][80];
int B[80][80];
bool dp[80][80][25601];
const int border = 12800;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            cin >> A[h][w];
        }
    }
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            cin >> B[h][w];
        }
    }
    dp[0][0][border+A[0][0]-B[0][0]] = true;
    dp[0][0][border-A[0][0]+B[0][0]] = true;
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            for(int before = 0; before <= 2 * border; before++) {
                if(!dp[h][w][before]) continue;
                //cerr << h << " " << w << " " << before - border << endl;
                if(h != H - 1) {
                    int after = before + A[h+1][w] - B[h+1][w];
                    if(after >= 0 && after <= 2 * border) {
                        dp[h+1][w][after] |= dp[h][w][before];
                    }
                    after = before - A[h+1][w] + B[h+1][w];
                    if(after >= 0 && after <= 2 * border) {
                        dp[h+1][w][after] |= dp[h][w][before];
                    }
                }
                if(w != W - 1) {
                    int after = before + A[h][w+1] - B[h][w+1];
                    if(after >= 0 && after <= 2 * border) {
                        dp[h][w+1][after] |= dp[h][w][before];
                    }
                    after = before - A[h][w+1] + B[h][w+1];
                    if(after >= 0 && after <= 2 * border) {
                        dp[h][w+1][after] |= dp[h][w][before];
                    }
                }
            }
        }
    }
    int ans = 1e9;
    for(int val = 0; val <= 2 * border; val++) {
        if(dp[H-1][W-1][val]) {
            chmin(ans, abs(val - border));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 159104
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define endl "\n"

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
const int N = 2e5 + 10;
const ll inf = 1e18 + 10, mod = 1e9 + 7;
int n, x, y, dx[N], dy[N], k, ans[N];
int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("lca_rmq.in", "r", stdin);
    //freopen("lca_rmq.out", "w", stdout);
    cin >> n >> x >> y;
    for(int i = x; i <= n; i++)dx[i] = k++;
    k = 0;
    for(int i = x; i >= 1; i--)dx[i] = k++;
    k = 0;
    for(int i = y; i <= n; i++)dy[i] = k++;
    k = 0;
    for(int i = y; i >= 1; i--)dy[i] = k++;

    for(int i = 1; i <= n; i++)
    {
        for(int j = i + 1; j <= n; j++)
        {
            ans[min(j - i, dx[i] + dy[j] + 1)]++;
        }
    }
    for(int i = 1; i < n; i++)cout << ans[i] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;

int n;

struct point{
    double x, y; 
};

void koch(double x1, double y1, double x2, double y2, int q){
    point s, t, u, a, b, c, d;
    double x = (x2-x1)/3, y = (y2-y1)/3;
    double r = sqrt(x*x + y*y);
    s.x = x1 + x; s.y = y1 + y;
    t.x = x2 - x; t.y = y2 - y;
    u.x = (t.x-s.x)/2 - sqrt(3)*(t.y-s.y)/2 + s.x;
    u.y = sqrt(3)*(t.x-s.x)/2 + (t.y-s.y)/2 + s.y;
    if (q == 1) {
        printf("%.5f %.5f\n", s.x, s.y);
        printf("%.5f %.5f\n", u.x, u.y);
        printf("%.5f %.5f\n", t.x, t.y);
        printf("%.5f %.5f\n", x2, y2);
        return;
    }
    else {
        koch(x1, y1, s.x, s.y, q-1);
        koch(s.x, s.y, u.x, u.y, q-1);
        koch(u.x, u.y, t.x, t.y, q-1);
        koch(t.x, t.y, x2, y2, q-1);
    }
}

int main(void){
    int e = 1, v = 2;
    point p1, p2;
    p1.x = 0; p1.y = 0; p2.x = 100; p2.y = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {v += e*3; e = v-1;}
    printf("%.5f %.5f\n", p1.x, p1.y);
    if (n > 0) koch(p1.x, p1.y, p2.x, p2.y, n);
    if (n == 0) printf("%.5f %.5f\n", p2.x, p2.y);
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n, h;
    cin >> n >> h;
    vector<int> a(n), b(n);
    
    for (int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    
    int ans = 0;
    int sum = 0;
    
    for (int i=0; i<n; i++){
        if(a[0] <= b[i]){
            sum += b[i];
            ans++;
            if(sum >= h){
                cout << ans << endl;
                return 0;
            }
        }
    }
    
    while(sum < h){
        sum += a[0];
        ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 4052
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

ll n, p;

int main() {
    cin >> n >> p;
    vector< int > factors(ceil(sqrt(p)), 0);

    if (n == 1) {
        cout << p << endl;
        return 0;
    }

    ll x = p;
    for (int i = 2; i <= sqrt(p); i++) {
        while (x % i == 0) {
            factors[i] += 1;
            x /= i;
        }
    }

    int ans = 1;
    for (int i = 2; i <= sqrt(p); i++) {
        // cout << i << ": " << factors[i] << endl;
        if (factors[i] / n >= 1) {
            ans = ans * pow(i, floor(factors[i] / n));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4096
# https://atcoder.jp/contests/abc117/tasks/abc117_c


N, M = gets.split.map(&:to_i)
Xs = gets.split.map(&:to_i)

if N >= M
  puts "0"
  exit
end

Xs.sort!
D = Xs.last - Xs.first
ds = Xs.each_cons(2).map { |x1, x2| x2 - x1 }.sort.reverse

ans = D - (ds.take(N - 1).reduce(&:+) || 0)
puts ans


Measured memory_bytes: 13384
//  ######    ##   ######    ##   ##    ##
//  ##  ##   ###   ##  ##   ###   ###   ##
//  ######  ####   ######  ####   ##### ##
//  ##     ## ##   ##     ## ##   ## #####
//  ##    ##  ##   ##    ##  ##   ##   ###
#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++)
#define mod 1000000007
#define gc getchar_unlocked
#define pc putchar_unlocked3
#define pb(a) push_back((a))
#define mod 1000000007



lo gcdExtended(lo a, lo b, lo *x, lo *y); 
 
lo modInverse(lo b, lo m) 
{ 
    lo x, y; // used in extended GCD algorithm 
    lo g = gcdExtended(b, m, &x, &y); 
  
    // Return -1 if b and m are not co-prime 
    if (g != 1) 
        return -1; 
  
    // m is added to handle negative x 
    return (x%m + m) % m; 
} 
lo modDivide(lo a, lo b, lo m) 
{ 
    a = a % m; 
    lo inv = modInverse(b, m); 
    return (inv * a) % m; 
} 
lo gcdExtended(lo a, lo b, lo *x, lo *y) 
{ 
    // Base Case 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    lo x1, y1; // To store results of recursive call 
    lo gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    // Update x and y using results of recursive 
    // call 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 
  



lo ans = 0;
lo n,m;

void solve()
{

    lo a,b;
    cin>>a>>b;
    if((a+b)%3!=0){cout<<0;return;}
    else n = (a+b)/3;
    lo r=n*2-a;
    if(r<0||r>n){cout<<0;return;}
    r=min(r,n-r);
    if(r<0||r>n){cout<<0;return;}
    //cout<<n<<' '<<r<<endl;
    lo x = n-r;
    lo p=1;
    lo q=1;
    lo s=1;
    for(lo k=x+1;k<=n;k++){p=(p*k)%mod;}
    while(r)
    {q=(q*r)%mod;r--;}

    lo ans = modDivide(p,q,mod);
    //ans = modDivide(ans,s,mod);
    cout<<ans;
}


int main()
{
        ios::sync_with_stdio(0);
    cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    */
    
    lo t;
    //cin>>t;
    //while(t--)
        solve();




}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

#define MAX(a, b) (a>b?a:b)
#define MIN(a, b) (a<b?a:b)
#define MOD 1000000007

int compare(const void* a, const void* b) {
    return *(int*)a-*(int*)b;
}

int findMax(int* a, int n) {
    int i, max = INT_MIN, max_ind = -1;
    for(i=0;i<n;i++) {
        if(a[i] >= max) {
            max = a[i];
            max_ind = i;
        }
    }
    return max_ind;
}

void testCase() {
    long long int i, a, b, n, res;
    if(scanf("%lld%lld%lld", &a, &b, &n)) {
        if(n < b) {
            res = (a*n)/b;
        }
        else {
            res = (a*(b-1))/b;
        }
        printf("%lld\n", res);
    }
}

int main() {
    int t=1;
    // scanf("%d", &t);
    while(t--) {
        testCase();
    }
    return 0;
}

Measured memory_bytes: 1688
#include <iostream>
#include <vector>

using namespace std;

using sushi = pair<long, int>;


int main(int argc, char *argv[]) {
	int N;
	long C;
	cin >> N >> C;

	vector<sushi> s(N);
	
	for (int i = 0; i < N; i++) {
		long x;
		int v;
		cin >> x >> v;
		s[i] = make_pair(x, v);
	}

	long ans = 0;
	
	vector<long> cl(N); // clockwise
	vector<long> cc(N); // counter-clockwise
	vector<long> cl_max(N);
	vector<long> cc_max(N);
	
	cl[0] = s[0].second;
	cl_max[0] = cl[0] - s[0].first;
	for (int i = 1; i < N; i++) {
		cl[i] = cl[i - 1] + s[i].second;
		cl_max[i] = max(cl_max[i - 1], cl[i] - s[i].first);
	}

	cc[N-1] = s[N-1].second;
	cc_max[N-1] = cc[N-1] - (C - s[N-1].first);
	for (int i = N - 2; i >= 0; i--) {
		cc[i] = cc[i + 1] + s[i].second;
		cc_max[i] = max(cc_max[i + 1], cc[i] - (C - s[i].first));
	}

	ans = max(ans, cl_max[N - 1]);
	ans = max(ans, cc_max[0]);

	for (int i = 0; i < N - 1; i++)
		ans = max(ans, cl[i] - 2 * s[i].first + cc_max[i + 1]);

	for (int i = N - 1; i > 0; i--)
		ans = max(ans, cc[i] - 2 * (C - s[i].first) + cl_max[i - 1]);

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

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, D;
    cin >> N >> D;
    vector<int> X(N), Y(N);
    for(int i = 0; i < N; ++i)  cin >> X[i] >> Y[i];

    vector<vector<int>> graph(N * 2), rev(N * 2);
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < i; ++j){
            if(abs(X[i] - X[j]) < D){
                graph[i * 2 + 1].emplace_back(j * 2);
                graph[j * 2 + 1].emplace_back(i * 2);
                rev[i * 2].emplace_back(j * 2 + 1);
                rev[j * 2].emplace_back(i * 2 + 1);
            }
            if(abs(X[i] - Y[j]) < D){
                graph[i * 2 + 1].emplace_back(j * 2 + 1);
                graph[j * 2].emplace_back(i * 2);
                rev[i * 2].emplace_back(j * 2);
                rev[j * 2 + 1].emplace_back(i * 2 + 1);
            }
            if(abs(Y[i] - X[j]) < D){
                graph[i * 2].emplace_back(j * 2);
                graph[j * 2 + 1].emplace_back(i * 2 + 1);
                rev[i * 2 + 1].emplace_back(j * 2 + 1);
                rev[j * 2].emplace_back(i * 2);
            }
            if(abs(Y[i] - Y[j]) < D){
                graph[i * 2].emplace_back(j * 2 + 1);
                graph[j * 2].emplace_back(i * 2 + 1);
                rev[i * 2 + 1].emplace_back(j * 2);
                rev[j * 2 + 1].emplace_back(i * 2);
            }
        }
    }

    vector<int> vs;
    vector<bool> used(N * 2, false);
    auto dfs = [&](auto&& self, int cur) -> void {
        used[cur] = true;
        for(int nxt : graph[cur]){
            if(!used[nxt])  self(self, nxt);
        }
        vs.emplace_back(cur);
    };
    for(int v = 0; v < N * 2; ++v){
        if(!used[v])    dfs(dfs, v);
    }
    reverse(vs.begin(), vs.end());

    vector<int> scc_id(N * 2, -1);
    int K = 0;
    auto rdfs = [&](auto&& self, int cur) -> void {
        scc_id[cur] = K;
        for(int nxt : rev[cur]){
            if(scc_id[nxt] == -1)   self(self, nxt);
        }
    };
    for(int v : vs){
        if(scc_id[v] == -1){
            rdfs(rdfs, v);
            ++K;
        }
    }

    vector<bool> ans(N);
    for(int i = 0; i < N; ++i){
        if(scc_id[i * 2] == scc_id[i * 2 + 1]){
            cout << "No\n";
            return 0;
        }
        ans[i] = scc_id[i * 2] < scc_id[i * 2 + 1];
    }

    cout << "Yes\n";
    for(int i = 0; i < N; ++i)  cout << (ans[i] ? X[i] : Y[i]) << '\n';
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;

  if (N % 1000 % 111 == 0) {
    cout << "Yes" << endl;
  }
  else if (N % 1110 <= 9) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main() {
  int d;
  cin >> d;

  if (d == 25) {
    cout << "Christmas" << endl;
  } else if (d == 24) {
    cout << "Christmas Eve" << endl;
  } else if (d == 23) {
    cout << "Christmas Eve Eve" << endl;
  } else {
    cout << "Christmas Eve Eve Eve" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  if(a==b){
    cout << 2*a;
  }
  else if(a > b){
  	cout << 2*a-1 << endl;
  }
  else if(a < b){
  	cout << 2*b-1 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N;
    vector<int> row;
    cin >> N;
    for(int i = 0;i<N;i++){
        int temp = 0;
        cin >> temp;
        row.push_back(temp);
    }
    int times = 0;
    for(int i = 0;i<N;i++){
        int minj = i;
        for(int j = i;j < N;j++){
            if(row[j] < row[minj]){
                minj = j;
            }
        }
        if(i != minj){
            times ++;
            swap(row[i], row[minj]);
        }
        
    }
    
    for(int i = 0;i < N;i++){
        if(i == N - 1){
            cout << row[i] << endl;
        }else{
            cout << row[i] << " ";
        }
    }
    cout << times << endl;
    return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<int>r(n,0);
	for(int i=0,a,b;i<m;++i){
		cin>>a>>b;
		++r.at(a-1),++r.at(b-1);
	}
	for(auto&i:r)cout<<i<<"\n"s;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int x[n], y[n], a[n];
    for (int i = 0; i < n; i++)
        cin >> x[i] >> y[i] >> a[i];
    int v[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            v[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++) {
        if (a[i] == 1) {
            for (int j = 0; j < h; j++) {
                for (int k = 0; k < x[i]; k++)
                    v[j][k] = 1;
            }
        } else if (a[i] == 2){
            for (int j = 0; j < h; j++) {
                for (int k = x[i]; k < w; k++)
                    v[j][k] = 1;
            }
        } else if (a[i] == 3) {
            for (int j = h - y[i]; j < h; j++) {
                for (int k = 0; k < w; k++)
                    v[j][k] = 1;
            }
        } else {
            for (int j = 0; j < h - y[i]; j++) {
                for (int k = 0; k < w; k++)
                    v[j][k] = 1;
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (!v[i][j])
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def stones(input):
    k, x = map(int, input.split())
    if k is 1:
        print(x)
        return x
    j = [i for i in range(x - k + 1, x + k)]
    s = ' '.join(map(str, j))
    print(s)
    return
 
 
stones(input())

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int cho, ei, don;
	cho = ei = don = 0;
	for (int a, b, c; cin >> a >> b >> c;) {
		vector<int> v{ a,b,c };
		sort(all(v));
		a = v[0], b = v[1], c = v[2];
		if (a + b <= c)break;
		if (a*a + b*b == c*c)cho++;
		else if (a*a + b*b > c*c)ei++;
		else don++;
	}
	cout << cho + ei + don << " " << cho << " " << ei << " " << don << endl;
	return 0;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;


int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);

    long long n,a,b;
    cin>>n>>a>>b;
    long long x[n];
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    long long ans=0;
    long long now=x[0];
    for(int i=1;i<n;i++){
        ans += min(b,a*(x[i]-now));
        now = x[i];
    }
    cout << ans << endl;

    
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)

@mt
def slv(S):
    M = Mod(10**9 + 7)
    t = [0] * 13
    t[0] = 1
    m = 1
    for i, c in enumerate(reversed(S)):
        if c != '?':
            n = (m * int(c)) % 13
            nt = [0] * 13
            for k in range(13):
                nt[(k+n) % 13] = t[k]
            t = nt
        else:
            nt = [0] * 13
            for j in range(10):
                n = (m * j) % 13
                for k in range(13):
                    nt[(k+n) % 13] = M.add(nt[(k+n) % 13], t[k])
            t = nt
        m *= 10
        m %= 13
    return t[5]


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 64728
#include <iostream>
int main()
{
    int k, s;
    std::cin >> k;
    std::cin >> s;

    int cnt = 0;

    if ( k == s )
    {
        cnt = (k + 2)*(k+1)/2;
    }
    else
    {
        const int lim = std::min(k, s);
        // off-diagonal
        for (int ix = 0; ix < lim+1; ++ix)
        {
            for (int iy = ix + 1; iy < lim+1; ++iy)
            {
                const int z = s - ix - iy;
                if (z < 0) break;
                if (z <= k) ++cnt;
            }
        }
        cnt *= 2;

        // diagonal
        for (int ix = 0; ix < lim+1; ++ix)
        {
            const int z = s - 2*ix;
            if (z < 0) break;
            if (z <= k) ++cnt;
        }
    }

    std::cout << cnt << "\n";

    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

#define INF 100000

int main(){
  long long a,b,c;
  cin >> a >> b >> c;
  long long ans = 0;
  ans += b;
  ans += min(a+b+1,c);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 10000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int m, n;
string s[1005];
string joi[2];
char w[3] = {'J', 'O', 'I'};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    rep(i, n) cin >> s[i];
    rep(i, 2) cin >> joi[i];
    int ans = 0;
    rep(i, n - 1)rep(j, m - 1) {
        bool ok = true;
        rep(k, 2)rep(l, 2) {
            if (s[i + k][j + l] != joi[k][l]) {
                ok = false;
                break;
            }
        }
        if (ok) ans++;
    }
    int plus = 0;
    rep(i, n)rep(j, m) {
        int cnt = 0;
        rep2(l, i - 1, i + 1)rep2(o, j - 1, j + 1) {
            if (l < 0 || o < 0) continue;
            bool ok = true;
            rep(a, 2)rep(b, 2) {
                if (l + a >= n || o + b >= m) {
                    ok = false;
                    break;
                }
                if (s[l + a][o + b] != joi[a][b]) {
                    ok = false;
                    break;
                }
            }
            if (ok) cnt++;
        }
        char tmp = s[i][j];
        rep(k, 3) {
            s[i][j] = w[k];
            int cnt_tmp = 0;
            rep2(l, i - 1, i + 1)rep2(o, j - 1, j + 1) {
                if (l < 0 || o < 0) continue;
                bool ok = true;
                rep(a, 2){
                    rep(b, 2) {
                        if (l + a >= n || o + b >= m) {
                            ok = false;
                            break;
                        }
                        if (s[l + a][o + b] != joi[a][b]) {
                            ok = false;
                            continue;
                        }
                    }
                }
                if (ok) cnt_tmp++;
            }
            plus = max(plus, cnt_tmp - cnt);
        }
        s[i][j] = tmp;
    }
    cout << ans + plus << endl;
}

Measured memory_bytes: 4120
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]

N = 0
ans = []
for hi in range(H):
  for wi in range(W-1):
    if a[hi][wi]%2 == 1:
      N += 1
      a[hi][wi+1] += 1
      ans.append((hi+1, wi+1, hi+1, wi+2))
      
for hi in range(H-1):
  if a[hi][-1]%2 == 1:
    N += 1
    a[hi+1][-1] += 1
    ans.append((hi+1, W, hi+2, W))
    
print(N)
for y, x, yp, xp in ans:
  print(y, x, yp, xp)

Measured memory_bytes: 28376
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h, a, q, r;
  cin >> h >> a;
  if (h < a) {
    cout << 1 << endl;
     return 0;
  }
  q = h/a;
  r = h%a;
  if (0 < r) {
    q += 1;
  }
  cout << q << endl;
}

Measured memory_bytes: 3596
#include <cmath>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    cout << max(0, n-k+1) << endl;
}


Measured memory_bytes: 892
#include <iostream>
#include <vector>
using namespace std;
const int V_MAX = 50;

struct LowLink
{
	const vector<vector<int>> &g;
	int V;
	vector<vector<int>> dfs_tree;
	vector<int> dfs_roots;
	int pre_order[V_MAX];
	int p_ord = 0;
	int lowlink[V_MAX];
	bool articulation[V_MAX] = {};
	vector<pair<int, int>> bridge;

	LowLink(const vector<vector<int>> &g) : g(g), V(g.size()), dfs_tree(g.size()) {}

	void dfs(int v, int parent) {
		lowlink[v] = pre_order[v] = p_ord;
		p_ord++;
		for (int nv : g[v]) {
			if (nv == parent) continue;
			if (pre_order[nv] == -1) {
				dfs_tree[v].push_back(nv);
				dfs(nv, v);
				lowlink[v] = min(lowlink[v], lowlink[nv]);
			}
			lowlink[v] = min(lowlink[v], pre_order[nv]);
		}
	}

	void calc() {
		p_ord = 0;
		fill(pre_order, pre_order+V_MAX, -1);
		for (int i = 0; i < V; i++) {
			if (pre_order[i] != -1) continue;
			dfs_roots.push_back(i);
			dfs(i, -1);
		}
		for (int i = 0; i < V; i++) {
			for (int j : dfs_tree[i]) {
				if (pre_order[i] < lowlink[j]) bridge.push_back({i, j});
			}
		}
		for (int i = 0, x = 0; i < V; i++) {
			bool ok = false;
			if (x < dfs_roots.size() && dfs_roots[x] == i) {
				if (dfs_tree[i].size() > 1) ok = true;
				x++;
			} else {
				for (int j : dfs_tree[i]) {
					if (pre_order[i] <= lowlink[j]) ok = true;
				}
			}
			articulation[i] = ok;
		}
	}
};

int main() {
	int n , m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	LowLink L(g);
	L.calc();
	int ans = L.bridge.size();
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long int
#define fin(x) scanf("%lld",&x)
#define fout(x) printf("%lld\n",x)
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
#define cases int t;  scanf("%d",&t);   while(t--)
#define MOD 1000000007
#define MAXN 123456
#define read() freopen("lele.txt","r",stdin)
#define write() freopen("dede.txt","w",stdout)

using namespace std;

ll ar[MAXN], sum[MAXN];

int main()
{	
	ll n, m, ans = 0;
	fin(n); fin(m);
	map <ll,ll> open, close;
	for(ll i = 1; i <= m; i++)
	{
		ll x, y;
		fin(x); fin(y);
		open[x]++;
		close[y]++;
		ar[x]++;
		ar[y + 1]--;
	}
	ll curr = 0;
	for(ll i = 1; i <= n; i++)
	{
		curr += ar[i];
		sum[i] = curr;
	}
	for(ll i = 1; i <= n; i++)
		ans += (sum[i] == m);
	fout(ans);
	return 0;
}


Measured memory_bytes: 14336
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] xs) {
    int n = cast(int)xs.length;
    return max(xs.sum, (xs[0] - 1) + (9 * (n - 1)));
}

void main() {
    auto s = readln.chomp;
    auto xs = s.map!(e => cast(int)(e - '0')).array;

    auto ans = calc(xs);
    writeln(ans);
}


Measured memory_bytes: 256
N , Q = map(int,input().split())
S = input()

count = [0] * (N + 1)

for i in range(N) :
    count[i+1] = count[i] + (1 if S[i:i+2] == 'AC' else 0)

ans = [0] * Q

for i in range(Q) :
    l , r = map(int,input().split())
    ans[i] = count[r-1] - count[l-1]

for a in ans :
    print(a)





Measured memory_bytes: 11876
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>

#define DEBUG 0
#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;

int main() {
    if (DEBUG) {
        freopen("CP.inp", "r", stdin);
        //freopen("CP.out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    vi a(n + 1); for (int &x : a) cin >> x;
    vi b(n); for (int &x : b) cin >> x;
    LL res = 0, tmp;
    fore(i, 0, n) {
        tmp = min(b[i], a[i]);
        a[i] -= tmp;
        b[i] -= tmp;
        res += tmp;
        tmp = min(b[i], a[i + 1]);
        a[i + 1] -= tmp;
        b[i] -= tmp;
        res += tmp;
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int h,m,hh,mm,k; cin >> h>>m>>hh>>mm>>k;
    int a,b;
    a = 60*h+m; b = 60*hh+mm;
    int ans = b-a-k;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
S = input()
T = input()

SS = sorted(list(S))
TT = sorted(list(T))
SSS = []
TTT = []
numS = 0
checkS = 1
checkT = 1

for i in range(len(S)-1):
    if SS[i] != SS[i+1]:
        SSS.append(checkS)
        checkS = 1
    elif i == len(S)-2:
        SSS.append(checkS+1)
    else:
        checkS += 1

    if TT[i] != TT[i+1]:
        TTT.append(checkT)
        checkT = 1
    elif i == len(S)-2:
        TTT.append(checkT+1)
    else:
        checkT += 1
SSS.sort()
TTT.sort()
if SSS == TTT:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 8904
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int n, k;
ll a[100000];
ll fact[100000];
ll inv[100000];

ll pow(ll a, ll b) {
    if (b == 0) return 1;
    if (b % 2) return a * pow(a, b - 1);
    return pow(a * a, b / 2);
}
//a^(-1)≡a^(p-2) (mod p) (but p is prime)
ll powMod(ll a, ll b, ll p) {
    if (b == 0) return 1;
    if (b % 2) return (a * powMod(a, b - 1, p)) % p;
    return powMod(a * a % p, b / 2, p);
}

ll combi(ll nn, ll kk) {
    if (nn < kk)
        return 0;
    return (((fact[nn] * inv[nn - kk]) % MOD7) * inv[kk]) % MOD7;
}

void pre() {
    fact[0] = 1;
    inv[0] = 1;
    for (int i = 1; i < n; ++i) {
        fact[i] = (fact[i - 1] * i) % MOD7;
        inv[i] = (inv[i - 1] * powMod(i, MOD7 - 2, MOD7)) % MOD7;
    }
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    
    pre();

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += (a[i] * combi(i, k - 1)) % MOD7;
        ans %= MOD7;
        ans -= (a[i] * combi(n - i - 1, k - 1)) % MOD7;
        ans %= MOD7;
    }
    if (ans < 0)
        ans += MOD7;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

Vii G;
Vi dp;

int dfs(int k)
{
	if (dp[k] != -1)  return dp[k];
	if (G[k].size() == 0)  return 0;

	int res = 0;
	for (int u : G[k]) {
		res = max(res, dfs(u) + 1);
	}
	return dp[k] = res;
}




int main()
{
	int n, m;
	cin >> n >> m;
	G.resize(n);
	rep(i, m) {
		int x, y;
		cin >> x >> y;
		x--;  y--;
		G[x].push_back(y);
	}
	
	dp.resize(n, -1);
	int ans = 0;
	rep(i, n)  chmax(ans, dfs(i));

	cout << ans << endl;
}


Measured memory_bytes: 8192
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

#define rep(i, n) for(int i=0;i<n;i++)

using namespace std;
int main(){

	int a;
	cin >> a;
	if (a < 1200)
		cout << "ABC" << endl;
	else
		cout << "ARC" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

using P = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> l(n), r(n);
  int lmax = 0, rmin = 1e9+10, lidx, ridx;
  rep(i, n) {
    cin >> l[i] >> r[i];
    r[i]++;
    if (chmax(lmax, l[i]))
      lidx = i;
    if (chmin(rmin, r[i]))
      ridx = i;
  }
  
  int mx = 0;
  rep(i, n) chmax(mx, r[i]-l[i]);
  int ans = mx+max(rmin-lmax, 0);

  if (lidx != ridx) {
    vector<P> rem;
    rep(i, n) {
      if (i == lidx || i == ridx)
        continue;
      rem.push_back({l[i], r[i]});
    }
    sort(rem.rbegin(), rem.rend());
    rem.push_back({l[ridx], r[ridx]});
    int l1 = rem[0].first, r1 = rmin;
    int l2 = lmax, r2 = r[lidx];
    chmax(ans, max(r1-l1, 0)+max(r2-l2, 0));
    rep(i, n-2) {
      l1 = rem[i+1].first;
      chmin(r2, rem[i].second);
      chmax(ans, max(r1-l1, 0)+max(r2-l2, 0));
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2168
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
#include <climits>
using namespace std;
#define INF 1100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int d[110000];
ll ans=0;
vector<int> V[110000];
int N,K,a,b;


void bfs(){
  queue<int> que;

  for(int i=0;i<110000;i++){
      d[i]=INF;
  }
  d[0]=0;
  que.push(0);
  ans=K;
  while(que.size()){
    int count=0;
    int p=que.front(); que.pop();
    for(int i=0;i<(int)V[p].size();i++){
      int np=V[p][i];
      if(d[np]==INF){
        que.push(np);
        d[np]=d[p]+1;
        if(d[np]==1) ans*=(K-d[np]-count);
        else ans*=(K-2-count);
        count++;
        ans%=MOD;
      }
    }
  }

  return;
}


int main(){
    cin>>N>>K;
    for(int i=0;i<N-1;i++){
        cin>>a>>b;
        a--; b--;
        V[a].push_back(b);
        V[b].push_back(a);
    }
    bfs();
    cout<<ans<<endl;
}


Measured memory_bytes: 7160