akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define inf 100000000

using namespace std;

int N, M;
int SG[205][205], LG[205][205];
int R;
int z[1005];

int dp[1005][205];
int Sdist[205][205], Ldist[205][205];

void WarshallFloyd(int G[205][205], int dist[205][205])
{
	for(int k = 1; k <= N; k++){
		for(int i = 1; i <= N; i++){
			for(int j = 1; j <= N; j++){
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
}

int main(void)
{
	while(1){
		cin >> N >> M;
		if(N == 0 && M == 0) break;
		
		for(int i = 1; i <= N; i++){
			for(int j = 1; j <= N; j++){
				SG[i][j] = LG[i][j] = inf;
			}
		}
		int x, y, t; char sl;
		for(int i = 0; i < M; i++){
			cin >> x >> y >> t >> sl;
			if(sl == 'S') SG[x][y] = SG[y][x] = min(SG[x][y], t);
			if(sl == 'L') LG[x][y] = LG[y][x] = min(LG[x][y], t);
		}
		
		for(int i = 1; i <= N; i++){
			for(int j = 1; j <= N; j++){
				Sdist[i][j] = SG[i][j];
				Ldist[i][j] = LG[i][j];
				if(i == j) Sdist[i][j] = Ldist[i][j] = 0;
			}
		}
		
		WarshallFloyd(SG, Sdist);
		WarshallFloyd(LG, Ldist);
		
		
		cin >> R;
		for(int i = 0; i < R; i++) cin >> z[i];
		
		for(int i = 0; i < R; i++){
			for(int j = 1; j <= N; j++) dp[i][j] = inf;
		}
		dp[0][z[0]] = 0;
		
		int d;
		for(int i = 1; i < R; i++){
			for(int j = 1; j <= N; j++){
				for(int k = 1; k <= N; k++){
					if(j == k){
						dp[i][k] = min(dp[i][k], dp[i-1][j] + Ldist[z[i-1]][z[i]]);
						continue;
					}
					d = Ldist[z[i-1]][j] + Sdist[j][k] + Ldist[k][z[i]];
					if(d > inf) d = inf;
					dp[i][k] = min(dp[i][k], dp[i-1][j] + d);
				}
			}
		}
		
		int ans = inf;
		for(int i = 1; i <= N; i++) ans = min(ans, dp[R-1][i]);
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 4532
#include<stdio.h>

int main()
{
	int i,n;
	int array[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&array[i]);
	}
	for(i=n;i>0;i--){
		if(i<n){
			printf(" ");
		}
		printf("%d",array[i-1]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
N, K = [int(x) for x in input().split()]

A = [[0]*2 for i in range(N)]



for i in range(N):
	A[i] = [int(x) for x in input().split()]

A.sort()

counter = 0
for i in range(N):
	counter += A[i][1]
	if counter >= K:
		break

print(A[i][0])

Measured memory_bytes: 21680
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
#include<cmath> 
using namespace std; 
int main()
{ 
	int h, w;   
	cin >> h >> w;
	string ans = "";
;	for (int i = 0; i < h; i++)
	{
	string a; 
	cin >> a;  
	if (i!=0)
	{
		ans+= "\n";
	}
	ans += a; 
	ans += "\n"; 
	ans += a; 
	
	} 
cout << ans;
}

Measured memory_bytes: 256
//Let Our Voices Echo
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAX=600;
int n,m,h,w,a[MAX][MAX];
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>m>>h>>w;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)	
			if (i%h==0 && j%w==0)
				a[i][j]=-(h*w);
			else
				a[i][j]=1;
	if (m%w!=0)
	{
		int x=n-n%h;
		a[x][1]+=3e8;
		for (int i=1;i*w+1<=m;i++)
		{
			a[x][i*w]-=3e8;
			a[x][i*w+1]+=3e8;
		}
	}
	else
	if (n%h!=0)
	{
		int y=m-m%w;
		a[1][y]+=3e8;
		for (int i=1;i*h+1<=n;i++)
		{
			a[i*h][y]-=3e8;
			a[i*h+1][y]+=3e8;
		}
	}
	else return cout<<"No",0;
	cout<<"Yes"<<endl;
	for (int i=1;i<=n;i++,cout<<endl)
		for (int j=1;j<=m;j++)	
			cout<<a[i][j]<<' ';
	return 0;
}

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

void fnInput(int& rnMaxNum, int& rnWinPnt)
{
  cin >> rnMaxNum >> rnWinPnt;
}

double fnWinRate(int nMaxNum, int nWinPnt)
{
  vector<int> vnBorder;

  int nBorder = nWinPnt;
  vnBorder.push_back( nBorder );

  while (nBorder > 1)
  {
    nBorder = (nBorder + 1) / 2;           // 切り上げ
    vnBorder.push_back( nBorder );
  }
  double nWinRate = 0.0;

  for (int nPower = vnBorder.size() - 1; nPower > 0; nPower--)
  {
    double nOneRate = 0.0;
    int nNum = vnBorder[nPower];

    while (nNum < min(vnBorder[nPower - 1], nMaxNum + 1))
    {
      nOneRate += 1.0 / nMaxNum;
      nNum++;
    }
    for (int n = 0; n < nPower; n++)
      nOneRate /= 2;

    nWinRate += nOneRate;
  }
  if (nMaxNum >= vnBorder[0])
  {
    int nDiff = nMaxNum - vnBorder[0] + 1;
    nWinRate += (double)nDiff / nMaxNum;
  }
  return nWinRate;
}
  
int main()
{
  int nMaxNum, nWinPnt;
  fnInput(nMaxNum, nWinPnt);
  cout << fixed << setprecision(10) << fnWinRate(nMaxNum, nWinPnt) << endl;

  return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
const int N = 400, M = 7 + 1e9;
int n;
ll a[N+1], dp[N+1][N+1];//start end
ll cal(int l, int r)
{
	if( l == r )
		return 0;
	ll &ret = dp[l][r];
	if(~ret)
		return ret;
	ret = 1e15;
	f(i, l, r){// last i would be r-1
		int left = i, right = i+1;// l -> left left slime // right -> r right slime
		ret = min(ret, cal(l, left) + cal(right, r));
	}
	return ret += a[r] - a[l-1];
}
int main()
{
	memset(dp, -1, sizeof dp);
	cin >> n;
	f(i, 1, n+1)
		cin >> a[i];
	f(i, 2, n+1)
		a[i] += a[i-1];
	cout << cal(1, n);
}

Measured memory_bytes: 1536
a['   '];n,s,i,m;main(k){for(;scanf("%d%d",&n,&k)*n;s=i=!printf("%d\n",m))for(;i<n;s+=a[i],m=i++<k?s:fmax(m,s-=a[i+~k]))scanf("%d",a+i);}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

int qp(int a, ll b)
{
  int ans = 1;
  do
  {
    if (b & 1)
      ans = 1ll * ans * a % mod;
    a = 1ll * a * a % mod;
  } while (b >>= 1);
  return ans;
}
int qp(int a, ll b, int mo)
{
  int ans = 1;
  do
  {
    if (b & 1)
      ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
void make_fact(ll);
void make_invfact(ll);

ll powLL(ll x, ll y)
{
  ll ans = 1;
  for (ll i = 0; i < y; i++)
    ans *= x;
  return ans;
}

int main(void)
{
  ll t;
  cin >> t;

  for (ll i = 0; i < t; i++)
  {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    if (b > d)
    {
      cout << "No" << endl;
      continue;
    }

    if (a < b)
    {
      cout << "No" << endl;
      continue;
    }
    if (c >= b)
    {
      cout << "Yes" << endl;
      continue;
    }
    if (c + 1 == b)
    {
      cout << "Yes" << endl;
      continue;
    }
    ll g = gcd(b, d);
    //g = gcd(g, d);
    ll m = a % g;

    ll Max = b - g + m;
    if (Max > c)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }

  return 0;
}

ll mod_pow(ll x, ll r)
{
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % mod;
  else if (r % 2 == 0)
  {
    ll t = mod_pow(x, r / 2) % mod;
    return mod_mul(t, t);
  }
  else
  {
    ll t = mod_pow(x, r / 2) % mod;
    ll k = mod_mul(t, t);
    return (k % mod) * (x % mod);
  }
}
ll mod_add(ll a, ll b)
{
  return ((a % mod) + (b % mod)) % mod;
}

ll mod_mul(ll a, ll b)
{
  return ((a % mod) * (b % mod)) % mod;
}

ll mod_div(ll a, ll b)
{
  return mod_mul(a, mod_pow(b, mod - 2));
}

void make_fact(ll n)
{
  fac[0] = 1;
  rep(i, n)
  {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}

void make_invfact(ll n)
{
  invfac[n] = mod_pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
  {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}

Measured memory_bytes: 256
//******************************************************************************
// File Name: D.cpp
// Author: Shili_Xu
// E-Mail: shili_xu@qq.com
// Created Time: 2018年09月05日 星期三 14时43分16秒
//******************************************************************************

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;

const int MAXN = 1e5 + 5;

int n;
ll cnt;
int a[MAXN], b[MAXN], sum[MAXN], temp[MAXN];

ll merge_sort(int l, int r)
{
	if (l == r) return 0;
	ll ans = 0;
	int mid = (l + r) >> 1;
	ans += merge_sort(l, mid);
	ans += merge_sort(mid + 1, r);
	int i = l, j = mid + 1, index = l;
	while (i <= mid && j <= r) {
		if (sum[i] < sum[j])
			temp[index++] = sum[i++];
		else
			temp[index++] = sum[j++], ans += (mid + 1 - i);
	}
	while (i <= mid) temp[index++] = sum[i++];
	while (j <= r) temp[index++] = sum[j++];
	for (int i = l; i <= r; i++) sum[i] = temp[i];
	return ans;
}

bool check(int x)
{
	sum[0] = 0;
	for (int i = 1; i <= n; i++)
		sum[i] = (a[i] <= x ? 1 : -1);
	for (int i = 1; i <= n; i++) sum[i] += sum[i - 1];
	ll cnt1 = merge_sort(0, n);
	cnt1 = cnt - cnt1;
	return (cnt1 >= cnt / 2 + 1);
}

int main()
{
	scanf("%d", &n);
	cnt = 0;
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]), b[i] = a[i], cnt += (ll)i;
	sort(b + 1, b + 1 + n);
	int l = 1, r = n;
	while (l < r) {
		int mid = (l + r) >> 1;
		if (check(b[mid]))
			r = mid;
		else
			l = mid + 1;
	}
	printf("%d\n", b[l]);
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
signed main()
{
int n;
cin>>n;
for(int i=1;i<=9;i++)
{
    if(n%i==0)
    {
        if((n/i)<=9)
        {
            cout<<"Yes";
            return 0;
        }
    }
}
cout<<"No";
return 0;
}



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

const int N=1e5+10;
int INF=0x3f3f3f3f;
//memset(a,0x3f,sizeof(a));
int a[N];

int main(){
	ios_base::sync_with_stdio(false);
	
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	
	int flag=0,ans=1;
	int temp=a[1];
	for(int i=1;i<=N;i++){
		if(temp==2) {flag=1;break;}
		temp=a[temp];
		ans++;
	}
	
	if(flag==0) cout<<-1<<endl;
	else cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define float double
#define pb push_back
#define FF first
#define SS second
#define N 201000
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i++)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define INF 1000000000000000000
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

signed main() 
{
    speed;
    
    int n,k;
    cin>>n>>k;
    int A[n];
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    int dp[n];
    dp[0]=0;
    
    for(int i=1;i<n;i++)
    {
    	int j;
    	int p=i-k;
        if(p<0) p=0;
        dp[i]=INT_MAX;
        for(j=p;j<i;j++)
        {
            dp[i]=min(dp[j]+abs(A[i]-A[j]),dp[i]);
        }
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main()
{
    const auto primes = [] {
        vector<int> r;
        bitset<1'000'000> b;
        auto t = b;
        t.set();
        t[0] = false;
        t[1] = false;
        int i = 0;
        while (true) {
            bool done = false;
            while (!t[i]) {
                ++i;
                if (i == t.size()) {
                    done = true;
                    break;
                }
            }
            if (done) {
                break;
            }

            b[i] = true;
            r.push_back(i);
            for (int j = i; j < t.size(); j += i) {
                t[j] = false;
            }
        }
        return r;
    }();

    while (true) {
        int n, p;
        cin >> n >> p;
        if (n == -1 && p == -1) {
            return 0;
        }

        const auto s = upper_bound(begin(primes), end(primes), n);
        vector<int> q;
        for (int i = 0; i < p; ++i) {
            for (int j = i; j < p; ++j) {
                q.push_back(*(s + i) + *(s + j));
            }
        }
        sort(begin(q), end(q));
        cout << q[p - 1] << endl;
    }
}


Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_set>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>
	
string s;
ll k;
ll ans = 0;


ll com(ll n, ll r) {
	if (n < 0 or r < 0)return 0;
	if (n < r)return 0;
	ll res = 1;
	REPO(i, r)res = res * (n - i + 1) / i;
	return res;
}

void solve(ll a, ll b, ll c) {
	if (a == s.size()) {
		if (b == k) {
			ans++;
		}
		return;
	}
	if (s[a] - '0' == 0)solve(a + 1, b, c);
	else solve(a + 1, b, 1);
	if (b == k) return;
	FOR(i, 1, 10) {
		if (c == 0 and i > s[a] - '0')break;
		if (s[a] - '0' > i) ans += com(s.size() - 1 - a, k - b - 1) * pow(9, k - b - 1);
		else solve(a + 1, b + 1, c);
	}
}
int main() {
	cin >> s >> k;
	solve(0, 0, 0);
	cout << ans << endl;
}



Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<string>
#include<map>

using namespace std;
const int INF = 1<<30;
typedef long long int ll;

int main(){
  int n;cin>>n;
  map<int, int> count;
  for(int i=0;i<n;i++){int a;cin>>a;count[a]++;}
  int m;cin>>m;
  for(int i=0;i<m;i++){int a;cin>>a;count[a]--;}
  bool ans=true;
  for(auto itr=count.begin();itr!=count.end();itr++){
  	if(itr->second<0){ans=false;break;}
  }
  cout<<(ans?"YES":"NO")<<endl;
}


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

total=sum(A)
if total%(4*M)==0:
  n=total//(4*M)
else:
  n=total//(4*M)+1


cnt=0
for i in range(N):
  if A[i]>=n:
    cnt+=1
if cnt>=M:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<stdio.h>

long long calcce(long long pt[]){
  if(pt[0]==pt[1]&&pt[1]==pt[2]&&pt[2]==pt[3]){return 4;}
  if(pt[0]==pt[2]&&pt[1]==pt[3]){return 2;}
  return 1;
}

long long cha[1024][4];
long long ispt(long long tg,long long hash){
  if(cha[tg][0]==hash){return 1;}
  if(cha[tg][1]==hash){return 1;}
  if(cha[tg][2]==hash){return 1;}
  if(cha[tg][3]==hash){return 1;}
  return 0;
}

long long calc(long long cnt[]){
  long long i,j,k,l,res=0,dt;
  long long pj,pk,pl;
  //for(i=0;i<16;i++){printf("[%lld]",cnt[i]);}printf("\n");
  for(i=1;i<16;i+=2){//if((i&1)==0){continue;}
    if(cnt[i]==0){continue;}
    dt=cnt[i];cnt[i]--;
    pj=dt;
    for(j=0;j<16;j++){if((j&2)==0){continue;}
      if(cnt[j]==0){continue;}
      dt*=cnt[j];cnt[j]--;
      pk=dt;
      for(k=0;k<16;k++){if((k&4)==0){continue;}
        if(cnt[k]==0){continue;}
        dt*=cnt[k];cnt[k]--;
        pl=dt;
        for(l=8;l<16;l++){//if((l&8)==0){continue;}
          if(cnt[l]==0){continue;}
          dt*=cnt[l];cnt[l]--;
          res+=dt;
          cnt[l]++;
          dt=pl;
        }
        cnt[k]++;
        dt=pk;
      }
      cnt[j]++;
      dt=pj;
    }
    cnt[i]++;
  }
  return res;
}

int main(){
  //printf("%lld\n",(1ll<<10) + (2ll<<20) + (3ll<<30));
  srand(0);
  long long n,i,j,k,l,m,f,ce,res=0,tf,mem;
  long long c[512][4];
  long long jt[4],kt[4];
  long long md[4][4];
  long long cnt[16]={0};
  long long nha,mha[4];
  scanf("%lld",&n);
  //n=400;
  for(i=0;i<n;i++){
    nha=0;
    for(j=0;j<4;j++){
      scanf("%lld",&c[i][j]);
      //c[i][j]=rand()%4;
      nha|=(c[i][j]<<(10*j));
    }
    for(j=0;j<4;j++){
      cha[i][j]=nha;
      mem=(nha&((1ll<<10)-1));
      //printf("[%lld]<%lld>",cha[i][j],mem);
      nha>>=10;
      nha|=(mem<<30);
    }//printf("\n");
  }
  for(i=0;i<n;i++){
    for(j=0;j<4;j++){jt[j]=c[i][j];}
    for(j=i+1;j<n;j++){
      for(k=0;k<4;k++){
        for(l=0;l<4;l++){
          kt[l]=c[j][(4+k-l)&3ll];
        }
        ce=1;
        for(l=0;l<4;l++){
          md[l][0]=jt[l];
          md[l][1]=jt[(l+3)&3ll];
          md[l][2]=kt[(l+3)&3ll];
          md[l][3]=kt[l];
          mha[l]=(md[l][0]|(md[l][1]<<10)|(md[l][2]<<20)|(md[l][3]<<30));
          //printf("<%lld %lld %lld %lld : %lld>\n",md[l][0],md[l][1],md[l][2],md[l][3],mha[l]);
          ce*=calcce(md[l]);
        }
        for(l=0;l<16;l++){cnt[l]=0;}
        tf=0;
        for(l=i+1;l<n;l++){
          if(l==j){continue;}
          f=0;
          for(m=0;m<4;m++){
            if(ispt(l,mha[m])==1){f|=(1ll<<m);}
          }
          //printf("%lld\n",f);
          tf|=f;
          cnt[f]++;
        }
        if(tf!=15){continue;}
        res+=ce*calc(cnt);
      }
    }
  }
  printf("%lld\n",res);
  return 0;
}


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

int main() {
  string a;
  cin >> a;
  if((a.at(2) == a.at(3)) && (a.at(4) == a.at(5))){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    deque<string> rest;
    map<string, vector<int>> mps;
    map<int, int> mp;
    for (int i = 0; i < N; i++)
    {
        string S;
        int P;
        cin >> S >> P;
        rest.push_back(S);
        mps[S].push_back(P);
        sort(mps[S].begin(), mps[S].end(), greater<int>());
        mp[P] = i + 1;
    }
    sort(rest.begin(), rest.end());
    for (int i = 0; i < N; i++)
    {
        cout << mp[mps[rest[i]].front()] << endl;
        mps[rest[i]].erase(mps[rest[i]].begin());
    }
}

Measured memory_bytes: 256
#include <stdio.h>
        #include <stdlib.h>
         
        int main() {
         
        	int num_a, num_b, num_c, num_d;
        	int max_s,min_e;
        	int res = 0;
         
        	scanf("%d %d %d %d", &num_a, &num_b, &num_c, &num_d);
         
        	max_s = (num_a > num_c) ? num_a : num_c;
         
        	min_e = (num_b < num_d) ? num_b : num_d;
         
        	res = min_e - max_s;
         
        	if (res < 0) {
        		printf("%d", 0);
        	} else {
        		printf("%d", res);
        	}
         
        	return 0;
         
        }

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;

	int cnt = 0;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		if(t % 2 == 1) cnt++;
	}
	if(cnt % 2 == 1){
		puts("NO");
	}else{
		puts("YES");
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    long long h,w;
    long long x,y;
    
    cin >> w >> h >> x >> y;
    
    int check = 0;
    
    if (w%2 == 0 && h%2 == 0 && x == w/2 && y == h/2){
        check = 1;
    }
    
    double ans = (double)(h*w)/2;
    printf("%.12f %d\n",ans,check);
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    string s;
    int k;
    cin >> s;
    cin >> k;
    REP(i,k) {
        if(s[i] != '1') {
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << "1" << endl;
    return 0;
}


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 int long long
#ifdef TEST
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#endif
#define ins insert
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, ans, A[200005];

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1, prv = 0; i <= N; i++) {
		if (prv > A[i]) ans += prv - A[i];
		else prv = A[i];
	}
	cout << ans << '\n';
}


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

int s[224] = {};

void push(int );
void empty();
int  pop();

int top = 0;

int main(){
  char ss[224];
  int x,y;
  while(scanf("%s",ss) != EOF){
    // printf("%s\n",ss);
    if(ss[0] == '+'){
      x = pop();
      y = pop();
      // printf("+x = %d,y = %d\n",x,y);
      push(x + y);
    }
    else if(ss[0] == '-'){
      x = pop();
      y = pop();
      // printf("-x = %d,y = %d\n",x,y);
      push(y - x);
    }
    else if(ss[0] == '*'){
      x = pop();
      y = pop();
      // printf("*x = %d,y = %d\n",x,y);
      push(x * y);
    }
    else{
      // printf("at = %d\n,top = %d\n",atoi(ss),top);
      push(atoi(ss));
    }
  }

  printf("%d\n",s[top]);  
  return 0;
}

void push(int x){
  top++;
  s[top] = x;
}

int pop(){
  top--;
  return s[top + 1];
}


  

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

using namespace std;

int main(){
    int a;
    int b;
    int c;
    int k;
    cin >> a >> b >> c >> k;
    int result = 0;
    if(k < a){
        result = k;
    }
    else if(a <= k && b >= k){
        result = a;
    }
    else{
        result = a - (k - a - b);
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3600
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    T, A = map(int, input().split())
    H = list(map(int, input().split()))

    d = 10000000
    ans = 0
    for i, h in enumerate(H):
        if abs(T - 0.006*h - A) < d:
            d = abs(T - 0.006*h - A)
            ans = i+1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63064
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#include <iostream>
#include <string>
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    lint a[n],max = -INT_MAX,min = INT_MAX,sum = 0;
    rep(i,n){
        cin >> a[i];
        chmax(max,a[i]);
        chmin(min,a[i]);
        sum += a[i];
    }
    cout << min << " " << max << " " << sum << '\n';
}



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



int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int dp[n]={-1};
     dp[0]=0;
    for(int i=1;i<n;i++){
        dp[i]=INT_MAX;
        for(int j=i-1;j>=0 and i-j<=k;j--){
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
    }
    cout<<dp[n-1];
    return 0;
    }


Measured memory_bytes: 4384
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int N = sc.nextInt();
  int K = sc.nextInt();
  int X = sc.nextInt();
  int Y = sc.nextInt();
  if(N <= K)System.out.println(N*X);
  else System.out.println((N-K)*Y + K*X);
}
}

Measured memory_bytes: 23252
n,m = list(map(int, input().split()))
L = [list(map(int, input().split())) for _ in range(m)]

from collections import defaultdict
from collections import deque
d=defaultdict(list)
for l in L:
    d[l[0]-1].append(l[1]-1)
    d[l[1]-1].append(l[0]-1)

#print(d)

# 辺を切断した状態で幅優先探索をしてすべての頂点に行けるか
def check_path(hen):
        
    visit=[False]*n
    q=deque([0])
    
#    print('L=',L)
#    print('hen=',hen)
    
    while q:
        node = q.popleft()
#        print('current->', node)
        visit[node]=True
        Nexts = d[node]
        for nxt in Nexts:
            if visit[nxt]:
#                print(nxt, ' is already visited.')
                continue
            
            if node+1 not in L[hen] or nxt+1 not in L[hen]:
#                print('next->', nxt)
                q.append(nxt)
    
#    print('visit=', visit)
    return all(visit)
    
cnt=0
for i in range(m):
    if not check_path(i):
        cnt+=1

print(cnt)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

#define MAX 100

int tx, ty, ans;
int n, X[MAX][MAX], Y[MAX][MAX];
bool visited[MAX][MAX], found[MAX][MAX];
bool used[MAX][MAX], flg;

void rec(int x, int y){
  if(visited[x][y]){
    if(!found[x][y] && tx == x && ty == y){
      found[x][y] = flg = true;
      ans++;
    } 
    return;
  }
  visited[x][y] = true;
  rec(X[x][y],Y[x][y]);
}

void draw(int x,int y){
  if(tx == x && ty == y){
    return;
  }
  used[x][y] = true;
  draw(X[x][y],Y[x][y]);
}

int main(){
  while(cin >> n ,n){
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
	cin >> X[j][i] >> Y[j][i];
      }
    }

    ans = 0;
    memset(found,false,sizeof(found));
    memset(used,false,sizeof(used));
    for(int i = 0 ; i < n ; i++){ 
      for(int j = 0 ; j < n ; j++){
	memset(visited,false,sizeof(visited));
	if(!used[i][j]){
	  flg = false;
	  visited[i][j] = true;
	  tx = i, ty = j;
	  rec(X[i][j], Y[i][j]);
	  if(flg){
	    draw(X[i][j], Y[i][j]);
	  }
	}
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define MAX_V        20004

const ll inf = 1e15;
const ll mod = 1e9+7;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

struct edge {
    ll to, cap, rev;
    edge(ll t, ll c, ll r): to(t), cap(c), rev(r){}
};

vector<edge> G[MAX_V];
ll level[MAX_V];
ll iter[MAX_V];

void add_edge(ll from, ll to, ll cap) {
    G[from].push_back(edge(to, cap, G[to].size()));
    G[to].push_back(edge(from, 0, G[from].size() - 1));
}

void bfs(ll s) {
    memset(level, -1, sizeof(level));
    queue<ll> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
        ll v = que.front(); que.pop();
        rep(i, G[v].size()) {
            edge &e = G[v][i];
            if (e.cap > 0 && level[e.to] < 0) {
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

ll dfs(ll v, ll t, ll f) {
    if (v == t) return f;
    ll &i = iter[v];
    while (i < G[v].size()) {
        edge &e = G[v][i];
        if (e.cap > 0 && level[v] < level[e.to]) {
            ll d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
        i++;
    }
    return 0;
}

ll max_flow(ll s, ll t) {
    ll flow = 0;
    while (true) {
        bfs(s);
        if (level[t] < 0) return flow;
        memset(iter, 0, sizeof(iter));
        ll f;
        while ((f = dfs(s, t, inf)) > 0) {
            flow += f;
        }
    }
}

char field[101][101];
int main() {
    ll H, W; cin >> H >> W;
    rep(i, H) rep(j, W) {
        cin >> field[i][j];
        if (field[i][j] == 'X' && (i == 0 || i == H-1 || j == 0 || j == W-1)) {
            cout << -1 << endl;
            return 0;
        }
    }
    
    ll S = 2 * H * W;
    ll T = 2 * H * W + 1;
    rep(i, H) rep(j, W) {
        if (field[i][j] == 'X') add_edge(S, i * W + j, inf);
        if (i == 0 || i == H-1 || j == 0 || j == W-1) add_edge(H * W + i * W + j, T, inf);
        
        add_edge(i * W + j, H * W + i * W + j, field[i][j] == 'X' ? inf : 1);
        rep(k, 4) {
            if (i+dy[k] < 0 || H-1 < i+dy[k] || j+dx[k] < 0 || W-1 < j+dx[k]) continue;
            add_edge(H * W + i * W + j, (i+dy[k]) * W + (j+dx[k]), inf);
        }
    }
    cout << max_flow(S, T) << endl;
    
    return 0;
}

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

vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
  int k;
  cin>>k;
  cout<<v[k-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
num = int(input())
an = [ int(i) for i in input().split()]
print(" ".join([str(n) for n in an]))

for i in range(1, len(an)):
    v = an[i]
    j = i - 1
    while j >= 0 and an[j] > v:
      an[j+1] = an[j]
      j = j - 1
    
    an[j+1] = v

    print(" ".join([str(n) for n in an]))



Measured memory_bytes: 5604
#include<cstdio>
#include<iostream>
using namespace std;
int n,k,ans=0,now;
int main(){
	scanf("%d%d",&n,&k);
	now=1;
	for(now=1;now<n;now+=k){
		++ans;--now;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
x = int(input())

dp = [0 for _ in range(100000 + 1)] #0:"No", 1:"Yes"
dp[0] = 1
for i in range(100, 106):
    dp[i] = 1
for i in range(106, x + 1):
    #if dp[i-100] == 1 or dp[i-101] == 1 or dp[i-102] == 1 or dp[i-103] == 1 or dp[i-104] == 1 or dp[i-105] == 1:
    if sum(dp[i-105:i-99]) >= 1:
        dp[i] = 1
print(dp[x])


Measured memory_bytes: 3864
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 100005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <ll,int> P;

int N;
ll A[SIZE],B[SIZE],sB[SIZE*2];
P T[SIZE*2]; //ソート後の位置計算用
int U[SIZE*2]; //ソート後の位置
bool W[SIZE*2]; //消えたかどうか
ll a;

int main()
{
	cin >> N;
	priority_queue<ll,vector<ll>,greater<ll>> que;
	ll asum = 0;
	rep(i,0,N){
		cin >> a;
		que.push(a);
		asum += a;
	}
	rep(i,0,N){
		cin >> A[i];
		sB[i] = A[i];
		T[i] = P(sB[i],i);
	}
	ll bsum=0;
	rep(i,0,N){
		cin >> B[i];
		sB[i+N] = B[i];
		T[i+N] = P(sB[i+N],i+N);
	}
	sort(sB,sB+2*N);
	sort(T,T+2*N); //ソート後の位置計算用
	rep(i,0,2*N) { //ソート後の位置
		U[T[i].second] = i;
	}

	rep(i,0,N) bsum += sB[i];
	int bmin = N-1;
	ll ans = asum - bsum;
	rep(i,0,N) {
		asum += A[i];
		que.push(A[i]);
		asum -= que.top();que.pop();

		if(A[i] <= sB[bmin]){ //消える
			W[U[i]] = true;
			bmin++;
			while(W[bmin])bmin++;
			bsum -= A[i];
			bsum += sB[bmin];
		}else{ //変わらない
			W[U[i]] = true;
		}
		//cout << asum << " " << bsum << endl;

		ans = max(ans,asum-bsum);
	}


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


Measured memory_bytes: 8436
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>

typedef long long LL;

using namespace std;

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}


int main(void) {
	string s;
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA";
		return 0;
	}
	int count = 0;
	for (int i = 2; i < s.size() - 1; i++) {
		if (s[i] == 'C') {
			count++;
		}
	}
	if (count != 1) {
		cout << "WA";
		return 0;
	}
	count = 0;
	for (int i = 0; i < s.size(); i++) {
		if (isupper(s[i])) {
			count++;
		}
	}
	if (count != 2) {
		cout << "WA";
		return 0;
	}
	cout << "AC";
	return 0;
}

Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    L=LI()
    L.sort()
    ans = 0
    for i in range(N):
        ans += L[2*i]
    print(ans)
if __name__ == '__main__':
    main()

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

struct UnionFind{

    vector<int> par;
    vector<int> sizes;

    UnionFind(int n):par(n),sizes(n,1){
        for(int i=0;i<n;i++){
            par[i]=i;
        }
    }
    
    int find(int x) { //xの根を得る
        if (x == par[x]) return x;
        return par[x] = find(par[x]); //根を張り替えながら再帰的に根ノードを探す
    }

    void unite(int x, int y) { //xとyの集合を併合
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sizes[find(x)];
    }
};

int main(){
    int N,M; cin >> N >> M;
    int p[N];
    for(int i=0;i<N;i++){
        int x;
        cin >> x; x--;
        p[i]=x;
    }
    UnionFind uf(N);
    for(int i=0;i<M;i++){
        int x,y; cin >> x >> y;
        x--;y--;
        uf.unite(x,y);
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(uf.same(i,p[i])){
            ans++;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 1408
#include <stdio.h>
#define exchange(a,b) {typeof(a) __tmp=a;a=b;b=__tmp;}
 
 
char A[100001];
int B[100001];
 
 
int Partition(int A[], int p, int r) {
  int i,j;
  int x;

  x = A[r];
  i = p-1;
  for(j = p; j < r; ++j) {
    if(B[A[j]] <= B[x]) { // if(A[j] <= x) {
      i = i+1;
      exchange(A[i], A[j]);
    }
  }
  exchange(A[i+1], A[r]);
  return i+1;
}
 
void Quicksort(int A[], int p, int r) {
  int q;

  if(p < r) {
    q = Partition(A,p,r);
    Quicksort(A,p,q-1);
    Quicksort(A,q+1,r);
  }
}
 
int isStable(int A[], int n) {
  int i;

  for(i = 2; i <= n; ++i) {
    if(B[A[i-1]] == B[A[i]] && A[i-1] > A[i]) return 0;
  }
  return 1;
}
 
int main() {
  int i, n;
  int C[100001];

  scanf("%d", &n);
  for(i = 1; i <= n; ++i) {
    scanf(" %c %d", A+i,B+i);
    C[i] = i;
  }
  Quicksort(C,1,n);
  if(isStable(C,n)) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 1; i <= n; ++i) {
    printf("%c %d\n", A[C[i]], B[C[i]]);
  }
  return 0;
}


Measured memory_bytes: 2572
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n:usize,
        k:usize,
        mut h:[i64; n]
    }
    h.sort();
    let mut min = 1<<60;
    for i in 0..n-k+1 {
        min = std::cmp::min(min, h[i+k-1] - h[i]);
    }
    println!("{}", min);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define INF 100000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define print(x) cout << x << "\n"
#define printv(vec) rep(i, vec.size()) cout << vec[i] << " "
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;

vvl d2_add(vvl a){
	ll w, h, cnt_w;
	w = a[0].size();
	h = a.size();
	vvl da(h, vl(w));
	da[0][0] = a[0][0];
	rep2(i, 1, w)  da[0][i] = da[0][i - 1] + a[0][i];
	rep2(i, 1, h){
		cnt_w = 0;
		rep(j, w){
			cnt_w += a[i][j];
			da[i][j] = da[i - 1][j] + cnt_w;
		}
	}
	return da;
}

ll d2_calc(vvl& da, ll x1, ll y1, ll x2, ll y2){
	if(x1 > x2 || y1 > y2)  return 0;
	if(x1 == 0 && y1 == 0)  return da[x2][y2];
	if(x1 == 0)  return da[x2][y2] - da[x2][y1 - 1];
	if(y1 == 0)  return da[x2][y2] - da[x1 - 1][y2];
	return da[x2][y2] - da[x1 - 1][y2] - da[x2][y1 - 1] + da[x1 - 1][y1 - 1];
}

void solve(){
	
	ll N, M, Q, a, b, ans;
	cin >> N >> M >> Q;
	vvl v(N, vl(N));
	vvl p(Q, vl(2));
	
	rep(i, M){
		cin >> a >> b;
		v[a - 1][b - 1] += 1;
	}
	
	rep(i, Q){
		cin >> a >> b;
		p[i][0] = a - 1;
		p[i][1] = b - 1;
	}
	
	vvl ret = d2_add(v);
	
	rep(i, Q){
		ans = d2_calc(ret, p[i][0], p[i][0], p[i][1], p[i][1]);
		print(ans);
	}
	
}	

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
    
	return 0;
	
}


Measured memory_bytes: 14544
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>

using namespace std;

long long dp[100];

long long lucas(int n) {
	if(n == 0) return 2;
	if(n == 1) return 1;
	if(dp[n] == 0) dp[n] = lucas(n-1) + lucas(n-2);
	return dp[n];
}

int main() {
	int n;
	cin >> n;
	cout << lucas(n) << endl;
}


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

int main()
{
  int N;
  cin >> N;
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  long long dp[100001][3];
  for (auto i = 0; i < N; ++i) for (auto j = 0; j < 3; ++j) dp[i][j] = 0;
  dp[0][0] = a[0]; dp[0][1] = a[1]; dp[0][2] = a[2];
  for (int i = 1; i < N; ++i) {
    cin >> a[0] >> a[1] >> a[2];
    for (int j = 0; j < 3; ++j)
    	for (int k = 0; k < 3; ++k)
          if (j != k) 
      		dp[i][j] = max(dp[i][j], a[j] + dp[i-1][k]);
    
  }
  cout << max(max(dp[N-1][0], dp[N-1][1]), dp[N-1][2]) << endl;
  return 0;
}

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

int main() {
  int64_t n;
  cin>>n;
  vector<int64_t> a;
  for(int64_t i=0; i<n; i++) {
  	int64_t temp;
    cin>>temp;
    a.push_back(temp);
  }
  
  int64_t count=0;
  for(int64_t i=1; i<n; i++) {
  	if(a[i] < a[i-1]) {
    	count+= (a[i-1]-a[i]);
      a[i] = a[i-1];
    }
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 5336
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
 
using namespace std;
int N;
int A;

int main()
{
  int n, i;
  int ret=0;

  cin >> N;
  for (i=0; i<N; i++) {
    cin >> A;
    if (A%2) continue;
    if (A%3 == 0) continue;
    if (A%5 == 0) continue;
    break;
  }
  if (i>=N)
    printf("APPROVED\n");
  else
    printf("DENIED\n");

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
#define pi acos(-1);
ll strtoint(string str);
int main(){
	fast;
	ll k; cin>>k;
	string s; cin>>s;
	if(s.size()<=k)cout<<s<<'\n';
	else{
		cout<<s.substr(0,k)+"..."<<'\n';
	} 
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 3644
fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val a = (1..n).map { readLine()!! }
    val b = (1..m).map { readLine()!! }

    for(y in 0..n-m)for(x in 0..n-m) {
        if((0..m-1).all{ i-> (0..m-1).all{ j-> a[y+i][x+j]==b[i][j] } }) {
            println("Yes")
            return
        }
    }
    println("No")
}

Measured memory_bytes: 37752
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::min; using std::max;
using std::swap; using std::sort;
typedef long long ll;

template<typename T>
void read(T &x) {
	int flag = 1; x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= flag;
}

const int _ = 4e2 + 10, P = 1e9 + 7;
int n, m, a[_], b[_], f[_][_], pw[_][_], p[_][_];

int main () {
	read(n), read(m);
	for(int i = 1; i <= n; ++i) read(a[i]);
	for(int i = 1; i <= n; ++i) read(b[i]);
	for(int i = 1; i <= 400; ++i) {
		p[i][0] = 1;
		for(int j = 1; j <= m; ++j)
			p[i][j] = 1ll * p[i][j - 1] * i % P;
	}
	f[0][0] = 1;
	for(int i = 1; i <= n; ++i) {
		int tmp = 1;
		for(int j = a[i]; j <= b[i]; ++j) tmp = 1ll * tmp * j % P;
		pw[i][0] = b[i] - a[i] + 1;
		for(int k = 1; k <= m; ++k)
			for(int j = a[i]; j <= b[i]; ++j)
				(pw[i][k] += p[j][k]) %= P;
	}
	for(int i = 1; i <= n; ++i)
		for(int j = 0; j <= m; ++j)
			for(int k = 0; k <= j; ++k)
				(f[i][j] += 1ll * f[i - 1][j - k] * pw[i][k] % P) %= P;
	printf("%d\n", f[n][m]);
	return 0;
} 

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

using namespace std;

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

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===




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

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

	vector<Vi> pos(10);
	for (int i = 0; i < N; ++i) {
		pos[S[i] - '0'].push_back(i);
	}


	int ans = 0;

	for (int i = 0; i <= 999; ++i) {
		int d1, d2, d3;
		int idx1, idx2, idx3;
		int i_tmp;

		d1 = i / 100;
		d2 = (i - 100 * d1) / 10;
		d3 = i % 10;

		if (0 < pos[d1].size()) idx1 = pos[d1][0];
		else continue;

		i_tmp = upper_bound(pos[d2].begin(), pos[d2].end(), idx1) - pos[d2].begin();
		if (i_tmp < pos[d2].size()) idx2 = pos[d2][i_tmp];
		else continue;

		i_tmp = upper_bound(pos[d3].begin(), pos[d3].end(), idx2) - pos[d3].begin();
		if (i_tmp < pos[d3].size()) idx3 = pos[d3][i_tmp];
		else continue;

		++ans;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define re(n) for (int i = 0; i < (n); ++i)
#define rej(n) for (int j = 0; j < (n); ++j)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <pair <int, int>> vii;

const ld PI = acos((ld)-1);

int main() {
    #ifndef LOCALDEBUG
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #endif  // LOCALDEBUG
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0, j = s.size() - 1; i < j; ++i, --j){
        if (s[i] != s[j]) ++ans;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <iterator>
#include <set>

using namespace std;

int A, B;

int main()
{
    cin >> A >> B;
    if ((A + B) % 2 != 0) {
        cout << "IMPOSSIBLE" << endl;
    }
    else {
        cout << (A + B) / 2 << endl;
    }
}

Measured memory_bytes: 256
n,l = map(int,input().split())
li = []
ind = 0
for i in range(1,n+1):
    li.append(i+l-1)

mi = abs(li[0])
for i in li:
    if abs(i) < mi:
        mi = abs(i)
        ind = li.index(i)

print(sum(li)-li[ind])

Measured memory_bytes: 9044
S = input()
flag = True
while flag:
    if S[-5:]=="dream":
        S = S[:-5]
    elif S[-5:]=="erase": 
        S = S[:-5]
    elif S[-7:]=="dreamer": 
        S = S[:-7]
    elif S[-6:]=="eraser": 
        S = S[:-6]
    elif len(S)==0:
        break
    else:
        flag = False

if flag:
    print("YES")
else:
    print("NO")
    

Measured memory_bytes: 3188
n = int(input())
result = ''


def rec(n, result):
    q, mod = divmod(n, 26)

    if q == 0:
        if mod != 0:
            result += chr(mod + 96)
        return result

    if mod == 0:
        result += 'z'
        q = q - 1
    else:
        result += chr(mod + 96)

    n = q
    return rec(n, result)


result = rec(n, result)
print(result[::-1])


Measured memory_bytes: 9128
#include<stdio.h>
int main(void)
{
	int n,i,x,y,w,max,c;
	scanf("%d",&n);
	max=-1; x=0;
	for(i=1;i<=n;i++){
		y=i; c=0;
		while(1){
			if(y%2!=0) break;
			y=y/2;
			c++;
		}
		if(max<c){
			max=c; x=i;
		}	
	}
	printf("%d\n",x);
	return 0;
}	

Measured memory_bytes: 128