stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<iostream>

#include<sstream>

#include<string>

#include<string.h>

#include<algorithm>

#include<stdio.h>

#include<math.h>

#include<vector>

#include<queue> 

#include<map>

#include<set>

#include<stack>

#define debug(a) cout << "*" << a << "*" << endl

using namespace std;

typedef long long ll; 

ll a, b, c, d, mx;

ll gcd(ll a, ll b)

{

	return b == 0 ? a : gcd(b, a % b);

}

int main()

{

	while (~scanf("%lld%lld%lld%lld", &a, &b, &c, &d))

	{

		mx = c * d / gcd(max(c, d), min(c, d));

		a--;

		printf("%lld\n", b - a - b / c - b / d + a / c + a / d + b / (mx) - a / (mx));

	}

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;



long long gcd(long long x,long long y)

{

	if(!y) return x;

	return gcd(y,x%y);

}



int main()

{

	long long a,b,c,d;

	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);

	long long e=c*d/gcd(c,d);a--;

	long long ans=(b-a+1)-((b-(b%c))-(a-(a%c)))/c-1-((b-(b%d))-(a-(a%d)))/d-1+((b-(b%e))-(a-(a%e)))/e+1;

	printf("%lld\n",ans);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long int lint;



int main(){

    lint a, b, c, d;

    

    

    cin >> a >> b >> c >> d;

    lint ekok = (c*d)/__gcd(c,d);

    lint c_bolum_a = (a-1)/c;

    lint d_bolum_a = (a-1)/d;

    lint cd_bolum_a = (a-1)/ekok;

    lint c_bolum_b = b/c;

    lint d_colum_b = b/d;

    lint cd_bolum_b = b/ekok;

    

    lint res = -c_bolum_a-d_bolum_a+c_bolum_b+d_colum_b+cd_bolum_a- cd_bolum_b;

    cout << b-a+1-res;



    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<cstring>

using namespace std;



long long gcd(long long a,long long b)

{

    return !b?a:gcd(b,a%b);

}



long long lms(long long  a,long long  b)

{

    return (a*b)/gcd(a,b);

}



int main()

{

    long long a,b,c,d,nc=0;

    //long long i,j;

    while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d)){

    nc=0;

    long long Lms=lms(c,d);

    if(a%c==0) nc++;

    //if(b%c==0) nc++;

    if(a%d==0) nc++;

    //if(b%d==0) nc++;

    nc+=(b/c-a/c);

    nc+=(b/d-a/d);

    if(a%Lms==0) nc--;

    //if(b%Lms==0) nc--;

    nc-=(b/Lms-a/Lms);

    printf("%lld",b-a+1-nc);}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

const int N = 2e5 + 3;

int main() {

#ifndef ONLINE_JUDGE

//	freopen("input.in", "r", stdin);

#endif

	long long a, b, c, d;

	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);

	long long res = b / c;

	res -= (a - 1) / c;

	res += b / d;

	res -= (a - 1) / d;

	res -= b / (c * d / __gcd(c, d));

	res += (a - 1) / (c * d / __gcd(c, d));

	printf("%lld\n", (b - a + 1) - res);

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<cstring>

using namespace std;



long long gcd(long long a,long long b)

{

    return !b?a:gcd(b,a%b);

}



long long lms(long long  a,long long  b)

{

    return (a*b)/gcd(a,b);

}



int main()

{

    long long a,b,c,d,nc=0;

    //long long i,j;

    while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d)){

    nc=0;

    long long Lms=lms(c,d);

    if(a%c==0) nc++;

    //if(b%c==0) nc++;

    if(a%d==0) nc++;

    //if(b%d==0) nc++;

    nc+=(b/c-a/c);

    nc+=(b/d-a/d);

    if(a%Lms==0) nc--;

    //if(b%Lms==0) nc--;

    nc-=(b/Lms-a/Lms);

    printf("%lld",b-a+1-nc);}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;



ll gcd(ll a,ll b)

{



    if(b==0)

        return a;

    else

        return gcd(b,a%b);

}



ll lcm(ll a,ll b)

{

    return (a/(gcd(a,b)))*b;



}



int main()

{

    ll t=1;





    while(t--)

    {

        ll a,b,c,d;

        //cout<<lcm(3,4)<<endl;

        cin>>a>>b>>c>>d;

        ll tot=b-a+1;

        ll a1=(a-1)/c+(a-1)/d-((a-1)/lcm(c,d));

        ll b1=b/c+b/d-(b/lcm(c,d));

        //ans= tot-ans;

        //cout<<a1<<" "<<b1<<" "<<tot<<endl;

        cout<<tot-(b1-a1)<<endl;



    }









}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<cstring>

using namespace std;



long long gcd(long long a,long long b)

{

    return !b?a:gcd(b,a%b);

}



long long lms(long long  a,long long  b)

{

    return (a*b)/gcd(a,b);

}



int main()

{

    long long a,b,c,d,nc=0;

    //long long i,j;

    while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d)){

    nc=0;

    long long Lms=lms(c,d);

    if(a%c==0) nc++;

    //if(b%c==0) nc++;

    if(a%d==0) nc++;

    //if(b%d==0) nc++;

    nc+=(b/c-a/c);

    nc+=(b/d-a/d);

    if(a%Lms==0) nc--;

    //if(b%Lms==0) nc--;

    nc-=(b/Lms-a/Lms);

    printf("%lld",b-a+1-nc);}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):


/*|In The Name Of Allah|*/



#include <bits/stdc++.h>



using namespace std;



const int N = 1e3+5;



long long a;

long long b;

long long c;

long long d;



long long get(long long A , long long B){

        return A / B;

}



int main(){

    cin >> a >> b >> c >> d;

    long long ans = (b - a + 1) - (get(b , c) + get(b , d) - get(b , c*d/__gcd(c , d)));

    ans +=  get(a-1 , c) + get(a-1 , d) - get(a-1 , c*d/__gcd(c , d));

    cout << ans << endl;

}



// a <= b


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<cstring>

using namespace std;



long long gcd(long long a,long long b)

{

    return !b?a:gcd(b,a%b);

}



long long lms(long long  a,long long  b)

{

    return (a*b)/gcd(a,b);

}



int main()

{

    long long a,b,c,d,nc=0;

    //long long i,j;

    while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d)){

    nc=0;

    long long Lms=lms(c,d);

    if(a%c==0) nc++;

    //if(b%c==0) nc++;

    if(a%d==0) nc++;

    //if(b%d==0) nc++;

    nc+=(b/c-a/c);

    nc+=(b/d-a/d);

    if(a%Lms==0) nc--;

    //if(b%Lms==0) nc--;

    nc-=(b/Lms-a/Lms);

    printf("%lld",b-a+1-nc);}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
//

/*==========================================================*/

/*    Template ver 2017-0720    |    Created by JollyBee    */

/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */

/*==========================================================*/

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef vector<int> vi;

typedef pair<int,int> pii;

typedef pair<ll,ll> pll;

typedef vector<pii> vii;

const double EPS=(double)1e-9;

const double PI=(double)acos(-1.0);

#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define pob pop_back

#define pf push_front

#define pof pop_front

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

#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)

#define REP(i,l,r) REPP(i,l,r,1)

#define FORD(i,n) for(int i=n-1;i>=0;i--)

#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)

#define REV(i,l,r) REVV(i,l,r,1)

//random

int irand(int lo, int hi){

    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;

}

//ll to string

string toString(ll x) {

    stringstream ss;

    ss << x;

    return ss.str();

}

//string to ll

ll toNumber(string S) {

    ll ret;

    sscanf(S.c_str(),"%lld",&ret);

    return ret;

}

// std::fill(start, end, value);

// for(auto it: DS){}



const int INF=(int)2e9;

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

/*==========================================================*/

/*                     END OF TEMPLATE                      */

/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */

/*==========================================================*/



ll f(ll n, ll mult){

    return n / mult;

}



int main(){

    ll a,b,c,d; scanf("%lld %lld %lld %lld", &a, &b, &c, &d);

    ll lcm = c * d / __gcd(c,d);

    ll range = b - a + 1;

    ll mult_c = f(b,c) - f(a-1,c);

    ll mult_d = f(b,d) - f(a-1,d);

    ll mult_cd = f(b,lcm) - f(a-1,lcm);

    printf("%lld\n", range - mult_c - mult_d + mult_cd);

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

long long a,b,c,d;

int main(){

   while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d)){

       long long s=0,t1,t2;

       t1=b/c-a/c;

       if(a%c==0)

        t1++;

        t2=b/d-a/d;

        if(a%d==0)

            t2++;

        s=t1+t2;

        long long p;

        p=__gcd(c,d);

        p=c*d/p;

        s-=b/p-a/p;

        if(a%p==0)

            s--;

            s=(b-a+1)-s;

        printf("%lld\n",s);

   }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
//Assalamualaikum//

//Mahmudul Ahsan Mahi

//RUET CSE 19'





#include<iostream>

#include<cstdio>

#include <bits/stdc++.h>

#include<cstring>

#include<vector>

#include<list>

#include<stack>

#include<iterator>

#include<algorithm>

#include<cstdlib>



#define ll long long

#define ull unsigned long long

#define pi acos(-1)



using namespace std;



int main()

{

    stack<int>st[1001];



    int i, n, q, o, t, x;



    cin>>n>>q;



    while(q--){

        cin>>o;



        if(o==0){

            cin>>t>>x;

            st[t].push(x);

        }



        else if(o==1){

            cin>>t;

            if(st[t].empty())

                ;

            else{

                cout<<st[t].top()<<endl;

            }

        }



        else if(o==2){

            cin>>t;

            if(st[t].empty())

                ;

             else{

                st[t].pop();

             }





        }

    }





    return 0;

}






// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

int main ()

{

     signed long long x,a,q,y,z,n,t;

    cin>>n;

    cin>>q;

    getchar();

    stack<int>S[n];

    stack<int>S2[n];

     for(int i=1; i<=q; i++)

    {

        cin>>a;

        if(a==0)

        {

            cin>>t;

            cin>>x;

            S[t].push(x);

        }

        else if(a==1)

        {

            cin>>t;

            //cout<<"S[t] = ";

            if(!S[t].empty())

            {

          cout<<S[t].top()<<endl;

            S2[t].push(S[t].top());

            S2[t].pop();

            }

        }

        else if(a==2)

        {

            cin>>t;

            if(!S[t].empty())

            {

                S[t].pop();

            }

        }

    }

    return 0;

}






// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

#include<cmath>

#include<cstring>

#include<cstdlib>

#include<ctime>

#include<cstdio>

#include<string>

//#include<string>

//#include<sstream>

using namespace std;



int main()

{

	long long a[100000],i;

	long long num=0;

	i=1;

	while(num<=1000000000){

		num+=i;

		a[i]=num;

		i++;

	}

	int sum=i;

	int x;

	scanf("%d",&x);

	for(i=1;i<=sum;i++){

		if(x<=a[i]){

			printf("%d\n",i);

			break;

		}

	}

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <string.h>

#include <math.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <unordered_map>

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 10;



#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl

#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl

#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl



int main() {

    //freopen(".in", "r", stdin);

    int n;

    scanf("%d",&n);

    ll sum=0;

    for(int i=1;;i++)

    {

        sum+=i;

        if(sum>=n) return 0*printf("%d\n",i);

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 7;

ll a[maxn];

int aim, ans = 0;

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(0), cout.tie(0);

    for(int i = 1; i < maxn; i++) a[i] = a[i-1] + i;

    cin>>aim;

    while(a[ans] < aim) ans++;

    cout<<ans<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <string.h>

#include <math.h>

#include <iostream>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <unordered_map>

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 10;



#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl

#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl

#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl



int main() {

    //freopen(".in", "r", stdin);

    int n;

    scanf("%d",&n);

    ll sum=0;

    for(int i=1;;i++)

    {

        sum+=i;

        if(sum>=n) return 0*printf("%d\n",i);

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define _C ios::sync_with_stdio(false);cin.tie(0);

#define xx first

#define yy second

#define ERR 0.00000001

#define INF (ll)1<<62

#define nSize 1000000

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

using namespace std;

typedef long long ll;

typedef pair<ll,ll> pll;

typedef vector<ll> vll;

typedef vector<pll> vpll;

typedef complex<double> cp;

typedef vector<cp> polinomio;

typedef long double ld;

const ld PI = acos(-1);





int main()

{_C

	ll n , k;

	ll mx = INF;

	cin >> n >> k;

	vll v(n);

	forn

		cin >> v[i];

	sort(v.begin(),v.end());

	for(int i = k-1 ; i < n ; i++)

	{

		mx = min(v[i]-v[i-k+1],mx);

	}

	cout << mx << '\n';

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <algorithm>



int n, k, ans = 0x7fffffff;

int a[100010];



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



int main() {

    n = read(), k = read();

    for(int i = 1; i <= n; ++i) a[i] = read();

    std::sort(a + 1, a + n + 1);

    for(int i = 1; i + k - 1 <= n; ++i) ans = std::min(ans, a[i + k - 1] - a[i]);

    print(ans);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int arr[2000005];

int main()

{

    int i,j,m,n,t,ans,tem;

    cin>>n>>m;

    for(i=1; i<=n; i++)

        cin>>arr[i];



    sort(arr+1,arr+n+1);

    ans=1000000007;

    for(i=m; i<=n; i++)

    {

        if((arr[i]-arr[i-m+1])<ans)

            ans=arr[i]-arr[i-m+1];

    }

    cout<<ans<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <algorithm>



int n, k, ans = 0x7fffffff;

int a[100010];



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



int main() {

    n = read(), k = read();

    for(int i = 1; i <= n; ++i) a[i] = read();

    std::sort(a + 1, a + n + 1);

    for(int i = 1; i + k - 1 <= n; ++i) ans = std::min(ans, a[i + k - 1] - a[i]);

    print(ans);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <stdio.h>

#include <queue>

#include <stack>

#include <string.h>

#include <algorithm>

#include <math.h>

#include <bits/stdc++.h>

#define ll long long

#define wtcl return

using namespace std;



inline ll read()

{

	ll s = 0, f = 1;

	char ch = getchar();

	for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = - 1;

	for(; ch >= '0' && ch <= '9'; ch = getchar()) s = ((s << 3ll) + (s << 1ll) + (ch ^ 48ll));

	return s * f ;

}

inline void out(ll x)

{

	if(x<0) putchar('-'),x=-x;

	if(x>9) out(x/10);

	putchar(x%10+'0');

}



int main()

{

	int n,k;

	cin>>n>>k;

	int num[100005];

	for(int i=0;i<n;i++)

		num[i]=read();

	sort(num,num+n);

	int ans  = 999999999;

	for(int i=0;i<=n-k;i++)

	{

		ans = min(ans,num[i+k-1]-num[i]);

	}

	cout<<ans<<endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cctype>

#include <algorithm>



int n, k, ans = 0x7fffffff;

int a[100010];



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



int main() {

    n = read(), k = read();

    for(int i = 1; i <= n; ++i) a[i] = read();

    std::sort(a + 1, a + n + 1);

    for(int i = 1; i + k - 1 <= n; ++i) ans = std::min(ans, a[i + k - 1] - a[i]);

    print(ans);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(){

    int n, k;

    cin >> n >> k;

    int h[n], a[n];

    for(int i = 0; i < n; i++){

        cin >> h[i];

    }

    sort(h, h+n);

    for(int i = 0; i < n-k+1; i++){

        a[i] = h[i+k-1] - h[i];

    }

    sort(a, a+(n-k+1));



    cout << a[0] << endl;

return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int main()

{

    int k,n,a[100005],b[100005];

    scanf("%d%d",&k,&n);

    for(int i=0;i<k;i++)

        scanf("%d",&a[i]);

    sort(a,a+k);

    int w=0;

    for(int i=0;i<k-n+1;i++)

    {

        b[w++]=a[i+n-1]-a[i];

    }

    int min=b[0];

    for(int j=0;j<w;j++)

    {

        if(b[j]<min)

            min=b[j];

    }

    printf("%d\n",min);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<vector>

#include<algorithm>



using namespace std;



int main(){

	int n,k,x,t,i,j,min;

	vector <int> v;

	cin>> n >> k;

	for(i = 0; i < n; i++){

		cin >> x;

		v.push_back(x);

	}

	sort(v.begin(),v.end());

	/*for(i = 0; i < n; i++){

		for(j = i+1; j <n; j++){

			if (v[i] > v[j] ){

				t = v[i];

				v[i] = v[j];

				v[j] = t;

			}

		}

	 	

	}*/



	i= 0;

	j=i+k-1; 

	min = v[j] - v[i];

	while(j < n){

		if( (v[j]-v[i]) < min) min =v[j]-v[i];

		i++;

		j++; 

	}

	cout << min;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int main()

{

    int k,n,a[100005],b[100005];

    scanf("%d%d",&k,&n);

    for(int i=0;i<k;i++)

        scanf("%d",&a[i]);

    sort(a,a+k);

    int w=0;

    for(int i=0;i<k-n+1;i++)

    {

        b[w++]=a[i+n-1]-a[i];

    }

    int min=b[0];

    for(int j=0;j<w;j++)

    {

        if(b[j]<min)

            min=b[j];

    }

    printf("%d\n",min);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main(){

int n,k;

cin>>n>>k;

vector<int> trees(n);

int min=1e9;

for(int i=0;i<n;i++){

	cin>>trees[i];

}

sort(trees.begin(),trees.end());

for(int i=0;i<=n-k;i++){

if(min>trees[i+k-1]-trees[i]){

	min=trees[i+k-1]-trees[i];

}

}

cout<<min<<endl;



return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int main()

{

    int k,n,a[100005],b[100005];

    scanf("%d%d",&k,&n);

    for(int i=0;i<k;i++)

        scanf("%d",&a[i]);

    sort(a,a+k);

    int w=0;

    for(int i=0;i<k-n+1;i++)

    {

        b[w++]=a[i+n-1]-a[i];

    }

    int min=b[0];

    for(int j=0;j<w;j++)

    {

        if(b[j]<min)

            min=b[j];

    }

    printf("%d\n",min);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

using namespace std;

int a[100010];

int main(){

	int k,n,i,x=-1;

	cin >> n >> k;

	for(i=0;i<n;i++){

		cin >> a[i];

	}

	sort(a,a+n);

	for(i=0;i<=n-k;i++){

		if(a[i+k-1]-a[i]<x || x==-1){

			x=a[i+k-1]-a[i];

		}

	}

	cout << x << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int main()

{

    int k,n,a[100005],b[100005];

    scanf("%d%d",&k,&n);

    for(int i=0;i<k;i++)

        scanf("%d",&a[i]);

    sort(a,a+k);

    int w=0;

    for(int i=0;i<k-n+1;i++)

    {

        b[w++]=a[i+n-1]-a[i];

    }

    int min=b[0];

    for(int j=0;j<w;j++)

    {

        if(b[j]<min)

            min=b[j];

    }

    printf("%d\n",min);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

typedef long long ll;

#define dbg          cout<<"Freak"<<endl;

#define dbgg(i)      cout<<i<<endl;

#define N            1e9+7;

using namespace std;

ll t;

ll arr[200005];

int main()

{

    ll a,b,c,d,e,f,i,j;

    cin>>a>>b;

    for(i=1;i<=a;i++)

    {

        cin>>arr[i];

    }

    c=N;

    sort(arr+1,arr+a+1);

    for(i=b;i<=a;i++)

    {

        c=min(c,(arr[i]-arr[i-b+1]));

    }

    cout<<c<<endl;





return 0;



}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int main()

{

    int k,n,a[100005],b[100005];

    scanf("%d%d",&k,&n);

    for(int i=0;i<k;i++)

        scanf("%d",&a[i]);

    sort(a,a+k);

    int w=0;

    for(int i=0;i<k-n+1;i++)

    {

        b[w++]=a[i+n-1]-a[i];

    }

    int min=b[0];

    for(int j=0;j<w;j++)

    {

        if(b[j]<min)

            min=b[j];

    }

    printf("%d\n",min);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <stdio.h>

#include <iostream>

#include <algorithm>

#include <string.h>

#define ll long long 

#define inf 0x3f3f3f

using namespace std;

int main()

{

	int a[100005];

	int n,k;

	while(scanf("%d %d",&n,&k)!=EOF)

	{

		for(int i=0;i<n;i++)

		scanf("%d",&a[i]);

		sort(a,a+n);

		int mi=999999999;

		for(int i=0;i<=n-k;i++)

		{

			mi=min(mi,a[i+k-1]-a[i]);

		}

		printf("%d\n",mi);

	}

	return 0;

 } 

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int main()

{

    int k,n,a[100005],b[100005];

    scanf("%d%d",&k,&n);

    for(int i=0;i<k;i++)

        scanf("%d",&a[i]);

    sort(a,a+k);

    int w=0;

    for(int i=0;i<k-n+1;i++)

    {

        b[w++]=a[i+n-1]-a[i];

    }

    int min=b[0];

    for(int j=0;j<w;j++)

    {

        if(b[j]<min)

            min=b[j];

    }

    printf("%d\n",min);

    return 0;

}

// Fastest known solution for this problem: