akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n)  for(int i=0; i<(int) (n); i++)


const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];


int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	return lower_bound(all(vec), xx) - vec.begin();
}
template<typename T>
void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>
void vecin(vector<TT>& vec) {
	for (int i = 0; i < vec.size(); i++) {
		cin >> vec[i];
	}
}


// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
//グループが0個でもいいときはnにxを足す
// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx <= 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}




signed main() {
	COMinit();
	int n, k,ans=0;
	cin >> n >> k;
	vector<int>vec(n);
	vecin(vec);
	sort(all(vec));
	rep(i, n) {
		ans += COM(i, k - 1) * vec[i];
		ans -= COM((n - i - 1), k - 1) * vec[i];
		ans %= mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 15920
#include <stdio.h>

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

for(int i=0;i<m;++i){
    scanf("%d",&a);    
    n = n-a;
    } 
if (n<0)
   printf("-1");
   
else
    printf("%d", n); 
 
    return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <utility>
#include <limits.h>
#include <algorithm>
using namespace std;

int N,K;
int main(){
	cin >> N >> K;
	vector<int> X(N,0),Y(N,0);
	vector<int> x,y;
	for(int i=0;i<N;i++){
		cin >> X[i] >> Y[i];
		x.push_back(X[i]);
		y.push_back(Y[i]);
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	long long ans = 1LL*(x[N-1]-x[0])*(y[N-1]-y[0]);
	for(int xi=0;xi<N;xi++){
		for(int xj=xi+1;xj<N;xj++){
			for(int yi=0;yi<N;yi++){
				for(int yj=yi+1;yj<N;yj++){
					int num = 0;
					long long lx = x[xi],rx = x[xj];
					long long by = y[yi],uy = y[yj];
					for(int i=0;i<N;i++){
						if(lx<=X[i] && X[i]<=rx && by<=Y[i] && Y[i]<=uy) num++;
					}
					if(num>=K) ans = min(ans,1LL*(rx-lx)*(uy-by));
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using  namespace std;
typedef long long ll;
 
const int MAXN = 100000;
ll x[MAXN+2], v[MAXN+2], sum[MAXN+2];
 
int main() {
  int n;
  ll c;
  cin >> n >> c;
  rep(i, n) {
    cin >> x[i+1] >> v[i+1];
  	sum[i+1] = sum[i] + v[i+1];
  }
  ll lmax[n+2], rmax[n+2];
  lmax[0] = rmax[n+1] = 0;
  rep(i, n) {
    lmax[i+1] = max(lmax[i], sum[i+1] - x[i+1]);
    rmax[n-i] = max(rmax[n-i+1], (sum[n]-sum[n-i-1]) - (c-x[n-i]));
  }
  ll ans = 0;
  rep(i, n) {
    ans = max(ans, sum[i+1]-2*x[i+1]+rmax[i+2]);
    ans = max(ans, (sum[n]-sum[n-i-1]) - 2*(c-x[n-i]) + lmax[n-i-1]);
  }
  ans = max(ans, max(lmax[n], rmax[1]));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4096
// problem: "https://atcoder.jp/contests/abc157/tasks/abc157_c"

#include<bits/stdc++.h>

using namespace std;

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


    int i,l;
    char c;
    string s;

    if(n==1)
        s = " ";
    else if(n==2)
        s = "  ";
    else
        s = "   ";

    for(i=0;i!=m;i++)
    {
        cin>>l>>c;

        if(s[l-1] != ' ' && s[l-1] != c)
        {
            cout<<-1;
            exit(0);
        }

        s[l-1] = c;
    }

    for(i=0;i!=n;i++)
    {
        if(!i)
        {
            if(s[i] == ' ' && n > 1)
                s[i] = '1';
            else if(s[i] == ' ' && n == 1)
                s[i] = '0';
        }
        else
        {
            if(s[i] == ' ')
                s[i] = '0';
        }
    }

    if(s[0] == '0' && n > 1)
    {
        cout<<-1;
        exit(0);
    }

    cout<<stoi(s);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;



int main(){
   ll n;
   cin >> n;
   string ans="";
   string alp="abcdefghijklmnopqrstuvwxyz";
   while(n>0){
       --n;
       ans = alp[n%26] + ans;
       n /= 26;
   }
   
   cout << ans << endl;

}


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

using ll=long long;

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

	for(int n,q;cin>>n>>q && n|q;){
		vector<ll> qs(1,n);
		for(int i=0;i<q;i++){
			ll x; cin>>x;
			while(qs.size() && qs.back()>=x)
				qs.pop_back();
			qs.push_back(x);
		}
		vector<ll> cs(qs.size());
		cs.back()=1;
		vector<ll> res(n+1);
		for(int i=qs.size();i--;){
			for(;;){
				int j=upper_bound(begin(qs),begin(qs)+i,qs[i])-begin(qs)-1;
				if(j<0) break;
				cs[j]+=qs[i]/qs[j]*cs[i];
				qs[i]%=qs[j];
			}
			res[0]+=cs[i];
			res[qs[i]]-=cs[i];
		}
		for(int i=0;i<n;i++){
			cout<<res[i]<<endl;
			res[i+1]+=res[i];
		}
	}
}


Measured memory_bytes: 4212
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 200000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
struct Edge{
    int to;
    int next;
}edge[N];
int n,m;
int tot,head[N];
void addEdge(int from,int to){
    edge[++tot].to=to;
    edge[tot].next=head[from];
    head[from]=tot;
}
bool dfs(int s,int step){
    if(s==n&&step==2)
        return true;
    for(int i=head[s];i!=-1;i=edge[i].next){
        int to=edge[i].to;
        if(dfs(to,step+1))
            return true;
    }
    return false;
}
int main() {
    memset(head,-1,sizeof(head));
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        addEdge(x,y);
    }

    bool flag=dfs(1,0);
    if(flag)
        printf("POSSIBLE\n");
    else
        printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0; char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return x;
}
int main(void)
{
	long n = read();
    long ans = n;
	for (long i = 1; i < n; ++i)
	{
        long u = read(), v = read();
		if (u > v) swap(u, v);
        ans += i * n - i * i + i - u * n + u * v - u;
	}
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define orep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> VI;

int main() {
  int K;
  cin >> K;
  ll sum = 0;
  orep(i, K) {
    orep(j, K) {
      orep(k, K) { sum += gcd(gcd(i, j), k); }
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        var key = new Scanner(System.in);
        var n = key.nextInt();
        if (n % 1000 == 0) {
            System.out.println(0);
        } else {
            System.out.println(1000-n%1000);
        }
    }
}


Measured memory_bytes: 35892
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>


using namespace std;




int main(){

  int n,k;
  cin>>n>>k;
  int ans = 1, cnt = 0;
  while(n >= ans){
    ans=ans*k;
    cnt++;
  }
  cout<<cnt;
    



}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

int main()
{


	ll n;
	cin >> n;
	ll arr[n];
	for (ll i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	ll dp[n][n];
	for (int L = n - 1ll; L >= 0ll; L--)
	{
		for (int R = L; R < n; R++)
		{
			if (L == R)
			{
				dp[L][R] = arr[L];
			}
			else
			{
				dp[L][R] = max(arr[L] - dp[L + 1][R] , arr[R] - dp[L][R - 1]);
			}
		}
	}

	cout << dp[0][n - 1];
}

Measured memory_bytes: 46464
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (ll)(1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll dp[3][300][300],cop[3][300][300];
vector<P> v[300];
int main() {
	rep(j, 3) {
		dp[j][0][0] = 1;
	}
	int n, m; cin >> n >> m;
	rep(i, m) {
		int le, ri, x; cin >> le >> ri >> x; ri--;
		v[ri].push_back({ le,x });
	}
	rep(i, n) {
		rep(k, i + 1) {
			rep(l, i + 1) {
				rep(j, 3) {
					cop[j][k][l] = 0;
				}
			}
		}
		rep(k, i + 1) {
			rep(l, i + 1) {
				rep(j, 3) {
					(cop[j][k][l] += dp[j][k][l])%=mod;
				}
				(cop[0][i][l] += dp[1][k][l]) %= mod;
				(cop[0][k][i] += dp[2][k][l]) %= mod;
				(cop[1][i][l] += dp[0][k][l])%=mod;
				(cop[1][k][i] += dp[2][k][l])%=mod;
				(cop[2][i][l] += dp[0][k][l])%=mod;
				(cop[2][k][i] += dp[1][k][l]) %= mod;
			}
		}
		rep(j, (int)v[i].size()) {
			int le = v[i][j].first; int c = v[i][j].second;
			rep(k, i + 1) {
				rep(l, i + 1) {
					rep(m, 3) {
						if (c == 1) {
							if (k >= le || l >= le)cop[m][k][l] = 0;
						}
						if (c == 2) {
							if ((k >= le && l >= le) || (k < le&&l < le))cop[m][k][l] = 0;
						}
						if (c == 3) {
							if (k < le || l < le)cop[m][k][l] = 0;
						}
					}
				}
			}
		}
		rep(k, i + 1) {
			rep(l, i + 1) {
				rep(j, 3) {
					dp[j][k][l] = cop[j][k][l];
				}
			}
		}
	}
	ll out = 0;
	rep(j, 3) {
		rep(k, n) {
			rep(l, n) {
				(out += dp[j][k][l]) %= mod;
				//cout << j << " " << k << " " << l << " " << dp[n][j][k][l] << endl;
			}
		}
	}
	out = out * ((mod+1) / 3) % mod;
	cout << out << endl;
	return 0;
}


Measured memory_bytes: 4480
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <functional>
#include <chrono>
#include <time.h>
using namespace std;

struct Trie {
	Trie *next[27];
	int cnt[28];

	Trie() {
		fill(next, next + 27, (Trie *)0);
		fill(cnt, cnt + 28, 0);
	}

	void insert(const char *s) {
		if (*s == '\0') {
			cnt[27]++;
			return;
		}
		if (this->next[*s-'a'] == NULL)
			this->next[*s-'a'] = new Trie();
		cnt[*s - 'a']++;
		this->next[*s- 'a']->insert(s + 1);
	}

	bool find(const char *s) {
		if (*s == '\0') return true;
		if (this->next[*s-'a'] == NULL)
			return false;
		return this->next[*s-'a']->find(s + 1);
	}
};

pair<int, int> solve(Trie* trie, const char *t) {
	if (*t == '\0') {
		return make_pair(trie->cnt[27], 0);
	}

	int n = *t - 'a';
	vector<int> res;
	int cnt = 0;
	pair<int, int>pcnt = make_pair(0, 0);
	vector<int>next;
	for (int i = 0; i < 26; i++) {
		if (i < n)cnt += trie->cnt[i];
		else if (i == n) {
			if (trie->cnt[i]) {
				pair<int,int> pi = solve(trie->next[i], t + 1);
				pcnt.first += pi.first;
				pcnt.second += pi.second;
			}
		}
		else break;
	}
	cnt += trie->cnt[27];

	if (trie->cnt[26]) {
		if (n == 0) {
			pair<int, int> pi = solve(trie->next[26], t + 1);
			pcnt.first += pi.first;
			pcnt.second += 0;
		}
		else if (n == 25) {
			pair<int, int> pi = solve(trie->next[26], t + 1);
			pcnt.first += trie->cnt[26];
			pcnt.second += pi.second;
		}
		else {
			pcnt.first += trie->cnt[26];
		}
	}

	return make_pair(cnt + pcnt.first, cnt + pcnt.second);
}

int main()
{
	int n; cin >> n;
	Trie* trie = new Trie();

	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		for (int j = 0; j < s.size(); j++)if (s[j] == '?')s[j] = 'a' + 26;
		trie->insert(s.data());
	}

	string T; cin >> T;
	//trie->insert(T.data());

	pair<int, int>ans = solve(trie, T.data());

	bool first = true;
	for (int i = ans.second; i <= ans.first; i++) {
		if (first==false)cout << " ";
		cout << i + 1;
		first = false;
	}
	cout << endl;

    return 0;
}



Measured memory_bytes: 25472
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  string s;
  cin>>s; 
  bool a=true;
  for(int i=0; i<s.size()/2;i++){
    if(s.at(i)!=s.at(s.size()-i-1)){
      a=false;
      break;
    }
  }
  if(a){
  for(int i=0; i<s.size()/4;i++){
    if(s.at(i)!=s.at(s.size()/2-i-1)){
      a=false;
      break;
    }
  }
  }
  if(a){   
  cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}



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

int main(void){

int n;
int l;
int sum=0;
int ans;
int i;
int tmp;
scanf("%d%d",&n,&l);


int a[n];
for(i=0;i<n;i++){
  a[i]=l+i;//a[i]=l+i-1でlは一からだから、。
  sum=sum+a[i];
}

if(a[n-1]<0){
  ans=n-1;
}
else if(a[0]<=0&&a[n-1]>=0){
  for(i=0;i<n;i++){
    if(a[i]==0)
    ans=i;
  }
}
  /*tmp=-a[0];
  if(tmp>a[n-1]){
    ans=a[n-1];
  }
  else if(tmp<a[n-1])
  ans=a[0];
  else{
    for(i=0;i<n;i++){
      if(a[i]==0)
      ans=i;
  }
}*/
else if(a[0]>0){
  ans=0;
}

sum=sum-a[ans];
printf("%d",sum);





return 0;

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000

int main(){
  int n,x;
  int min_m=INF,sum=0;
  cin>>n>>x;
  for(int i=0;i<n;i++){
    int m;
    cin>>m;
    sum+=m;
    min_m=min(min_m,m);
  }
  cout<<n+(x-sum)/min_m<<endl;
  return(0);
}


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

int N, M;

int main() {
	cin >> N >> M;
	priority_queue<double> A;
	long long int ans = 0;
	for (int i = 0; i < N; i++) {
		double a;
		cin >> a;
		A.push(a);
	}

	for (int i = 0; i < M; i++) {
		double a = A.top(); A.pop();
		A.push(a / 2);
	}
	while (!A.empty()) {
		double a = A.top(); A.pop();
		ans += (int)a;
	}
	cout << ans << endl;
}

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

using namespace std;
using ll = unsigned long long;

ll n, x, xs[2*100000+5];

ll getCost(int k){
    ll result = 0;
    result += x*(n+k);
    result += (xs[0]-xs[k])*2;
    int i;
    for(i=0;i<n/k;i++){
        result += (2*i+3)*(xs[i*k]-xs[(i+1)*k]);
    }
    if(n%k!=0){
        result += (2*i+3)*(xs[i*k]-xs[n]);
    }
    return result;
}

int main(){
    int tmp;
    xs[0] = 0;

    cin >> n >> x;
    for(int i=0;i<n;i++){
        cin >> tmp;
        xs[i+1] = xs[i]+tmp;
    }
    reverse(begin(xs), begin(xs)+(n+1));

    ll ans = getCost(1);
    for(int i=2;i<=n;i++)
        ans = min(ans, getCost(i));

    cout << ans << endl;

/*
    int p[4];
    ll q[4];
    p[0] = 1;
    q[0] = getCost(p[0]);
    p[3] = n;
    q[3] = getCost(p[3]);
    while(p[3]-p[0]>3){
        //cout << p[0] << " " << p[3] << endl;
        p[1] = (p[0]+p[3])/2;
        q[1] = getCost(p[1]);
        p[2] = p[1]+1;
        q[2] = getCost(p[2]);
        ll m = *min_element(begin(q), end(q));
        if(m==q[0]){
            p[3] = p[1];
            q[3] = q[1];
        }
        else if(m==q[3]){
            p[0] = p[2];
            q[0] = q[2];
        }
        else if(m==q[1]){
            q[0] = q[1];
            p[0] = p[1];
        }
        else{
            q[3] = q[2];
            p[3] = p[2];
        }
    }
    p[1] = (p[0]+p[3])/2;
    q[1] = getCost(p[1]);
    p[2] = p[1]+1;
    q[2] = getCost(p[2]);

    cout << (*min_element(begin(q), end(q))) << endl;
*/

/*
    下凸っぽいので最小値を探索できそう?
    for(int k=1;k<=n;k++)
        cout << k << "回目： " << getCost(k) << endl;
*/

    return 0;
}

Measured memory_bytes: 1792
fun main (args : Array<String>) {
	val (a, b) = readLine()!!.split(" ")
	val A : Int = a.toInt()
	val B : Int = b.toInt()
	if ( (B % A) != 0) {
		return println("${B - A}")
	} else {
		return println("${A + B}")
	}
}

Measured memory_bytes: 36060
import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict
 
IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())
 
n,m=IA()
if n==1 or m==1:
  print(1)
else:
  print((n*m+1)//2)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

    ll n,k;
    cin>>n>>k;
    ll x=n;
    vector<ll>vec;
    ll sum=0;
    while(n--)
    {
        ll a;
        cin>>a;
        vec.push_back(a);
        sum+=a;
    }
    double val= sum/(4.0*k);
    ll cnt=0;
    sort(vec.rbegin(), vec.rend());
    for(ll i=0; i<vec.size(); i++)
    {
        if(vec[i]>=val)
            cnt++;
        else break;
    }
        if(cnt>=k)
        {
            cout<<"Yes";

        }
        else cout<<"No";




}


Measured memory_bytes: 256
import Control.Applicative

d = 1000000007

pow :: Integer -> Integer -> Integer
pow m n = pow' m n 1

pow' :: Integer -> Integer -> Integer -> Integer
pow' m n oddtime
    | n == 0 = oddtime
    | even n = pow' (m*m `mod` d) (n `div` 2) oddtime
    | odd n = pow' (m*m `mod` d) (n `div` 2) (oddtime*m)

main = do
    [m, n] <- words <$> getLine
    putStrLn $ show $ (pow (read m::Integer) (read n::Integer)) `mod` d

Measured memory_bytes: 3744
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=2e5+100;
//这题太神!
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int L[N],R[N],x[N];
int e[N<<2];
LL f[N],g[N];
#define lc (i<<1)
#define rc (lc|1)
inline void build(int i,int l,int r,int t) {
	e[i]=t;
	if (l!=r) {
		int mid=(l+r)>>1;
		build(lc,l,mid,t);
		build(rc,mid+1,r,t);
	}
}
inline void modify(int i,int l,int r,int L,int R,int k) {
	if (L<=l&&r<=R) e[i]=k;
	else {
		int mid=(l+r)>>1;
		if (L<=mid) modify(lc,l,mid,L,R,k);
		if (mid<R) modify(rc,mid+1,r,L,R,k);
	}
}
inline int query(int i,int l,int r,int k) {
	if (l==r) return e[i];
	int mid=(l+r)>>1;
	return min(e[i],k<=mid?query(lc,l,mid,k):query(rc,mid+1,r,k));
}
inline void add(int i,int l,int r,int L,int R) {
	if (L<=l&&r<=R) e[i]++;
	else {
		int mid=(l+r)>>1;
		if (L<=mid) add(lc,l,mid,L,R);
		if (mid<R) add(rc,mid+1,r,L,R);
	}
}
inline int Sum(int i,int l,int r,int k) {
	if (l==r) return e[i];
	int mid=(l+r)>>1;
	return e[i]+(k<=mid?Sum(lc,l,mid,k):Sum(rc,mid+1,r,k));
}
int main()
{
	int n=gi(),m=gi(),i,a,k,tp,sum=0,len=0;
	LL ans=1LL<<60,S=0;
	for (i=1;i<=n;i++) {
		a=gi(),tp=gi();S+=a<<1;
		if (tp==1&&a*2>m) return puts("-1"),0;
		if (tp==2) L[i]=0,R[i]=m-1;
		else L[i]=sum,R[i]=(sum-a*2%m+m)%m;
		sum=(sum-a*2%m+m)%m;
		x[++len]=L[i];
		x[++len]=R[i];
	}
	sort(x+1,x+1+len);
	len=unique(x+1,x+1+len)-x-1;
	build(1,1,len,n+1);
	for (i=n;i;i--) {
		L[i]=lower_bound(x+1,x+1+len,L[i])-x;
		R[i]=lower_bound(x+1,x+1+len,R[i])-x;

		k=query(1,1,len,L[i]);
		if (k!=n+1) f[i]=f[k]+(x[L[k]]-x[L[i]]+m)%m;
		k=query(1,1,len,R[i]);
		if (k!=n+1) g[i]=f[k]+(x[L[k]]-x[R[i]]+m)%m;

		if (L[i]<=R[i]) {
			if (R[i]<len) modify(1,1,len,R[i]+1,len,i);
			if (L[i]>1) modify(1,1,len,1,L[i]-1,i);
		} else if (R[i]+1<L[i]) modify(1,1,len,R[i]+1,L[i]-1,i);
	}
	build(1,1,len,0);
	for (i=1;i<=n;i++) {
		if (L[i]<=R[i]) add(1,1,len,L[i],R[i]);
		else add(1,1,len,L[i],len),add(1,1,len,1,R[i]);
		if (Sum(1,1,len,R[i])==i)
			ans=min(ans,g[i]);
	}
	cout<<ans+S<<endl;
	return 0;
}


Measured memory_bytes: 7680
// D - Xor Sum 4
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define MOD 1000000007

ll Z[60], O[60];

int main(){
	int N; cin>>N;
	rp(i, 0, N){
		ll a; scanf("%lld",&a);
		rp(j, 0, 60) if((a>>j)&1) O[j]++; else Z[j]++;
	}
	ll ans = 0;
	rp(i, 0, 60) ans = (ans + (Z[i]*O[i] % MOD) * ((1LL<<i) % MOD)) % MOD;
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int a[1111111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	string s; cin>>s;
	for(int i=0;i<n;i++)
	{
		a[i]=s[i]-'0';
	}
	for(int i=0;i<n-1;i++)
	{
		a[i]=abs(a[i]-a[i+1]);
	}
	n--;
	//solve the n-1 case
	int parity=0;
	for(int i=0;i<n;i++)
	{
		if((i&(n-1))==i)
		{
			parity^=(a[i]&1);
		}
	}
	if(parity==1) cout<<1<<'\n';
	else
	{
		int ex1=0;
		for(int i=0;i<n;i++)
		{
			if(a[i]==1) ex1=1;
		}
		if(ex1)
		{
			cout<<0<<'\n'; return 0;
		}
		//no ones
		for(int i=0;i<n;i++)
		{
			a[i]/=2;
		}
		int parity2=0;
		for(int i=0;i<n;i++)
		{
			if((i&(n-1))==i)
			{
				parity2^=(a[i]&1);
			}
		}
		cout<<parity2*2<<'\n';
	}
}


Measured memory_bytes: 5404
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <algorithm>
#include <limits>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef pair<double, int> E;
typedef complex<double> P;
typedef pair<P, P> L;
const double EPS = 1e-9;
int main() {
    char c[700][700];
    fill_n(c[0], 700*700, '.');
    int w, h;
    cin >> w >> h;
    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) {
            cin >> c[w-i-1+10][j+10];
        }
    }
    bool f[700];
    vector<L> l;
    for (int i = 1; i < 650; i++) {
        fill_n(f, 700, false);
        for (int j = 0; j < 650; j++) {
            if (c[i-1][j] != c[i][j]) f[j] = true;
        }
        vector<int> v;
        for (int j = 1; j < 650; j++) {
            if (f[j-1] != f[j]) v.push_back(j);
        }
        for (int j = 0; j < v.size(); j+=2) {
            l.push_back(L(P(i, v[j]), P(i, v[j+1])));
        }
    }
    for (int j = 1; j < 650; j++) {
        fill_n(f, 700, false);
        for (int i = 0; i < 650; i++) {
            if (c[i][j-1] != c[i][j]) f[i] = true;
        }
        vector<int> v;
        for (int i = 1; i < 650; i++) {
            if (f[i-1] != f[i]) v.push_back(i);
        }
        for (int i = 0; i < v.size(); i+=2) {
            l.push_back(L(P(v[i], j), P(v[i+1], j)));
        }
    }
    vector<E> e;
    for (L ll : l) {
        P p = P(10, 10);
        ll.first -= p; ll.second -= p;
        e.push_back(E(max(arg(ll.first), arg(ll.second))-EPS, -1));
        e.push_back(E(min(arg(ll.first), arg(ll.second))+EPS, 1));
    }
    sort(e.begin(), e.end());
    int res = 0, r = 0;
    for (E ee: e) {
        r += ee.second;
        res = max(res, r);
    }
    cout << res/2+1 << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll dp[105][10];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W, K;
    cin >> H >> W >> K;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    ll p = pow(2LL, W - 1);
    REP(i, H) {
        REP(b, p) {
            bool e = true;
            REP(j, W - 1) {
                if ((b >> j) & (b >> (j + 1)) & 1) {
                    e = false;
                    break;
                }
            }
            if (!e)
                continue;

            REP(j, W) {
                if (j > 0 && ((b >> (j - 1)) & 1))
                    dp[i + 1][j] += dp[i][j - 1];
                else if (j < W - 1 && ((b >> j) & 1))
                    dp[i + 1][j] += dp[i][j + 1];
                else
                    dp[i + 1][j] += dp[i][j];
            }
        }
        REP(j, W) {
            dp[i + 1][j] %= MOD;
        }
    }

    cout << dp[H][K - 1] << endl;
    return 0;
}

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

// 入力
int H, W;
vector<vector<int>> field;

// 探索
void dfs(int h, int w) {
    field[h][w] = 0;

    // 八方向を探索
    for (int dh = -1; dh <= 1; ++dh) {
        for (int dw = -1; dw <= 1; ++dw) {
            int nh = h + dh, nw = w + dw;

            // 場外アウトしたり、0 だったりはスルー
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (field[nh][nw] == 0) continue;

            // 再帰的に探索
            dfs(nh, nw);
        }
    }
}

int main() {
    // 入力受け取り
    while (cin >> W >> H) {
        if (H == 0 || W == 0) break;
        field.assign(H, vector<int>(W, 0));
        for (int h = 0; h < H; ++h) for (int w = 0; w < W; ++w) cin >> field[h][w];

        // 探索開始
        int count = 0;
        for (int h = 0; h < H; ++h) {
            for (int w = 0; w < W; ++w) {
                if (field[h][w] == 0) continue; // 残島じゃなかったらスルー
                dfs(h, w);
                ++count;
            }
        }
        cout << count << endl;
    }
}


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

int main() {
  int k,s,ans=0;
  cin >> k >> s;
  
  for (int x=0; x < k+1; x++) {
    if (s-x>2*k) continue;
    else if (s-x<0) continue;
    else {
      ans += min((2*k+1)-(s-x),s-x+1);
    }
  }
  cout << ans << endl;
}

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

int main()
{
	string S;
	vector<int> cnt(26);
	cin >> S;
	for (auto c : S) {
		cnt[c - 'a']++;
	}
	bool ok = false;
	for (int i = 0; i < 26; i++) {
		if (cnt[i] == 0) {
			cout << (char)('a' + i) << endl;
			ok = true;
			break;
		}
	}
	if (!ok) {
		cout << "None" << endl;
	}
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>

using namespace std;

#define N 3010

int main() {
  int32_t n;
  cin >> n;

  auto a = new int64_t[N];
  for (int32_t i = 0; i < n; ++i) {
    cin >> a[i];
  }

  auto dp = new int64_t[N][N];
  for (int32_t j = 0; j <= n; ++j) {
    dp[0][j] = 0;
  }
  for (int32_t i = 1; i <= n; ++i)
    for (int32_t j = 0; j <= n - i; ++j) {
      dp[i][j] = max(a[j+i-1] - dp[i-1][j], a[j] - dp[i-1][j+1]);
    }

  cout << dp[n][0] << endl;
}


Measured memory_bytes: 71040
#include<stdio.h>
#define M 100

void trace(int *,int);
void insert(int *,int);

int main() {

  int i;
  int number;
  int num[M];

  scanf("%d",&number);
  for(i=0;i<number;i++) scanf("%d",&num[i]);

  trace(num,number);

  insert(num,number);
  
  return 0;
  
}

void trace(int *A,int N) {
  int i;

  for(i=0;i<N;i++) {
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insert(int *A,int N) {
  int j,i,v;

  for(i=1;i<N;i++) {
    v = A[i];
    j=i-1;
    while(j>=0 && A[j]>v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A,N);
  }
}


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

int main() {
	int n, t; cin >> n >> t;
	vector<vector<int>> ct(n, vector<int>(2));
	for (int i = 0; i < n; i++) {
		cin >> ct.at(i).at(0) >> ct.at(i).at(1);
	}
	int ans = 1010;
	for (int i = 0; i < n; i++) {
		if (ct.at(i).at(1) <= t) ans = min(ans, ct.at(i).at(0));
	}
	if (ans > 1000) cout << "TLE" << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 256
import Control.Monad
  ( replicateM )
import Data.List
  ( sort, group )
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

cReadLn :: IO Int
cReadLn = fst . fromJust . C.readInt <$> C.getLine

getParms :: IO [Int]
getParms = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [n,m] <- getParms
  abs   <- replicateM m getParms 
  mapM_ print $ honsu n abs

honsu
  :: Int -> [[Int]] -> [Int]
honsu n as = map length' . group . sort . concat $ ([1..n] : as)
  where
    length' l = length l - 1

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
struct work{
	int a,b;
}a[1000001];
int cmp(work a,work b)
{
	return a.a<b.a;
}
priority_queue<int> q;
int n,m,ans;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].a>>a[i].b;
	}
	sort(a+1,a+n+1,cmp);
	int now=1;
	for(int i=1;i<=m;i++)
	{
		while(a[now].a==i)q.push(a[now++].b);
		if(q.size())
		{
			ans+=q.top();
			q.pop();
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1660
#include<stdio.h>
#include<limits.h>
int main() {
    int size, temp,j, q;
    int p[102];
    int m[102][102];

    scanf("%d", &size);
    for (int i = 0; i < size; i++) {
        scanf("%d %d", &p[i], &temp);
    }
    p[size] = temp;
    
    for (int i = 1; i < size + 1; i++)
    {
        m[i][i] = 0;
    }

    for (int l = 2; l < size + 1; l++) 
    {
        for (int i = 1; i < size - l + 2; i++) 
        {
            j = i + l - 1;
            m[i][j] = INT_MAX;
            for (int k = i; k <= j - 1; k++) 
            {
                q = (m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
                if (m[i][j] > q) 
                {
                    m[i][j] = q;
                }
            }
        }
    }
    printf("%d\n", m[1][size]);
    return 0;
}



Measured memory_bytes: 2108
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math


a,b,c = map(int,input().split())
ans = a+b+c
ans -= max(a,b,c)
print(ans)


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> lls(N);
  for(int i = 0; i < N; ++i) {
    cin >> lls[i];
  }
  sort(lls.begin(), lls.end(), greater<int>());
  int ans = 0;
  for(int i = 0; i < K; ++i) {
    ans += lls[i];
  }
  cout << ans << endl;
  return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li a[200200];
li n;

map<li, li> cnt;

inline li nc2(li nn) {
    return nn * (nn - 1) / 2;
}

int main() {
    cin >> n;
    rin{
        cin >> a[i];
        cnt[a[i]]++;
    }

    li bunshi = 0;
    for (auto && kv : cnt) {
        bunshi += nc2(kv.S);
    }

    rin{
        li tmp = bunshi - nc2(cnt[a[i]]) + nc2(cnt[a[i]] - 1);
        cout << tmp << endl;
    }




    return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  string AtCoder;
  cin >> AtCoder;
  string s;
  cin >> s;
  string Contest;
  cin >> Contest;
  cout << "A" << s[0] << "C" << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>

using namespace std;


int main() {
	int i, j, k;
	//int x, y, z;
	vector<int>n(3);

	for (i = 0; i < 3; i++) {
		cin >> n[i];
	}
	
	sort(n.begin(), n.end());

	char s1 = (char)(n[2] + 48);
	//char *s1 = (char)( (n[2] + 48), (n[1] + 48));
	char s2 = (char)(n[1] + 48);
	//char s1 = (char)(n[2] + 48);

	//string ss(s1,1);
	//string ss2(s2, 1);

	string ss{ s1 };
	string ss2{ s2 };

	//int numm = stoi(ss + ss2);

	int num = stoi(ss + ss2) + n[0];

	cout << num << endl;


	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

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

istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());

  combination c(n + 5);

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


Measured memory_bytes: 2176
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;

const int maxn = 109;
int a[maxn], b[maxn], c[maxn], d[maxn];
int n, W, w0, w, v, ans, A, B, C, D;

inline bool cmp(int a, int b){
	return a > b;
}

signed main(){
	scanf("%lld%lld", &n, &W);
	scanf("%lld%lld", &w0, &a[++A]);
	for (int i=1; i<=n-1; i++){
		scanf("%lld%lld", &w, &v);
		if (w0 == w) a[++A] = v;
		else if (w0+1 == w) b[++B] = v;
		else if (w0+2 == w) c[++C] = v;
		else d[++D] = v;
	}
	sort(a+1, a+A+1, cmp); sort(b+1, b+B+1, cmp);
	sort(c+1, c+C+1, cmp); sort(d+1, d+D+1, cmp);
	for (int i=2; i<=A; i++) a[i] += a[i-1];
	for (int i=2; i<=B; i++) b[i] += b[i-1];
	for (int i=2; i<=C; i++) c[i] += c[i-1];
	for (int i=2; i<=D; i++) d[i] += d[i-1];
	for (int i=0; i<=A; i++) if (i*w0 <= W)
		for (int j=0; j<=B; j++) if (i*w0+j*(w0+1) <= W)
			for (int k=0; k<=C; k++) if (i*w0+j*(w0+1)+k*(w0+2) <= W)
				for (int l=0; l<=D; l++) if (i*w0+j*(w0+1)+k*(w0+2)+l*(w0+3) <= W)
					ans = max(ans, a[i]+b[j]+c[k]+d[l]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
l, r = map(int, input().split())
ans = 2019
for i in range(l, min(r+1, l+2019)):
    for j in range(i+1, min(r+1, i+2019)):
        ans = min(ans, ((i % 2019) * (j % 2019)) % 2019)
print(ans)


Measured memory_bytes: 40940
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

vector<ll> vec;

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

    rep(i, n) {
        ll inputVal;
        cin >> inputVal;
        vec.push_back(inputVal);
    }

    ll min = 9999;
    ll max = -9999;

    rep(i, n) {
        if (min > vec.at(i)) {
            min = vec.at(i);
        }

        if (max < vec.at(i)) {
            max = vec.at(i);
        }
    }


    int pt = min;
    ll powerVal = 1e18;
    arep(i, min, max + 1) {
        ll curPowerVal = 0;
        rep(j, n) {
            ll dx = vec.at(j) - i;
            curPowerVal += dx * dx;
        }


        if (powerVal > curPowerVal) {
            pt = i;
            powerVal = curPowerVal;
        }
    }

    cout << powerVal << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
#define unsort(vec); sort(vec);reverse(vec);
#define int long long
long long ans;

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

int lcm(int x,int y){
	return x*y/gcd(x,y);
}
 
signed main(){
	int n,m;
	cin>>n>>m;
	if(n*2>=m){
		cout<<m/2<<endl;
	}
	else{
		cout<<n+(m-n*2)/4<<endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

constexpr ll INF = 1e9;
int main() {
	init();

	int N; cin >> N;
	vector<string>vec(3);
	vector<map<char, int>>mp(N);
	rep(i, 0, 3) {
		cin >> vec[i];
		rep(j, 0, vec[i].size())mp[j][vec[i][j]]++;
	}
	int ans = 0;
	rep(i, 0, N) {
		bool ok = false;
		for (auto p : mp[i]) {
			if (p.second > 1) {
				ans += 3 - p.second;
				ok = true;
			}
		}
		if (!ok)ans += 2;
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3652
x, k ,d = map(int, input().split())
x=abs(x)
if k*d <= x:
    print(x-k*d)
else:
    xx = x
    x -= min(k, x//d)*d
    k -= min(k, xx//d)
    if k % 2 != 0:
        ans = min(abs(x-d),abs(x+d))
    else:
        ans = min(abs(x), abs(x-2*d))
    print(ans)

Measured memory_bytes: 61768
s = input()
p = 2019
mods = [0] * p
mods[0] = 1
current = 0
base = 1
cnt = 0

for c in map(int, s[::-1]):
    current = (current + base * int(c)) % p
    base = base * 10 % p
    mods[current] += 1

print(sum(el*(el-1)//2 for el in mods))

Measured memory_bytes: 9392
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const X = BigInt(input[0][0]);

  let deposit = 100n;
  let years = 0;

  while (deposit < X) {
    deposit += deposit / 100n;
    years += 1;
  }

  return years;
};

console.log(main(read()));


Measured memory_bytes: 29756
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>

namespace n91 {

void main_() {
  const auto n = scan<u32>();
  const auto d = scan<u32>();

  const auto r = d + d + static_cast<u32>(1);

  std::cout << (n + r - static_cast<u32>(1)) / r << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define love 9223372036854775807 
using namespace std;
int main()
{
	long long min;
	long long n,k;
	scanf("%lld%lld",&n,&k);
	min=love;
	if(k==1||n%k==0)
	{
		printf("0\n");
	}
	
	else
	{
		if(n>k)
		{
			n=n%k;
		}
		min=n;
		n=abs(n-k);
		if(n<min)
		printf("%lld\n",n);
		else
		printf("%lld\n",min);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

//累積和
// vectorっぽく使う
template <typename T>
struct cumulative_sum {
    // data[i]:元の数列
    vector<T> data;
    // sum[i]:[0,i)の和
    vector<long long int> sum;
    //要素数を指定して初期化
    cumulative_sum(const int n) {
        data.assign(n, 0);
    }
    T& operator[](const int k) {
        return data[k];
    }
    // dataに基づいてsumを構築
    void build() {
        sum.assign(data.size() + 1, 0);
        for (int i = 0; i < (int)data.size(); i++) {
            sum[i + 1] = sum[i] + data[i];
        }
    }
    //[a,b)の和を求める
    long long int query(const int a, const int b) {
        return sum[b] - sum[a];
    }
};

int main() {
    int n;
    cin >> n;
    cumulative_sum<lint> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    a.build();
    unordered_map<lint, lint> count;
    for (int i = 0; i <= n; i++) {
        count[a.sum[i]]++;
    }
    lint ans = 0;
    for (auto itr = count.begin(); itr != count.end(); itr++) {
        lint temp = (*itr).second;
        ans += temp * (temp - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gc[100001];
ll gcd(ll a,ll b)
{
	return b == 0?a:gcd(b,a%b);
}
int main()
{
	int n;
	ll x;
	cin>>n;
	cin>>x;
	vector<ll> vi;
	for(int i=0;i<n;i++)
	{
		ll a;
		cin>>a;;
		gc[i] = abs(a-x);
	}
	for(int i=0;i<n-1;i++)
	{
		gc[i+1] = gcd(gc[i],gc[i+1]);
	}
	cout<<gc[n-1]<<endl;
	return 0;
 } 

Measured memory_bytes: 1024
#include <bits/stdc++.h> 
using namespace std; 
#define ll   long long int  
#define pb push_back
const int M=1e9 + 7;
int N=1000000+1;

int main() 
{ 
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    ll W;cin>>W;
    vector<int> v(n+1);
    vector<int> w(n+1);
    int totV=0;
    for(int i=1;i<=n;i++)
    {
    	cin>>w[i]>>v[i];
    	totV+=(v[i]);
	}
	vector<vector<ll>> dp(n+1,vector<ll>(totV+1,INT_MAX));

	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=totV;j++)
		{
			if(j>=v[i])
			{
				dp[i][j]=min(w[i]+dp[i-1][j-v[i]],dp[i-1][j]);
			}else{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	int ans;
		for(int j=0;j<=totV;j++)
		{
			if(dp[n][j]<=W)
			{    
				ans=j;
			}
	
		}
	cout<<ans<<"\n";
	return 0;
} 

Measured memory_bytes: 80256