akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define mod 1000000007
#define vll vector<ll>
#define pll vector<pair<ll,ll>>



int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	//cin>>t;
	t=1;
	start:
	while(t--){

      ll n,x,t,ans=0;
      cin>>n>>x>>t;

      while(n>=x){
        n-=x;
        ans+=t;

      }
      if(n==0){
        cout<<ans<<endl;
      }
      else cout<<ans+t<<endl;

	}
	return 0;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, M;
  cin >> N >> M;

  if (N == 1 && M == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (N == 1) {
    cout << M - 2 << endl;
    return 0;
  }
  if (M == 1) {
    cout << N - 2 << endl;
    return 0;
  }
  cout << (N - 2) * (M - 2) << endl;

  return 0;
}


Measured memory_bytes: 256
// IlyM

#include <bits/stdc++.h>

#define pb push_back
#define sp " "
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())
#define tra(a,b) for (auto a:b) 
#define fo(a,b,c) for (unsigned long long a=b;a<=c;a++) 
#define ms(a,b) memset(a,b,sizeof(a)) 
#define all(a) a.begin(),a.end()
#define rev(a) reverse(a.begin(),a.end())

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef pair<int,ii> iii;

const int N=2e6+5,mod=998244353;
int x,y,a,b,c,q[N],w[N],e[N];
vi res;
int pp;
ll s;
int main()
{
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	cin>>x>>y>>a>>b>>c;
	fo(i,0,a-1) cin>>q[i];
	fo(i,0,b-1) cin>>w[i];
	fo(i,0,c-1) cin>>e[i];
	sort(q,q+a); sort(w,w+b); sort(e,e+c);
	reverse(q,q+a); reverse(w,w+b); reverse(e,e+c);
	fo(i,0,x-1) res.pb(q[i]);
	fo(i,0,y-1) res.pb(w[i]);
	sort(all(res));
	fo(i,0,c-1) {
		if (e[i]>res[pp]) {
			swap(res[pp],e[i]);
			if (pp<sz(res)-1) pp++;
			else i=mod;
		}
	}
	fo(i,0,sz(res)-1) s+=res[i];
	cout<<s;
	return 0;
}


Measured memory_bytes: 7928
#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
void debug(vector<T> &vec) {
    for (auto x : vec) {
        cout << x << " ";
    }
    cout << endl;
    return;
}

template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

void solve(int n) {
    vector<int> vec(1e5);
    REP(i, n) {
        int sh, sm, ss, th, tm, ts;
        scanf("%d:%d:%d %d:%d:%d", &sh, &sm, &ss, &th, &tm, &ts);
        int s = sh * 3600 + sm * 60 + ss, t = th * 3600 + tm * 60 + ts;
        vec[s] += 1;
        vec[t] -= 1;
    }

    REP(i, 1e5 - 1) {
        vec[i + 1] += vec[i];
    }

    int ans = 0;

    REP(i, 1e5) {
        ans = max(ans, vec[i]);
    }

    cout << ans << endl;

    return;
}

int main() {
    int n;
    while (cin >> n && n) {
        solve(n);
    }
    return 0;
}


Measured memory_bytes: 3536
#include <stdio.h>

int main(void) {
  int n;
  int bool = 0;
  scanf("%d", &n);
  for(int i = 100; i >= 1; i /= 10) {
    if(n / i == 7) {
      printf("Yes");
      bool = 1;
      break;
    } else {
      n %= i;
    }
  }
  if(bool == 0) {
    printf("No");
  }
  return 0;
}


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

const int MOD = (int)1e9 + 7;


class BIT {
private:
    VI _bit;
    int _n_max;
    function<int(int&, int&)> _binary_operator;

public:
    BIT(int n, function<int(int&, int&)> binary_operator): 
        _n_max(n), _binary_operator(binary_operator) {
        _bit.resize(_n_max + 1, 0);
    }

    void add(int i, int x) {  // 1-indexed
        for(int j = i; j <= _n_max; j += j & -j) 
            _bit.at(j) = _binary_operator(x, _bit.at(j));
    }

    int sum(int i) {  // 1-indexed, sum of [1, i]
        int res = 0;
        for(int j = i; j > 0; j -= j & -j) 
            res = _binary_operator(res, _bit.at(j));
        return res;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    VI a(n);
    REP(i, n) cin >> a.at(i);
    vector<BIT> bit(n + 1, BIT(k + 1, [](int& lhs, int& rhs) {
        return ((ll)lhs + (ll)rhs) % MOD;
    }));
    bit.at(0).add(0 + 1, 1);
    FOR(i, 1, n)FOR(j, 0, k) {
        ll sum = bit.at(i - 1).sum(j + 1) 
            - bit.at(i - 1).sum(max(j - a.at(i - 1), 0));
        bit.at(i).add(j + 1, (sum + MOD) % MOD);
    }

    cout << (bit.at(n).sum(k + 1) - bit.at(n).sum(k) + MOD) % MOD << ln;
    return 0;
}


Measured memory_bytes: 40192
#include <iostream>
#include <vector>
using namespace std;
using ll=long long;
int main(){
  ll n; cin >> n;
  ll a[n]={0}, b[n];
  ll c=0;
  for(int i=0; i<n; i++) {ll m; cin >> m; b[i]=m-1; a[m-1]++;}
  for(int i=0; i<n; i++) c+=a[i]*(a[i]-1)/2;
  for(int i=0; i<n; i++){
    ll ans=c;
    if(a[b[i]]>=2){
      ans-=a[b[i]]*(a[b[i]]-1)/2;
      ans+=(a[b[i]]-1)*(a[b[i]]-2)/2;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 5760
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
D = [tuple(map(int, input().split())) for _ in range(N)]

for i in range(N-2):
    if D[i][0]==D[i][1] and D[i+1][0]==D[i+1][1] and D[i+2][0]==D[i+2][1]:
        print('Yes')
        exit()

print('No')


Measured memory_bytes: 64920
#include<stdio.h>
int main(){
	int H,W,i,i2,i3,ans[100][100],owata;
	char a[100][100];
	scanf("%d%d",&H,&W);
	for(i=0;i!=H;i++){
		scanf("%s",a[i]);
		for(i2=0;i2!=W;i2++){
			if(a[i][i2]=='c'){
				ans[i][i2]=0;
			}
			else{
				if(i2==0){
					ans[i][i2]=-1;
				}
				else{
					owata=1;
					for(i3=i2-1;1;i3--){
						if(a[i][i3]=='c'){
							ans[i][i2]=owata;
							break;
						}
						else if(i3==0){
							ans[i][i2]=-1;
							break;
						}
						owata++;
					}
				}
			}
		}
	}
	for(i=0;i!=H;i++){
		for(i2=0;i2!=W;i2++){
			printf("%d",ans[i][i2]);
			if(i2!=(W-1)){
				printf(" ");
			}
		}
		printf("\n");
	}
}

Measured memory_bytes: 2724
#include <bits/stdc++.h>
using namespace std;
#define sc(x)            scanf("%d",&x)
#define scc(x)           scanf("%c",&x)
#define scl(x)           scanf("%lld",&x)
#define sz(v)	     	(v.size())
#define mem(v, d)		memset(v, d, sizeof(v))
#define oo				2000000100
#define OO				2000000000000000100
#define PI 3.14159265
#define S second
#define F first
#define Ceil(x,y) ((x+y-1)/y)
#define EPS 1e-8
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double pi=3.14159265358979323846264338327950288419716939937510582097494459;
typedef unsigned int uint;
typedef long long ll;
int dX[] = {0,0,1,-1,0};
int dY[] = {1,-1,0,0,0};
string alpha = "abcdefghijklmnopqrstuvwxyz";
const int MOD = 1000000007;
const int N = 100100;
int n,k;
ll out;

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
#else
    //freopen("journey.in","r",stdin);
    //freopen("journey.out","w",stdout);
#endif
    sc(n); sc(k);
    priority_queue<int>pq; int x;
    for(int i = 0;i<n;++i) sc(x),pq.push(x);
    while(k--)
        x = pq.top(),pq.pop(),x>>=1,pq.push(x);


    while(!pq.empty()) out+=pq.top(),pq.pop();
    printf("%lld\n",out);






    return 0;
}


Measured memory_bytes: 892
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int max = 0;
		int count = 0;
		for (int i = 1; i < n; i++) {
			if (h[i] <= h[i - 1]) {
				count++;
			} else {
				max = Math.max(max, count);
				count = 0;
			}
		}
		max = Math.max(max, count);
		System.out.println(max);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 22528
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  string a,b;
  int n;
  cin >> a >> b;
  n = stoll(a+b);
  bool ok = false;
  rep(i,0,500){
    if (pow(i,2) == n) {
      ok = true;
      break;
    }
  }  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////




int main(){
    
    ll n,W;cin>>n>>W;
    ll w[n+1],v[n+1];rep(i,1,n)cin>>w[i]>>v[i];
    ll N=100005;
    ll dp[n+1][N];
    rep(i,0,n)rep(j,0,N-1)dp[i][j]=inf;
    dp[0][0]=0;
    
    rep(i,1,n){
        rep(j,0,N-1){
            dp[i][j]=dp[i-1][j];
            if(j-v[i]>=0)Min(&dp[i][j],dp[i-1][j-v[i]]+w[i]);
        }
    }
    /*rep(i,0,n){
        rep(j,0,20-1){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    for(ll i=N-1;i>=0;i--){
        if(dp[n][i]<=W){
            cout<<i<<endl;return 0;
        }
    }
    return 0;
}




Measured memory_bytes: 79104
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Sort by Hand
// 2012/12/29
public class Main{
	Scanner sc=new Scanner(System.in);

	int n;
	int[] a;

	void run(){
		n=sc.nextInt();
		a=new int[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextInt()-1;
		}
		solve();
	}

	int[][] pool;
	int[] dp;

	void solve(){
		pool=new int[n][n];
		dp=new int[n+1];
		for(int i=0; i<=n; i++){
			if(dfs(a, 0, i)){
				println(i+"");
				return;
			}
		}
	}

	boolean dfs(int[] a, int step, int ub){
		int lis=lis(a);
		if(step+n-lis>ub){
			return false;
		}
		if(lis==n){
			return true;
		}

		int s, t;
		for(s=0; a[s]==s; s++);
		for(t=n-1; a[t]==t; t--);
		int[] b=pool[step];
		for(int i=s; i<=t; i++){ // [s, t]
			if(a[i]==i){
				continue;
			}
			System.arraycopy(a, 0, b, 0, n);
			if(a[i]<i){
				System.arraycopy(a, a[i], b, a[i]+1, i-a[i]);
			}
			if(a[i]>i){
				System.arraycopy(a, i+1, b, i, a[i]-i);
			}
			b[a[i]]=a[i];
			if(dfs(b, step+1, ub)){
				return true;
			}
		}
		return false;
	}

	int lis(int[] a){
		int lis=1;
		for(int j=0; j<n; j++){
			dp[j]=1;
			for(int i=0; i<j; i++){
				if(a[i]<a[j]){
					dp[j]=max(dp[j], dp[i]+1);
				}
			}
			lis=max(lis, dp[j]);
		}
		return lis;
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define x first
#define y second
#define y1 secondy1
#define rank tipa_rank
#define pb push_back
#define mp make_pair
#define pow10 tipa_pow10
#define ll long long
#define INF 1000000000
#define EPS 1e-9
#define EPS2 1e-8
#define PI acos(-1.0)
using namespace std;
const int MOD = INF + 7;
const int base = 2;
deque<int> dq;
vector<vector<int> > g(100000);
int n , m;
bool inPath[100000];
int main()
{
	scanf("%d %d" , &n , &m);
	dq.push_back(0);
	for(int i = 0; i < m; i++)
	{
		int u , v;
		scanf("%d %d"  ,&u , &v);
		u--;
		v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	inPath[0] = 1;
	while(true)
	{
		bool finish = true;
		int u = dq.front();
		for(int i = 0; i < g[u].size(); i++)
		{
			int v = g[u][i];
			if(!inPath[v])
			{
				dq.push_front(v);
				finish = false;
				inPath[v] = 1;
				break;
			}
		}
		u = dq.back();
		for(int i = 0; i < g[u].size(); i++)
		{
			int v = g[u][i];
			if(!inPath[v])
			{
				dq.push_back(v);
				finish = false;
				inPath[v] = 1;
				break;
			}
		}
		if(finish)
			break;
	}
	printf("%d\n" , dq.size());
	for(int i = 0; i < dq.size(); i++)
	{
		printf("%d " , dq[i] + 1);
	}
}


Measured memory_bytes: 6784
#include<stdio.h>

int parent( int i ){ return i / 2; }
int left( int i ){ return 2 * i; }
int right( int i ){ return 2 * i + 1; }

int main()
{
  int H, i;

  scanf("%d", &H);
  int A[H+1];

  for( i=1; i<=H; i++ )
    {
      scanf("%d", &A[i]);
    }

  for( i=1; i<=H; i++ )
    {
      printf("node %d: ", i);
      printf("key = %d, ", A[i]);

      if( parent(i) >= 1 )
	{
	  printf("parent key = %d, ", A[parent(i)]);
	}
      if( left(i) <= H )
	{
	  printf("left key = %d, ", A[left(i)]);
	}
      if( right(i) <= H )
	{
	  printf("right key = %d, \n", A[right(i)]);
	}
      if( right(i) > H )
	{
	  printf("\n");
	}
    }

  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    double x;
    cin >> x;
    ll X = 100;
    rep(i, 1e6) {
        X = (X / 100.0)*101.0;
        if (X >= x) {
            cout << i + 1<< '\n';
            return;
        }
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3740
def binarySearch(A, key):
    left = 0
    # right = n
    right = len(A)
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            # return mid
            return 1
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    # return NOT_FOUND
    return 0


if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))
    q = int(input())
    T = list(map(int, input().split()))
    ans = 0
    for t in T:
        ans += binarySearch(S, t)
    print(ans)


Measured memory_bytes: 16712
#include <stdio.h>
#include<math.h>

int main() {
	int a, b, num,digit=0,sum;
	scanf("%d %d", &a, &b);
	num = b;
	while (num != 0) {
		num /= 10;
		digit++;
	}

	sum = a*pow(10,digit) + b;
	if (sum%(int)sqrt(sum) == 0)printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    String S = sc.next();
    sc.close();

    String ans = K < S.length() ?  S.substring(0, K) + "..." : S;
    System.out.println(ans);
  }
}


Measured memory_bytes: 38716
#include<stdio.h>

int main(void)
{
int i,j,n,max,min,t,ii,a,k;
int num[8];
int tem[8];

scanf("%d",&n);
for(k=0;k<n;k++){

max=0;
min=0;
ii=1;

scanf("%d",&a);
for(i=0;i<8;i++){
num[i]=a%10;
a/=10;
}

for(i=0;i<8;i++){
tem[i]=num[i];
}
for(i=0;i<8;i++){
for(j=0;j<7;j++){
if(tem[j]>tem[j+1]){
t=tem[j];
tem[j]=tem[j+1];
tem[j+1]=t;
}
if(num[j]<num[j+1]){
t=num[j];
num[j]=num[j+1];
num[j+1]=t;
}
}
}

for(i=0;i<8;i++){
max+=tem[i]*ii;
min+=num[i]*ii;
ii*=10;
}

printf("%d\n",max-min);
}

return 0;
}

Measured memory_bytes: 600
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>

using namespace std;

string A, B;



int main() {

	char a, b;
	cin >> a >> b;

	for (int i = 0; i < b - '0'; i++) {
		A += a;
	}

	for (int i = 0; i < a - '0'; i++) {
		B += b;
	}

	if (A <= B) cout << A << endl;
	else cout << B << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	stack<int> ans;

	int now=n;
	while(now!=0)
	{
		if(now-k<0)k=now;
		bool isgoal=false;
		for(int i=k;i>=1;i--)
		{
			//cout<<s[now-i]<<endl;
			if(s[now-i]=='0')
			{
				now-=i;
				ans.push(i);
				//cout<<i<<endl;
				isgoal=true;
				break;
			}
		}
		//cout<<now<<endl;
		if(!isgoal)
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	while(!ans.empty())
	{
		cout<<ans.top()<<endl;
		ans.pop();
	}
	return 0;
}

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

#define INF 1000000000000000

using namespace std;

typedef long long ll;


int main() {

    ll N;
    cin >> N;
    ll m = INF;
    ll a;
    for (int i=0; i<5; i++) {
        cin >> a;
        m = min(m, a);
    }
    ll res = (N / m) + 4;
    if (N % m != 0) res += 1;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
H = list(map(int,input().split()))
L = [1 for _ in range(N)]
for _ in range(M):
    A, B = map(int,input().split())
    if H[A-1] > H[B-1]:
        L[B-1] = 0
    elif H[A-1] < H[B-1]:
        L[A-1] = 0
    else:
        L[A-1] = 0
        L[B-1] = 0
print(sum(L))

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

int main(){
    int n, a;
    cin >> n;

    int two = 0, four = 0, odd = 0;
    
    for(int i = 0; i < n; i++){
        cin >> a;

        if(a%4 == 0)        four++;
        else if(a%2 == 0)   two++;
        else                odd++;
    }

    if(odd == 0 || four >= odd || (four+1 == odd && two == 0)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int main(){
    ll x;
    cin >> x;
    double rate = 1.01;
    ll base = 100;
    ll ans=0;
    while(floor(base*rate)<x){
        base *= rate;
        ++ans;
    }
    cout << ans+1 << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  int a, b;
  cin >> a >> b;
  cout << a*b << endl;
  return 0;
}

Measured memory_bytes: 3652
n,k=map(int,input().split())
s=input()
t=s[::-1]
u="".join([s,t])
ls=[]
for i in range(n):
  ls.append(u[i:i+n])
ls.sort()
k-=1
x=ls[0]
cnt=1
for i in range(1,n):
  if x[0]==x[i]:
    cnt+=1
  else:
    break
if cnt*2**k<n:
  y=n-cnt*2**k
  print(x[0]*(cnt*2**k)+x[cnt:y+cnt])
else:
  print(x[0]*n)


Measured memory_bytes: 380296
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final long MOD = (long)1e9 + 7;

        Scanner sc = new Scanner(System.in);
        int r1 = sc.nextInt();
        int c1 = sc.nextInt();
        int r2 = sc.nextInt();
        int c2 = sc.nextInt();

        int sumMax = r2+c2+1;
        long[] frac = new long[sumMax+1];
        long[] frac_inv = new long[sumMax+1];

        frac[0] = 1;
        frac_inv[0] = 1;

        for(int i = 1 ; i <= sumMax ; i++){
            frac[i] = (frac[i-1]*i) % MOD;
            frac_inv[i] = modinv(frac[i], MOD);
        }

        long ans = 0;
        for(int i = r1 ; i <= r2 ; i++){
            long tmp1 = 0;
            long tmp2 = 0;
            tmp1 = (frac[i + c2 + 1] * frac_inv[c2]) % MOD;
            tmp2 = (frac[i+c1] * frac_inv[c1-1]) % MOD;
            long tmp = (tmp1 - tmp2 + MOD) % MOD;
            tmp = (tmp * frac_inv[i+1]) % MOD;

            ans = (ans + tmp) % MOD;
        }

        System.out.println(ans);
    }

    // a^n mod を計算する
    static long modpow(long a, long n, long mod) {
        long res = 1;
        while (n > 0) {
            if ((n & 1) == 1){
                res = (res * a) % mod;
            }
            a = (a * a) % mod;
            n >>= 1;
        }
        return res;
    }

    // a^{-1} mod を計算する
    static long modinv(long a, long mod) {
        return modpow(a, mod - 2, mod);
    }
}

Measured memory_bytes: 54100
#include <bits/stdc++.h>

using namespace std;

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int a, b, c;
    cin >> a >> b >> c;

    if(a + b + c >= 22) cout << "bust\n";
    else cout << "win\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MN = 2e5+2;
int main () {
	ll n;
	scanf ("%lld",&n);
	if (n&1) printf ("0\n");
	else {
		ll ret = 0;
		for (ll i = 10; i <= n; i *= 5) ret += n/i;
		printf ("%lld\n",ret);
	}
	return 0;
}


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

int main(){
	int N;
	string S, T;
	cin >> N;
	cin >> S >> T;
	string str = "";
	for(int i = 0; i < N; i++){
		str += S[i];
		str += T[i];
	}
	cout << str;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 200005;

struct disj{
	int pa[MAXN];
	void init(int n){
		iota(pa, pa + n + 1, 0);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p); q = find(q);
		if(p == q)return 0;
		pa[q] = p; return 1;
	}
}disj;

int n;
vector<int> gph[MAXN];
vector<pi> edg;
int par[18][MAXN], prec[MAXN], dep[MAXN];

int lca(int s, int e){
	if(dep[s] > dep[e]) swap(s, e);
	int dx = dep[e] - dep[s];
	for(int i=0; i<18; i++){
		if((dx >> i) & 1) e = par[i][e];
	}
	for(int i=17; i>=0; i--){
		if(par[i][s] != par[i][e]){
			s = par[i][s];
			e = par[i][e];
		}
	}
	if(s != e) return par[0][s];
	return s;
}

void dfs(int x, int p){
	for(auto &i : gph[x]){
		if(i != p){
			dep[i] = dep[x] + 1;
			par[0][i] = x;
			prec[i] = prec[x] ^ (i > n ? (i-n) : i);
			dfs(i, x);
		}
	}
}
void add_edge(int s, int e){
	assert(1 <= s && s <= 2 * n);
	assert(1 <= e && e <= 2 * n);
	assert(disj.uni(s, e));
	edg.emplace_back(s, e);
	gph[s].push_back(e);
	gph[e].push_back(s);
}

int main(){
	cin >> n;
	if((n & -n) == n){
		puts("No");
		return 0;
	}
	if(n == 3){
		puts("Yes");
		for(int i=2; i<=n+n; i++) printf("%d %d\n", i-1, i);
		return 0;
	}
	disj.init(n + n);
	int N = (n - 1) / 4;
	for(int i=1; i<=4*N-1; i++){
		if(i != 4 * N - 1){
			add_edge(i, i + 1);
			add_edge(i + n, i + n + 1);
		}
		else{
			add_edge(4 * N - 1, n + 1);
		}
	}
	if(4 * N + 1 <= n){
		add_edge(4 * N + 1, 1);
		add_edge(4 * N, 4 * N + 1);

		add_edge(1, 4 * N + n);
		add_edge(4 * N + n, 4 * N + 1 + n);
	}
	if(4 * N + 2 <= n){
		add_edge(4 * N + 1, 4 * N + 2);
		add_edge(2, 4 * N + 2 + n);
	}
	if(4 * N + 3 <= n){
		add_edge(4 * N + 3, 4 * N + n);
		add_edge(2, 4 * N + 3 + n);
	}
	if(4 * N + 4 <= n){
		add_edge(4 * N + 4 + n, 4 * N + n);
		int w = (4 * N) ^ 1 ^ 2 ^ 3 ^ (4 * N + 4);
		add_edge(w, 4 * N + 4);
	}
	assert(edg.size() == n+n - 1);
	prec[1] = 1;
	dfs(1, 0);
	for(int i=1; i<18; i++){
		for(int j=1; j<=2*n; j++){
			par[i][j] = par[i-1][par[i-1][j]];
		}
	}
	for(int i=1; i<=n; i++){
		int l = lca(i, i + n);
		int ans = prec[i] ^ prec[i + n] ^ (l > n ? (l-n) : l);
		assert(ans == i);
	}
	puts("Yes");
	for(auto &i : edg) printf("%d %d\n", i.first, i.second);
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  ll A = nextLong();
  ll B = nextLong();
  ll K = nextLong();

  ll k1 = min(A, K);
  A -= k1;
  K -= k1;
  ll k2 = min(B, K);
  B -= k2;
  K -= k2;
  cout << A << " " << B << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define inlien inline
#define retrun return
#define cpnst const
typedef long long ll;
inline ll qpow(ll x,ll y,ll m)
{ll r=1;for(;y;y>>=1,(x*=x)%=m)if(y&1)(r*=x)%=m;return r;}
ll mod;
int n;
ll C[3333][3333],S2[3333][3333],R[3333];
int main()
{
	scanf("%d%lld",&n,&mod);
	register int i,ii;
	for(i=0;i<=n;i++)C[i][i]=S2[i][0]=C[i][0]=1;
	for(i=1;i<=n;i++)
		for(ii=1;ii<i;ii++)
			C[i][ii]=(C[i-1][ii]+C[i-1][ii-1])%mod;
	for(i=1;i<=n;i++)
		for(ii=1;ii<=i;ii++)
			S2[i][ii]=(S2[i-1][ii-1]+(ii+1)*S2[i-1][ii])%mod;
	ll w,wi;
	for(i=0;i<=n;i++)
		for(ii=0,w=qpow(2,n-i,mod),wi=1;ii<=i;ii++,(wi*=w)%=mod)
			(R[i]+=S2[i][ii]*wi)%=mod;
	ll ans=0;
	for(i=0;i<=n;i++)
	{
		ll k=qpow(2,qpow(2,n-i,mod-1),mod);
		(ans+=(((i&1)?-1:1)*k*R[i])%mod*C[n][i])%=mod;
	}printf("%lld\n",(ans+mod)%mod);
}
/*
Giving the world a better yourself is giving yourself a better world. 
*/

Measured memory_bytes: 158336
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
using namespace std;

int main(){
	int x;
	cin >> x;
	if (x == 1) {
		x = x - 1;
	}
	else {
		x = x + 1;
	}
	cout << x;
	return 0;

}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b && b == c) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

ll dp[100][3000];

int main()
{
	int n, a;
	scanf("%d%d", &n, &a);
	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		ll x;
		scanf("%lld", &x);
		for (int j = i; j > 0; --j)
			for (int k = a*n; k >= x; --k)
				dp[j][k] += dp[j-1][k-x];
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i)
		ans += dp[i][i*a];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1408
N, M = input().split()
A = list(map(int, input().split()))

arr_sum = sum(A)
A.sort(reverse=True)

min = arr_sum * (1 / (4 * int(M)))

for x in A[:int(M)]:
    if x < min:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    int a, b;
    int n; scanf("%d", &n);

    a = 0, b = 0;

    while(n--) {
        int res;
        char s1[101];
        char s2[101];
        scanf(" %s", s1);
        scanf(" %s", s2);

        res = strcmp(s1, s2);
        if(res > 0) a += 3;
        else if(res < 0) b += 3;
        else a++, b++;
    }

    printf("%d %d\n", a, b);

    return EXIT_SUCCESS;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, a;
    cin >> n;
    map<int, int> mp;
    for(int i=0;i<n;++i) {
        cin >> a;
        if(mp[a] == 1) {
            cout << "NO" << endl;
            return 0;
        }
        mp[a] = 1;
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
using Tree = vector<pair<int, int>>;

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    if (a == b && a == c)
    {
        if (a % 2 == 0)
            cout << -1 << endl;
        else
            cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0)
    {
        int _a = a, _b = b, _c = c;
        a = _b / 2 + _c / 2;
        b = _a / 2 + _c / 2;
        c = _a / 2 + _b / 2;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    ll a, b, c, d, e, f, g, h;
    cin >> a >> b >> c >> d >> e >> f >> g >> h;
    ll as = a + b + c + d, bs = e + f + g + h;
    cout << max(as, bs) << endl;
}


Measured memory_bytes: 3096
def main():
    kx = input().split()
    # print(kx)
    k, x = int(kx[0]), int(kx[1])
    l = max(-1000000, x-(k-1))
    r = min(1000000, x+(k-1))
    output = []
    for i in range(l, r+1):
        output.append(i)
    return output


if __name__ == '__main__':
    output = main()
    print(' '.join(map(str, output)))

Measured memory_bytes: 3188
W, B = gets.split.map(&:to_i)

if W < B
  fill_color = '.'
  w_cnt = 1
  b_cnt = 0
else
  fill_color = '#'
  w_cnt = 0
  b_cnt = 1
end

FIELD = Array.new(100) { Array.new(100, fill_color) }

TEMPLATE_W = [
  ['.', '.', '.'],
  ['.', '#', '.'],
  ['.', '.', '.']
]

TEMPLATE_WALL = [
  ['.', '.', '.'],
  ['.', '.', '.'],
  ['.', '.', '.']
]

TEMPLATE_B = [
  ['#', '#', '#'],
  ['#', '.', '#'],
  ['#', '#', '#']
]

TEMPLATE_BA = [
  ['#', '#', '#'],
  ['#', '#', '#'],
  ['#', '#', '#']
]

def fill_color(y, x, template)
  3.times do |i|
    3.times do |j|
      ny = y + i
      nx = x + j

      FIELD[ny][nx] = template[i][j]
    end
  end
end

25.times do |y|
  25.times do |x|
    next if w_cnt == W && b_cnt == B

    cy = 4 * y
    cx = 4 * x

    if W < B
      if w_cnt < W
        fill_color(cy, cx, TEMPLATE_B)
        w_cnt += 1
        b_cnt += 1
      else
        fill_color(cy, cx, TEMPLATE_BA)
        b_cnt += 1
      end
    else
      if b_cnt < B
        fill_color(cy, cx, TEMPLATE_W)
        w_cnt += 1
        b_cnt += 1
      else
        fill_color(cy, cx, TEMPLATE_WALL)
        w_cnt += 1
      end
    end
  end
end

puts FIELD.size
puts FIELD[0].size
puts FIELD.map(&:join)


Measured memory_bytes: 3964
#include <bits/stdc++.h>
#define int long long int
#define ld long double
#define pb push_back
#define pf push_front
#define ft first
#define sc second
#define all(v) v.begin(), v.end()
using namespace std;
const int maxn = 3010, mod = 998244353;
signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    vector<int> ans(n + 1, 0);
    for (int d = 0; d < n - 1; d++) {
        int c;
        cin >> c;
        ans[c]++;
    }
    for (int d = 1; d <= n; d++) {
        cout << ans[d] << "\n";
    }
}


Measured memory_bytes: 4784
import std.stdio, std.conv, std.string, std.algorithm;

void main() {
	int H, W;
	int [][10] c;
	auto t = readln().chomp().split().to!(int[])();
	H = t[0]; W = t[1];
	foreach(int i; 0..10) {
		c[i] = readln().chomp().split().to!(int[])();
	}
	foreach(int i; 0..10) {
		foreach(int j; 0..10) {
			foreach(int k; 0..10) {
				c[j][k] = min(c[j][k], c[j][i]+c[i][k]);
			}
		}
	}

	long res = 0;
	foreach(int i; 0..H) {
		t = readln().chomp().split().to!(int[])();
		foreach(int j; 0..W) {
			if(t[j] >= 0) {
				res += c[t[j]][1];
			}
		}
	}
	writeln(res);
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define all(v) v.begin(), v.end()
#define rip return
#define fo(i,a,b) for(int i = a ; a < b ? i <= b : i >= b ; i += (a < b ? 1 : -1))

#define F first
#define S second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;

const int mod = 1e9 + 7;
// const int mod = 998244353;
const ll inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-7;

const int N = 1e5 + 5;

ll fact[N], inv[N], a[N];
ll binpow (ll a, ll b) {
	ll res = 1;
	for (; b ; (a *= a) %= mod, b >>= 1) {
		if (b & 1) (res *= a) %= mod;
	}
	rip res;
}

ll C (ll n, ll k) {
	if (k < 0 || k > n) rip 0;
	ll cur = (((fact[n] * inv[k]) % mod) * inv[n - k]) % mod;
	// cout << "C(" << n << ", " << k << ") = " << cur << "\n";
	return cur;
}

void solve () {
	fact[0] = 1;
	fo (i, 1, N - 1) {
		fact[i] = fact[i - 1] * i % mod;
		inv[i] = binpow (fact[i], mod - 2);
	}
	inv[0] = 1;
	int n, k;
	cin >> n >> k;
	fo (i, 1, n) {
		cin >> a[i];
	}
	sort (a + 1, a + 1 + n);
	ll res = 0;
	fo (i, 1, n) {
		ll cur = a[i] * C (i - 1, k - 1);
		res += cur;
		res %= mod;
	}
	fo (i, n, 1) {
		ll cur = a[i] * C (n - i, k - 1);
		res -= cur;
		(res += mod) %= mod;
	}
	cout << res;
}

int main () {
	ios;
	// cout << fixed << setprecision (10);
	int tt = 1;
	// cin >> tt;
	while (tt-- || 0) {
		solve();
		// cout << "\n";
	}
}




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

char maze[101][101];
int main(){
    int h,w;
    cin >> h >> w;
    rep(i,h) rep(j,w){
        cin >> maze[i][j];
    }
    for (int i = 0;i < h;i++){
        bool f = true;
        for (int j = 0; j < w;j++){
            if (maze[i][j] != '.') f = false;
        }
        if (f){
            for (int j = 0; j < w;j++){
                maze[i][j] = '+';
            }
        }
    }
    for (int j = 0;j < w;j++){
        bool f = true;
        for (int i = 0;i < h;i++){
            if (maze[i][j] != '.' && maze[i][j] != '+') f = false;
        }
        if (f){
            for (int i = 0;i < h;i++){
                maze[i][j] = '+';
            }
        }
    }
    for (int i = 0;i < h;i++){
        bool f = true;
        int cnt = 0;
        for (int j = 0; j < w;j++){
            if (maze[i][j] != '+'){
                cout << maze[i][j];
            }
            else cnt++;
            if (cnt == w) f = false;
        }
        if (f) {
            cout << endl;
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 256
//???????????????
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;


int main()
{
	for (;;)
	{
		int n, m, h, k;
		int s[1234];
		int val[1234];
		vector<pair<int, int>>hor;
		vector<pair<int, int>>pick;
		int inv[1234];
		scanf("%d %d %d %d", &n, &m, &h, &k);
		if (n == 0 && m == 0 && h == 0 && k == 0)break;
		for (int i = 0; i < n; ++i)
		{
			scanf("%d", s + i);
			val[i] = i;
		}
		for (int j = 0; j < m; ++j)
		{
			int a, b;
			scanf("%d %d", &a, &b);
			hor.push_back(make_pair(a - 1, b));
		}
		sort(hor.begin(), hor.end(), [](const pair<int, int>&p1, const pair<int, int>&p2) {if (p1.second == p2.second)return p1.first < p2.first; return (p1.second < p2.second); });
		for (auto& swp : hor)
		{
			pick.push_back(make_pair(val[swp.first], val[swp.first + 1]));
			swap(val[swp.first], val[swp.first + 1]);
		}
		int ans = 0;
		for (int i = 0; i < n; ++i)
		{
			if (val[i] < k)ans += s[i];
			inv[val[i]] = i;
		}
		int diff = 0;
		for (auto& pk : pick)
		{
			if (pk.first < k && pk.second >= k)
			{
				diff = max(diff, -s[inv[pk.second]] + s[inv[pk.first]]);
			}
			else if (pk.first >= k && pk.second < k)
			{
				diff = max(diff, +s[inv[pk.second]] - s[inv[pk.first]]);
			}
		}
		printf("%d\n", ans - diff);
	}
	return 0;
}

Measured memory_bytes: 4804
N=int(input())
#5
A=sorted(map(int,input().split()))
#24 11 8 3 16

dp = [1]*max(A)
l = len(dp)

for a in A:
	if dp[a-1] == 1:
		dp[a-1] = 2
		for i in range(2*a, l+1, a):
			dp[i-1] = 0
	elif dp[a-1] == 2:
		dp[a-1] = 0

print(sum([1 for a in A if dp[a-1] != 0]))



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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	int ans = 0;
	FOR(i,0,n){
		int a;
		cin >> a;
		ans += a-1;
	}
	ANS(ans);
	return 0;
}


Measured memory_bytes: 256
/*input
5
1 2 3 4 5
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double

typedef pair<int,int> pi;

typedef vector<int> vi;
typedef vector<pi> vpi;

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define gcd __gcd

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

map< pair<int,int> , int > vis;

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int x = 0;
  int y = 0;
  int n,i,j,k;
  cin >> n;
  for(i = 0;i < n;i++){
    cin >> j;
    if(j%2)y++;
  }
  if(!(y%2))cout << "YES"; 
  else cout << "NO";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

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

	if (N < 100)
		cout << N*pow(100, D) << endl;
	else if (N == 100)
	{
		if (D == 0)
			cout << 101 << endl;
		else if (D == 1)
			cout << 10100 << endl;
		else
			cout << 1010000 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);


signed main(){

    int N; cin >> N;
    vec A(N); readvec(A);

    int s = 0;
    REP(i, N) s += A[i];
    
    #define N_bit 2000001
    bitset<N_bit> dp(1);
    REP(i, N) dp = dp | (dp << A[i]);

    IREP(i, s / 2 + 1){
        if(dp[i] == 1){
            cout<< s - i;
            break;
        } 
    }
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    if (N == 1) {
        cout << "Hello World" << endl;
    }
    else {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

fn map_sum(map: &HashMap<usize, usize>) -> usize {
    let mut sum = 0;
    
    for (k, v) in map.iter() {
        sum += k * v
    }
    
    sum
}


#[fastout]
fn main() {
    input!{
        n: usize,
        a_vec: [usize; n],
        q: usize,
        bc_vec: [(usize, usize); q],
    }

    let mut map: HashMap<usize, usize> = HashMap::new();
    
    for a in a_vec.iter() {
        *map.entry(*a).or_insert(0) += 1;
    }
    let mut sum = map_sum(&map);
    for query in bc_vec.iter() {
        match &map.get(&query.0) {
            Some(x) => {
                *map.entry(query.1).or_insert(0) += **x;
                let b_num = map.get(&query.0).unwrap();
                sum = sum - b_num * query.0 + b_num * query.1;
                *map.get_mut(&query.0).unwrap() = 0;
                println!("{}", sum)
            },
            None => println!("{}", sum),
        }
        // dbg!(&map);
        
    }

    println!("", );
}


Measured memory_bytes: 9616
#include <stdio.h>
#define N 100000

int A1[N];
char A2[N];
int input1[N];
char input2[N];

void swap1(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void swap2(char* a, char* b){
  char tmp = *a;
  *a = *b;
  *b = tmp;
}

int partition(int p, int r){
  int x = A1[r];
  int i = p - 1, j;
  for(j=p;j<r;j++){
    if(A1[j] <= x){
      i++;
      swap1(&A1[i], &A1[j]);
      swap2(&A2[i], &A2[j]);
    }
  }
  swap1(&A1[i+1], &A1[r]);
  swap2(&A2[i+1], &A2[r]);
  return i+1;
}

void quic_sort(int p, int r){
  if(p < r){
    int q = partition(p, r);
    quic_sort(p, q-1);
    quic_sort(q+1, r);
  }
}

int check(int n){
  int i, j;
  for(i=1;i<n;i++){
    if(A1[i-1] == A1[i]){
      int a, b;
      for(j=0;j<n;j++){
        if(A1[i-1] == input1[j] && A2[i-1] == input2[j]) a = j;
        if(A1[i] == input1[j] && A2[i] == input2[j]) b = j;
      }
      if(a > b) return 0;
    }
  }
  return 1;
}

main(){
  int n, i;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    getchar();
    scanf("%c%d", &A2[i], &A1[i]);
  }
  for(i=0;i<n;i++){
    input1[i] = A1[i];
    input2[i] = A2[i];
  }
  quic_sort(0, n-1);
  printf("%s\n", (check(n) ? "Stable" : "Not stable"));
  for(i=0;i<n;i++) printf("%c %d\n", A2[i], A1[i]);
  return 0;
}

Measured memory_bytes: 1404
#include<bits/stdc++.h>
#define ll long long int
#define ar array
#define pb push_back
#define input(arr,n) for(int i = 0; i<n; i++) cin>>arr[i]
const int mod = 1e9+7;
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,ans = 0;
	cin>>n;
	for(int i = 1; i<n; i++)
	{
		int h = n-i;
		for(int j = 1; j*j<=h; j++)
			if(h%j==0)
			{
				ans++;
				if(j*j!=h) ans++;
			}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 3600
N,M = map(int,input().split())
Ai = list(map(int,input().split()))
Ai.sort(reverse=True)
soutokuhyou = sum(Ai[:])
seigen = soutokuhyou / (4*M)
if Ai[M-1] < seigen:
    print("No")
else:
    print("Yes")



Measured memory_bytes: 2940