stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<cmath>

#include<cstring>

typedef long long LL;

using namespace std;



bool is_ok(LL N,LL A,LL B){

	if(N == 1 && A == B)

		return true;

	else if(N > 1 && A <= B)

		return true;

	return false;

}





int main(){

	LL N,A,B;

	cin >> N >> A >> B;

	

	if(is_ok(N,A,B)){

		if(N == 1 || A == B)

			cout << 1 << endl;

		else{

			LL diff = B-A;

			cout << diff*(N-2)+1 << endl;

		}

			

	}

	else

		cout << 0 << endl;

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 5.254168498733149x):
#include<stdio.h>

typedef long long ll;

int main()

{

	ll n,a,b;

	scanf("%lld %lld %lld",&n,&a,&b);

	ll ans=0;

	if(a>b)  ans=0;

	else if(n==1&&a!=b)  ans=0;

	else if(n==1&&a==b)  ans=1;

	else ans=(n-2)*(b-a)+1;

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

	return 0;

 }
// Slower C++ solution:
#include<iostream>

#include<cmath>

#include<cstring>

typedef long long LL;

using namespace std;



bool is_ok(LL N,LL A,LL B){

	if(N == 1 && A == B)

		return true;

	else if(N > 1 && A <= B)

		return true;

	return false;

}





int main(){

	LL N,A,B;

	cin >> N >> A >> B;

	

	if(is_ok(N,A,B)){

		if(N == 1 || A == B)

			cout << 1 << endl;

		else{

			LL diff = B-A;

			cout << diff*(N-2)+1 << endl;

		}

			

	}

	else

		cout << 0 << endl;

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 5.254122446941717x):
#include<stdio.h>

typedef long long ll;

int main()

{

	ll n,a,b;

	scanf("%lld %lld %lld",&n,&a,&b);

	ll ans=0;

	if(a>b)  ans=0;

	else if(n==1&&a!=b)  ans=0;

	else if(n==1&&a==b)  ans=1;

	else ans=(n-2)*(b-a)+1;

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

	return 0;

 }
// Slower C++ solution:
#include <iostream>

#include<cstdio>

#include<cmath>

using namespace std;



int main()

{

   int n,a,b;

   scanf("%d%d%d",&n,&a,&b);

   if(n==1)

   {

       if(a==b)

        printf("1\n");

       else

       {

           printf("0\n");

       }

   }

   else

   {

       if(a>b)

        printf("0\n");

       else

        printf("%lld\n",(long long)(n-2)*(b-a)+1);

   }



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.190531010039346x):
#include<stdio.h>

typedef long long ll;

int main()

{

	ll n,a,b;

	scanf("%lld %lld %lld",&n,&a,&b);

	ll ans=0;

	if(a>b)  ans=0;

	else if(n==1&&a!=b)  ans=0;

	else if(n==1&&a==b)  ans=1;

	else ans=(n-2)*(b-a)+1;

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

	return 0;

 }
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;





#define ONSPEED ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

#define pb push_back

#define f(i,x,n) for(i=x;i<n;i++)

#define rf(i,x,n) for(i=n;i>x;i--)

#define ll long long

#define GCD(a,b) __gcd(a,b)

#define ff first

#define ss second

#define adios return 0;



/*

tacet aquilae

*/



int main()

{

    ONSPEED;

    ll t,n,k,a,b,c,d,s=0,i,j,flag;

    string x,y;

    cin>>n>>a>>b;

    if(n==1)

    {

    	if(a==b) cout<<"1\n";

    	else cout<<"0\n";

    }

    else{

    	if(a>b) cout<<"0\n";

    	else{

    		cout<<(b-a)*(n-2)+1;

    	}

    }



    adios;

}

	


// Faster C++ solution for the same problem (measured speedup: 5.358516414741958x):
#include<stdio.h>

typedef long long ll;

int main()

{

	ll n,a,b;

	scanf("%lld %lld %lld",&n,&a,&b);

	ll ans=0;

	if(a>b)  ans=0;

	else if(n==1&&a!=b)  ans=0;

	else if(n==1&&a==b)  ans=1;

	else ans=(n-2)*(b-a)+1;

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

	return 0;

 }
// Slower C++ solution:
/*  TAHMID RAHMAN

    DAMIAN FOREVER

     MATH LOVER

    NEVER GIVE UP

*/

#include<bits/stdc++.h>

using namespace std;

#define pi acos(-1.0)

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define ll long long

#define pb push_back

#define fi first

#define se second

#define in insert

#define mp make_pair

#define GCD(a,b) __gcd(a,b);

#define endl "\n"

#define FRU freopen("out.txt","w",stdout)

#define FRO freopen("in.txt","r",stdin)

#define INFLL 9223372036854775807

#define debug 0

#define MAXN   100001

#define ar array

const int mxN=2e5;

const int MOD=1e9+7;

bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}

//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;

int main()

{



    ll i,j,k=0,c1=0,c2=0;

    ll n,a,b;

    cin>>n>>a>>b;

    if(a>b)

    {

        cout<<0<<endl;

    }

    else if(n==1)

    {

        if(a!=b)

            cout<<0<<endl;

        else

            cout<<1<<endl;

    }

    else

        cout<<(n-2)*(b-a)+1<<endl;







    //cout<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 5.253625196741621x):
#include<stdio.h>

typedef long long ll;

int main()

{

	ll n,a,b;

	scanf("%lld %lld %lld",&n,&a,&b);

	ll ans=0;

	if(a>b)  ans=0;

	else if(n==1&&a!=b)  ans=0;

	else if(n==1&&a==b)  ans=1;

	else ans=(n-2)*(b-a)+1;

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

	return 0;

 }
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <vector>

#include <iomanip>

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

#define rt return

#define dll(x) scanf("%I64d",&x)

#define xll(x) printf("%I64d\n",x)

#define sz(a) int(a.size())

#define all(a) a.begin(), a.end()

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

#define repd(i,x,n) for(int i=x;i<=n;i++)

#define pii pair<int,int>

#define pll pair<long long ,long long>

#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MSC0(X) memset((X), '\0', sizeof((X)))

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define eps 1e-6

#define gg(x) getInt(&x)

#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;

using namespace std;

typedef long long ll;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

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

ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}

inline void getInt(int* p);

const int maxn=1000010;

const int inf=0x3f3f3f3f;

/*** TEMPLATE CODE * * STARTS HERE ***/



int main()

{

	// freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);

    int n,a,b;

    while(cin>>n>>a>>b)

    {

    	if(n==1)

    	{

    		if(a!=b)

    		{

    			cout<<0<<endl;

    		}else

    		{

    			cout<<1<<endl;

    		}

    	}else

    	{

    		if(a<=b)

    		{

    			if(n==2)

    			{

    				cout<<1<<endl;

    			}

    			ll ans=1ll*(n-2)*b-1ll*(n-2)*a+1ll;

    			cout<<ans<<endl;

    		}else

    		{

    			cout<<0<<endl;



    		}

    	}

    }

    return 0;

}



inline void getInt(int* p) {

    char ch;

    do {

        ch = getchar();

    } while (ch == ' ' || ch == '\n');

    if (ch == '-') {

        *p = -(getchar() - '0');

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 - ch + '0';

        }

    }

    else {

        *p = ch - '0';

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 + ch - '0';

        }

    }

}




// Faster C++ solution for the same problem (measured speedup: 5.2583173652760005x):
#include<stdio.h>//需要使用大数相乘 

//struct bigint{

//	int digit[1000];

//	int size;

//	void init(){

//		for(int i=0;i<1000;i++){

//			digit[i]=0;

//		}

//		size=0;

//	}

//	void set(long long x){

//		init();

//		do{

//			digit[size++]=x%10000;

//			x=x/10000;

//		}while(x!=0);

//	}

//	bigint operator * (const bigint &a) const{

//		bigint ret;int tmp;int carry=0;

//		ret.init();

//		for(int i=0;i<size||i<)

//	}

//};

int main(){

	long long N,A,B;

	scanf("%lld%lld%lld",&N,&A,&B);

	if(N==0){

		printf("0\n");

	} 

	else if(N==1){

		if(A==B)

			printf("1\n");

		else

			printf("0\n");

	}

	else if(N==2){

		if(A<=B)

			printf("1\n");

		else

			printf("0\n");

	}

	else{

		if(A>B)

			printf("0\n");

		else if(A==B){

			printf("1\n");

		}

		else{

			long long ans=(N-2)*(B-A)+1;

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

		}

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>



using namespace std;





int main()

{

    long long N,A,B,i,j,min,max;

    cin>>N>>A>>B;



    min=(N-1)*A+B;

    max=(N-1)*B+A;





    if(B<A)

        cout<<'0';

    else

        if(B==A)

            cout<<'1';

    else

        if(N==1)

            cout<<'0';

        else

            cout<<max-min+1;



}

// Faster C++ solution for the same problem (measured speedup: 5.246724288230769x):
#include<stdio.h>//需要使用大数相乘 

//struct bigint{

//	int digit[1000];

//	int size;

//	void init(){

//		for(int i=0;i<1000;i++){

//			digit[i]=0;

//		}

//		size=0;

//	}

//	void set(long long x){

//		init();

//		do{

//			digit[size++]=x%10000;

//			x=x/10000;

//		}while(x!=0);

//	}

//	bigint operator * (const bigint &a) const{

//		bigint ret;int tmp;int carry=0;

//		ret.init();

//		for(int i=0;i<size||i<)

//	}

//};

int main(){

	long long N,A,B;

	scanf("%lld%lld%lld",&N,&A,&B);

	if(N==0){

		printf("0\n");

	} 

	else if(N==1){

		if(A==B)

			printf("1\n");

		else

			printf("0\n");

	}

	else if(N==2){

		if(A<=B)

			printf("1\n");

		else

			printf("0\n");

	}

	else{

		if(A>B)

			printf("0\n");

		else if(A==B){

			printf("1\n");

		}

		else{

			long long ans=(N-2)*(B-A)+1;

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

		}

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <vector>

#include <iomanip>

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

#define rt return

#define dll(x) scanf("%I64d",&x)

#define xll(x) printf("%I64d\n",x)

#define sz(a) int(a.size())

#define all(a) a.begin(), a.end()

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

#define repd(i,x,n) for(int i=x;i<=n;i++)

#define pii pair<int,int>

#define pll pair<long long ,long long>

#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MSC0(X) memset((X), '\0', sizeof((X)))

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define eps 1e-6

#define gg(x) getInt(&x)

#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;

using namespace std;

typedef long long ll;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

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

ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}

inline void getInt(int* p);

const int maxn=1000010;

const int inf=0x3f3f3f3f;

/*** TEMPLATE CODE * * STARTS HERE ***/



int main()

{

	// freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);

    int n,a,b;

    while(cin>>n>>a>>b)

    {

    	if(n==1)

    	{

    		if(a!=b)

    		{

    			cout<<0<<endl;

    		}else

    		{

    			cout<<1<<endl;

    		}

    	}else

    	{

    		if(a<=b)

    		{

    			if(n==2)

    			{

    				cout<<1<<endl;

    			}

    			ll ans=1ll*(n-2)*b-1ll*(n-2)*a+1ll;

    			cout<<ans<<endl;

    		}else

    		{

    			cout<<0<<endl;



    		}

    	}

    }

    return 0;

}



inline void getInt(int* p) {

    char ch;

    do {

        ch = getchar();

    } while (ch == ' ' || ch == '\n');

    if (ch == '-') {

        *p = -(getchar() - '0');

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 - ch + '0';

        }

    }

    else {

        *p = ch - '0';

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 + ch - '0';

        }

    }

}




// Faster C++ solution for the same problem (measured speedup: 5.265088880084855x):
#include <cstdio>

#include <algorithm>



using namespace std;





typedef long long LL;



int main(){

    LL N,A,B;

    scanf("%lld%lld%lld",&N,&A,&B);

    LL sum = (B-A)*(N-2)+1;

    if(A>B){

        printf("0");

        return 0;

    }

    if(N == 1 && A != B){

        printf("0");

        return 0;

    }

    if(N == 1 && A == B){

        printf("1");

        return 0;

    }

    printf("%lld", sum);



}
// Slower C++ solution:
#include <iostream>



using namespace std;





int main()

{

    long long N,A,B,i,j,min,max;

    cin>>N>>A>>B;



    min=(N-1)*A+B;

    max=(N-1)*B+A;





    if(B<A)

        cout<<'0';

    else

        if(B==A)

            cout<<'1';

    else

        if(N==1)

            cout<<'0';

        else

            cout<<max-min+1;



}

// Faster C++ solution for the same problem (measured speedup: 5.253480873797542x):
#include <cstdio>

#include <algorithm>



using namespace std;





typedef long long LL;



int main(){

    LL N,A,B;

    scanf("%lld%lld%lld",&N,&A,&B);

    LL sum = (B-A)*(N-2)+1;

    if(A>B){

        printf("0");

        return 0;

    }

    if(N == 1 && A != B){

        printf("0");

        return 0;

    }

    if(N == 1 && A == B){

        printf("1");

        return 0;

    }

    printf("%lld", sum);



}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main()

{

    long long n,a,b;

    cin>>n>>a>>b;

    if(n>1&&b>=a||n==1&&a==b)

        cout<<(n-2)*(b-a)+1<<endl;

    else

        cout<<0<<endl; 

 } 

// Faster C++ solution for the same problem (measured speedup: 5.256715361286601x):
#include <stdio.h>





int main()

{		

	long long a, b, n;

		

	scanf("%lld%lld%lld", &n, &a, &b);

	if(a == b) puts("1");

	else if(a < b){

		if(n > 1) printf("%lld\n", (b - a) * (n - 2) + 1);

		else puts("0");

	} 

	else puts("0");

				

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>



using namespace std;

int main(){

	int n,a,b;

	cin>>n>>a>>b;

	if(a>b){

		cout<<0<<endl;

		return 0;

	}

	if((n==1)&&(a!=b)) {

		cout<<0<<endl;

		return 0;

	}

	if((n==1)&&(a==b)){

		cout<<1<<endl;

		return 0;

	}

	

//	long max=a+(n-1)*b;

//	long min=(n-1)*a+b;

	printf("%lld\n",(long long)(b-a)*(n-2)+1);	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.226446449284064x):
#include <cstdio>



int main()

{

    int A,B,N;

    scanf("%d%d%d",&N,&A,&B);

    if(N==1)

    {

        if(A==B)

            printf("1\n");

        else

            printf("0\n");

    }

    else

    {

        if(A>B)

            printf("0\n");

        else

            printf("%lld\n",(long long )(B-A)*(N-2)+1);

    }

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;

int main(){

  int N, A, B;

  int count = 0;

  scanf("%d %d %d", &N, &A, &B);

  if(N == 1){

    if(A == B) printf("1");

    else printf("0");

  } else {

    if(A > B){

      printf("0");

    } else {

      printf("%lld", (long long)(B-A)*(N-2)+1);

    }

  }

  return 0; 

}

// Faster C++ solution for the same problem (measured speedup: 5.1795078995229495x):
#include <cstdio>



int main()

{

    int A,B,N;

    scanf("%d%d%d",&N,&A,&B);

    if(N==1)

    {

        if(A==B)

            printf("1\n");

        else

            printf("0\n");

    }

    else

    {

        if(A>B)

            printf("0\n");

        else

            printf("%lld\n",(long long )(B-A)*(N-2)+1);

    }

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <vector>

#include <iomanip>

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

#define rt return

#define dll(x) scanf("%I64d",&x)

#define xll(x) printf("%I64d\n",x)

#define sz(a) int(a.size())

#define all(a) a.begin(), a.end()

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

#define repd(i,x,n) for(int i=x;i<=n;i++)

#define pii pair<int,int>

#define pll pair<long long ,long long>

#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

#define MS0(X) memset((X), 0, sizeof((X)))

#define MSC0(X) memset((X), '\0', sizeof((X)))

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define eps 1e-6

#define gg(x) getInt(&x)

#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;

using namespace std;

typedef long long ll;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

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

ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}

inline void getInt(int* p);

const int maxn=1000010;

const int inf=0x3f3f3f3f;

/*** TEMPLATE CODE * * STARTS HERE ***/



int main()

{

	// freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);

    int n,a,b;

    while(cin>>n>>a>>b)

    {

    	if(n==1)

    	{

    		if(a!=b)

    		{

    			cout<<0<<endl;

    		}else

    		{

    			cout<<1<<endl;

    		}

    	}else

    	{

    		if(a<=b)

    		{

    			if(n==2)

    			{

    				cout<<1<<endl;

    				continue;

    			}

    			ll ans=1ll*(n-2)*b-1ll*(n-2)*a+1ll;

    			cout<<ans<<endl;

    		}else

    		{

    			cout<<0<<endl;



    		}

    	}

    }

    return 0;

}



inline void getInt(int* p) {

    char ch;

    do {

        ch = getchar();

    } while (ch == ' ' || ch == '\n');

    if (ch == '-') {

        *p = -(getchar() - '0');

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 - ch + '0';

        }

    }

    else {

        *p = ch - '0';

        while ((ch = getchar()) >= '0' && ch <= '9') {

            *p = *p * 10 + ch - '0';

        }

    }

}




// Faster C++ solution for the same problem (measured speedup: 5.246215430756344x):
#include <cstdio>



int main()

{

    int A,B,N;

    scanf("%d%d%d",&N,&A,&B);

    if(N==1)

    {

        if(A==B)

            printf("1\n");

        else

            printf("0\n");

    }

    else

    {

        if(A>B)

            printf("0\n");

        else

            printf("%lld\n",(long long )(B-A)*(N-2)+1);

    }

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include <utility>

#include <numeric>

using namespace std;

//変数デバッグ

#define DEB(variable) cout << #variable << '=' << variable << endl



//for簡易表記(引数ミス防止)

#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)

#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)





int main(){



    long long int n,a,b;

    cin>>n>>a>>b;

    if(n==0||(n==1&&a!=b)||a>b){

        cout << 0 << endl;

    }else{

        cout << 1 + ((n - 2) * (b - a)) << endl;

    }

    return 0;

}   

// Faster C++ solution for the same problem (measured speedup: 5.244780943102367x):
#include <cstdio>



int main(void)

{

    int A,B,N;

    scanf("%d%d%d",&N,&A,&B);

    if(N==1)

    {

        if(A==B)

            printf("1\n");

        else

            printf("0\n");

    }

    else 

    {

        if(A>B)

            printf("0\n");

        else

            printf("%lld\n",(long long )(B-A)*(N-2)+1);

    }

    return 0;

}
// Slower C++ solution:
#include <iostream>

using namespace std;



int main(){

	long long n,a,b;cin >> n >> a >> b;

	

	long long count=0;

	if(n==1&&a==b) cout << "1";

	else if(n==1&&a!=b) cout << "0";

	else if(a>b) cout << "0";

	else {

		count=(n-2)*b-(n-2)*a+1;

		cout << count;

	}

	

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 5.234036687286455x):
#include <cstdio>



int main(void)

{

    int A,B,N;

    scanf("%d%d%d",&N,&A,&B);

    if(N==1)

    {

        if(A==B)

            printf("1\n");

        else

            printf("0\n");

    }

    else 

    {

        if(A>B)

            printf("0\n");

        else

            printf("%lld\n",(long long )(B-A)*(N-2)+1);

    }

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <vector>

#include <list>

#include <climits>

#include <queue>

#include <string>

#include <map>

#include <stack>

#include <cmath>

#include <regex>

using namespace std;



int main()

{

long long n,a,b;

cin>>n>>a>>b;

if(n==1&&a==b)

{

    cout<<1;

    return 0;

}

if(n<2||a>b)

{

    cout<<0;

    return 0;

}

cout<<(b-a)*(n-2)+1;



}


// Faster C++ solution for the same problem (measured speedup: 5.235386832754376x):
#include <cstdio>



int main(void)

{

    int A,B,N;

    scanf("%d%d%d",&N,&A,&B);

    if(N==1)

    {

        if(A==B)

            printf("1\n");

        else

            printf("0\n");

    }

    else 

    {

        if(A>B)

            printf("0\n");

        else

            printf("%lld\n",(long long )(B-A)*(N-2)+1);

    }

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int maxn=1e5+10;

int a[maxn];

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

int n,m,v,p,b[maxn];

bool check(int mid)

{

    if(mid<=p)return 1;

    if(a[mid]+m<a[p])return 0;

    if(v<=p-1&&a[mid]+m>=a[p])return 1;

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

    int temp=0;

    for(int i=1;i<=p-1;i++)b[i]+=m,temp+=m;

    int inx=n,cnt=v-p+1;

    while(inx>mid&&cnt>1)temp+=m,inx--,cnt--,b[inx]+=m;

    temp+=m;

    int now=a[mid]+m;

    int res=m*v-temp;

    for(int i=p;i<mid;i++)

	{

        int add=min(m,max(now-a[i],0ll));

        if(add>res)add=res;

        res-=add,b[i]+=add;

    }

    return now>=b[p]&&res<=0;

}

signed main()

{

    cin>>n>>m>>v>>p;

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

    sort(a+1,a+n+1,cmp);

    int l=1,r=n;

    int ans=0;

    while(l<=r)

	{

        int mid=(l+r)>>1;

        if(check(mid))l=mid+1,ans=mid;

        else r=mid-1;

    }

    cout<<ans<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.190409101275806x):
#include <cstdio>

#include <algorithm>

#define ll long long

using namespace std;

const int N=1e5+5;

int n,m,v,p;

ll a[N],sum[N];

bool check(int x){

	if(a[x]+m<a[p]) return 0;

	return 1ll*m*v<=1ll*(p-1ll)*m+1ll*(n-x+1)*m-1ll*(sum[x-1]-sum[p-1])+1ll*(a[x]+m)*(x-p);

}

signed main() {

	scanf("%d%d%d%d",&n,&m,&v,&p);

	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);

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

	reverse(a+1,a+n+1);

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

	int l=p,r=n,ans=p;

	while(l<=r){

		int mid=l+r>>1;

		if(check(mid)){

			ans=mid;

			l=mid+1;

		}

		else r=mid-1;

	}

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

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define int long long

using namespace std;

int num[100007],chance=0,n,m,v,p;

bool cmp(int a,int b)

{

	return a>b;

}

signed main() 

{

	scanf("%lld%lld%lld%lld",&n,&m,&v,&p);

	int ans=p;

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

	{

		scanf("%lld",&num[i]);

	}

	sort(num+1,num+1+n,cmp);

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

	{

		if(num[p]>num[p+i]+m)

		{

			cout<<ans<<endl;

			return 0;

		}

		int t=v+i-n;

		if(t<=0)

		{

			ans++;

		}

		else 

		if( (t*m-chance-1)/i +num[p]+1<=num[p+i]+m)

		{

			ans++;

		}

		chance+=num[p]-num[p+i];

//		cout<<ans<<' ';

	}

	cout<<ans<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.186853483731229x):
#include <cstdio>

#include <algorithm>

#define ll long long

using namespace std;

const int N=1e5+5;

int n,m,v,p;

ll a[N],sum[N];

bool check(int x){

	if(a[x]+m<a[p]) return 0;

	return 1ll*m*v<=1ll*(p-1ll)*m+1ll*(n-x+1)*m-1ll*(sum[x-1]-sum[p-1])+1ll*(a[x]+m)*(x-p);

}

signed main() {

	scanf("%d%d%d%d",&n,&m,&v,&p);

	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);

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

	reverse(a+1,a+n+1);

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

	int l=p,r=n,ans=p;

	while(l<=r){

		int mid=l+r>>1;

		if(check(mid)){

			ans=mid;

			l=mid+1;

		}

		else r=mid-1;

	}

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

	return 0;

}